WordPress功能函數(shù)add_management_page()
WordPress功能函數(shù)add_management_page(),在工具主菜單中添加子菜單頁(yè)。
用法:
add_management_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', int $position = null )
描述:
該函數(shù)具有一種功能,用于確定菜單中是否包含某個(gè)頁(yè)面。
用于處理頁(yè)面輸出的函數(shù)也必須檢查用戶(hù)是否具備所需的功能。
參數(shù):
$page_title
(string) (必需) 選中菜單時(shí)要在頁(yè)面標(biāo)題標(biāo)簽中顯示的文本。
$menu_title
(string) (必需) 要用于菜單的文本。
$capability
(string) (必需) 向用戶(hù)顯示該菜單所需的功能。
$menu_slug
(string) (必需) 用來(lái)引用這個(gè)菜單的名稱(chēng)(對(duì)于這個(gè)菜單應(yīng)該是唯一的)。
$function
(callable) (可選) 用于輸出此頁(yè)面內(nèi)容的函數(shù)。
默認(rèn)值: ''
$position
(int) (可選) The position in the menu order this item should appear.
默認(rèn)值: null
返回
(string|false) 結(jié)果頁(yè)面的hook_suffix,如果用戶(hù)不具備所需的能力,則為false。
更多信息:
例子:
add_management_page('Custom permalinkks ', 'Custom permalinkks ', 'manage_options', 'my-unique-identifier', 'custom_permalinks_options_page');
注:
如果你正在運(yùn)行?你沒(méi)有足夠的權(quán)限訪問(wèn)這個(gè)頁(yè)面?!皐p_die()”屏幕中的消息,那么你太早上鉤了。你應(yīng)該使用的鉤子是' admin_menu '。
來(lái)源:
文件: wp-admin/includes/plugin.php
function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
}
更新日志:

用戶(hù)貢獻(xiàn)的筆記
(由David Brumbaugh貢獻(xiàn)- 5年前)
使用實(shí)例添加工具頁(yè)面。
class MyWPTool {
function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
function admin_menu() {
$hook = add_management_page( 'My WP Tool Page', 'My WP Tool', 'install_plugins', 'mywptool', array( $this, 'admin_page' ), '' );
add_action( "load-$hook", array( $this, 'admin_page_load' ) );
}
function admin_page_load() {
// ...
}
function admin_page() {
// ...
}
}
(由jakubd貢獻(xiàn)- 2年前)
// Example
add_action ('admin_menu', function () {
add_management_page('Some page title', 'Title in the menu', 'install_plugins', 'some_unique_string', 'my_custom_page_render_function', '');
});
function my_custom_page_render_function()
{
echo 'This is content of the page';
}