在wordpress后台在多媒体菜单下面添加一个子页面。
add_media_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '' )
wp模板中用这个函数需要一个功能,用于决定菜单中是否包含页面。连接到处理页面输出的函数必须检查用户是否具有所需的能力。
参数
$page_title
(string)
(Required)
The text to be displayed in the title tags of the page when the menu is selected.
$menu_title
(string)
(Required)
The text to be used for the menu.
$capability
(string)
(Required)
The capability required for this menu to be displayed to the user.
$menu_slug
(string)
(Required)
The slug name to refer to this menu by (should be unique for this menu).
$function
(callable)
(Optional)
The function to be called to output the content for this page.Default value: ”
返回值
(false|string) The resulting page’s hook_suffix, or false if the user does not have the capability required.
源代码文件位置: wp-admin/includes/plugin.php
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 ); }
简单实例(在模板文件夹中的function.php中添加):
add_action('admin_menu', 'media_submenu'); function media_submenu() { add_media_page(__('媒体子页面'), __('媒体子页面'), 'read', 'your-unique-identifier-media', 'add_media_submenu'); } function add_media_submenu() { echo '<div><p>这儿就是媒体子页面显示内容的地方.</p></div>'; }
刷新看效果: