add_meta_box

Definition:
function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {}

Add a meta box to an edit form.

Parameters

  • string $id: String for use in the ‘id’ attribute of tags.
  • string $title: Title of the meta box.
  • string $callback: Function that fills the box with the desired content. The function should echo its output.
  • string|object $screen: Optional. The screen on which to show the box (post, page, link). Defaults to current screen.
  • string $context: Optional. The context within the page where the boxes should show (‘normal’, ‘advanced’).
  • string $priority: Optional. The priority within the context where the boxes should show (‘high’, ‘low’).
  • $callback_args

Source code

function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {

	global $wp_meta_boxes;



	if ( !isset($wp_meta_boxes) )

		$wp_meta_boxes = array();

	if ( !isset($wp_meta_boxes[$page]) )

		$wp_meta_boxes[$page] = array();

	if ( !isset($wp_meta_boxes[$page][$context]) )

		$wp_meta_boxes[$page][$context] = array();



	foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {

		foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {

			if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )

				continue;



			// If a core box was previously added or removed by a plugin, don't add.

			if ( 'core' == $priority ) {

				// If core box previously deleted, don't add

				if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )

					return;

				// If box was added with default priority, give it core priority to maintain sort order

				if ( 'default' == $a_priority ) {

					$wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];

					unset($wp_meta_boxes[$page][$a_context]['default'][$id]);

				}

				return;

			}

			// If no priority given and id already present, use existing priority

			if ( empty($priority) ) {

				$priority = $a_priority;

			// else if we're adding to the sorted priortiy, we don't know the title or callback. Glab them from the previously added context/priority.

			} elseif ( 'sorted' == $priority ) {

				$title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];

				$callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];

				$callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];

			}

			// An id can be in only one priority and one context

			if ( $priority != $a_priority || $context != $a_context )

				unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);

		}

	}



	if ( empty($priority) )

		$priority = 'low';



	if ( !isset($wp_meta_boxes[$page][$context][$priority]) )

		$wp_meta_boxes[$page][$context][$priority] = array();



	$wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);

}

259

add_menu_page

Definition:
function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) {}

Add a top level menu page
This function takes a capability which will be used to determine whether or not a page is included in the menu.

Parameters

  • string $page_title: The text to be displayed in the title tags of the page when the menu is selected
  • string $menu_title: The text to be used for the menu
  • string $capability: The capability required for this menu to be displayed to the user.
  • string $menu_slug: The slug name to refer to this menu by (should be unique for this menu)
  • callback $function: The function to be called to output the content for this page.
  • string $icon_url: The url to the icon to be used for this menu
  • int $position: The position in the menu order this one should appear

Return values

returns:The resulting page’s hook_suffix

Source code

function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) {

	global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages;



	$menu_slug = plugin_basename( $menu_slug );



	$admin_page_hooks[$menu_slug] = sanitize_title( $menu_title );



	$hookname = get_plugin_page_hookname( $menu_slug, '' );



	if ( !empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) )

		add_action( $hookname, $function );



	if ( empty($icon_url) )

		$icon_url = esc_url( admin_url( 'images/generic.png' ) );

	elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )

		$icon_url = 'https://' . substr($icon_url, 7);



	$new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );



	if ( null === $position  )

		$menu[] = $new_menu;

	else

		$menu[$position] = $new_menu;



	$_registered_pages[$hookname] = true;



	// No parent as top level

	$_parent_pages[$menu_slug] = false;



	return $hookname;

}

253

add_media_page

Definition:
function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {}

Add sub menu page to the media main menu.
This function takes a capability which will be used to determine whether or not a page is included in the menu.

Parameters

  • string $page_title: The text to be displayed in the title tags of the page when the menu is selected
  • string $menu_title: The text to be used for the menu
  • string $capability: The capability required for this menu to be displayed to the user.
  • string $menu_slug: The slug name to refer to this menu by (should be unique for this menu)
  • callback $function: The function to be called to output the content for this page.

Return values

returns:The resulting page’s hook_suffix, or false if the user does not have the capability required.

Source code

function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {

	return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function );

}

249

add_management_page

Definition:
function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {}

Add sub menu page to the tools main menu.
This function takes a capability which will be used to determine whether or not a page is included in the menu.

Parameters

  • string $page_title: The text to be displayed in the title tags of the page when the menu is selected
  • string $menu_title: The text to be used for the menu
  • string $capability: The capability required for this menu to be displayed to the user.
  • string $menu_slug: The slug name to refer to this menu by (should be unique for this menu)
  • callback $function: The function to be called to output the content for this page.

Return values

returns:The resulting page’s hook_suffix, or false if the user does not have the capability required.

Source code

function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {

	return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function );

}

247