Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
add_theme_page() - 将子菜单页添加到外观主菜单 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / add_theme_page()

add_theme_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $callback = '', int $position = null )

将子菜单页添加到外观主菜单


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 3 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "d369e5096771b4ef95be960ff7c1c3db" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "5d38607a8b13d4a544b0e14fd6bf9118" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

addmore...

menu_page 菜单页more...


描述

这个函数接受一个能力(capability),它将被用来确定一个页面是否包括在菜单中。

用于处理页面输出的函数必须检查用户是否具有所需的能力。


参数

$page_title

(string)(必填) 选中菜单时要在页面标题标签中显示的文本。

$menu_title

(string)(必填) 要用于菜单的文本。

$capability

(string)(必填) 向用户显示此菜单所需的能力。

$menu_slug

(string)(必填) 用于引用此菜单的slug名称(对于此菜单应是唯一的)。

$callback

(callable)(可选) 要调用以输出此页面内容的函数。

默认值: ''

$position

(int)(可选) 此项应出现在菜单顺序中的位置。

默认值: null


返回

(string|false) 返回结果页面的hook_suffix,如果用户不具备所需的能力则返回false。


更多信息

  • 此函数是调用add_submenu_page()的简单包装器,传递接收到的参数并指定'themes.php'作为$parent_slug参数,这意味着新页面将作为子菜单添加到外观菜单。
  • $capability参数用于根据当前用户的角色和能力,确定该页面是否包含在菜单中。
  • 处理选项页面输出的函数还应验证用户的能力。


源码

查看源码 官方文档


更新日志

版本描述
5.3.0添加了$position参数。
2.0.0开始引入

使用示例

  • 示例1

    来自WordPress Codex,它指出add_theme_page必须提前调用。因此,使用‘admin_init’钩子将使角色能力对于创建的主题页无效。

    使用‘admin_menu’钩子替代,如下示例:

    function add_test_theme_page() {
    	add_theme_page( 'Theme Title Settings', 'Theme Menu Settings', 'edit_theme_options', 'test-theme-options', 'theme_option_page' );
    }
    add_action( 'admin_menu', 'add_test_theme_page' );
    
    function theme_option_page() {
    	echo 'This is a test theme options page!';
    }