add_media_page()在后台管理界面的“多媒体”菜单下增加二级菜单

目录

描述

Add sub menu page to the Media menu.

NOTE: If you're running into the »You do not have sufficient permissions to access this page.« message in a wp_die() screen, then you've hooked too early. The hook, you should use is admin_menu.

add_media_page() 描述

用法

 <?php
add_media_page
$page_title$menu_title$capability$menu_slug$function);
?> 

add_media_page() 用法

参数

$page_title

(string) (必填) The text to be displayed in the title tags of the page when the menu is selected

默认值: None

$menu_title

(string) (必填) The text to be used for the menu

默认值: None

$capability

(string) (必填) The capability required for this menu to be displayed to the user.

默认值: None

$menu_slug

(string) (必填) The slug name to refer to this menu by (should be unique for this menu).

默认值: None

$function

(callback) (可选) The function to be called to output the content for this page.

默认值: ' '

add_media_page() 参数

返回值

string 

The resulting page's hook_suffix (What add_submenu_page() returns)

add_media_page() 返回值

注意

  • This function is a simple wrapper for a call to add_submenu_page(), passing the received arguments and specifying 'upload.php' as the $parent_slug argument. This means the new page will be added as a sub menu to the Media menu.
  • The $capability parameter is used to determine whether or not the page is included in the menu based on the Roles and Capabilities) of the current user.
  • The function handling the output of the options page should also verify the user's capabilities.

add_media_page() 注意

源文件

add_media_page() 函数的代码位于 wp-admin/includes/plugin.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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.
 *
 * The function which is hooked in to handle the output of the page must check
 * that the user has the required capability as well.
 *
 * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
 * @param string $menu_title The text to be used for the menu
 * @param string $capability The capability required for this menu to be displayed to the user.
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
 * @param callback $function The function to be called to output the content for this page.
 *
 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
 */
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 );
}

add_media_page() 源文件