add_comments_page()

在后台管理界面的“评论”菜单下增加二级菜单

描述

将子菜单页面添加到“注释”菜单。

注意:如果您在 wp_die() 屏幕中遇到“您没有足够的权限访问此页面”消息,那么您上钩得太早了。钩子,你应该用的是 admin_menu 。

用法

 <?php
add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function);
?> 

参数

$page_title

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

默认值: None

$menu_title

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

默认值: None

$capability

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

默认值: None

$menu_slug

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

默认值: None

$function

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

默认值: ‘ ‘

返回值

string 

生成的页面hook_suffix(add_submenu_page() 返回的内容)

注意

此函数是调用 add_submenu_page() 的简单包装器,传递收到的参数并将“edit-comments.php”指定为 $parent_slug 参数。这意味着新页面将作为子菜单添加到“注释”菜单中。

此函数是调用 add_submenu_page() 的简单包装器,传递收到的参数并将“edit-comments.php”指定为 $parent_slug 参数。这意味着新页面将作为子菜单添加到“注释”菜单中。

处理选项页输出的函数还应验证用户的功能。

源文件

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

/**
* Add sub menu page to the comments 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_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = ” ) {

return add_submenu_page( ‘edit-comments.php’, $page_title, $menu_title, $capability, $menu_slug, $function );

}
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索