博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Function Reference/add submenu page
阅读量:6697 次
发布时间:2019-06-25

本文共 4990 字,大约阅读时间需要 16 分钟。

hot3.png

Description

Add a sub menu page.

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.

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.

This function should normally be hooked in with one of the the admin_menu actions depending on the menu where the sub menu is to appear:

  • The normal, or site, administration menu
    The user administration menu
    The administration menu

Usage

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

Parameters

  • $parent_slug

  • () (required) The slug name for the parent menu (or the file name of a standard WordPress admin page). Use NULL or set to 'options.php' if you want to create a page that doesn't appear in any menu (see example below).

    • Default:

  • Examples:

    1. For Dashboard: add_submenu_page( 'index.php', ... ); Also see

    2. For Posts: add_submenu_page( 'edit.php', ... ); Also see Also see

    3. For Media: add_submenu_page( 'upload.php', ... ); Also see

    4. For Links: add_submenu_page( 'link-manager.php', ... ); Also see

    5. For Pages: add_submenu_page( 'edit.php?post_type=page', ... ); Also see

    6. For Comments: add_submenu_page( 'edit-comments.php', ... ); Also see

    7. For Custom Post Types: add_submenu_page( 'edit.php?post_type=your_post_type', ... );

    8. For Appearance: add_submenu_page( 'themes.php', ... ); Also see

    9. For Plugins: add_submenu_page( 'plugins.php', ... ); Also see

    10. For Users: add_submenu_page( 'users.php', ... ); Also see

    11. For Tools: add_submenu_page( 'tools.php', ... ); Also see

    12. For Settings: add_submenu_page( 'options-general.php', ... ); Also see

    13. For Settings in the Network Admin pages: add_submenu_page( 'settings.php', ... );

  • $page_title

  • () (required) The text to be displayed in the title tags of the page when the menu is selected

    • Default:

  • $menu_title

  • () (required) The text to be used for the menu

    • Default:

  • $capability

  • () (required) The required for this menu to be displayed to the user.

    • Default:

  • $menu_slug

  • () (required) The slug name to refer to this menu by (should be unique for this menu). If you want to NOT duplicate the parent menu item, you need to set the name of the $menu_slug exactly the same as the parent slug.

    • Default:

  • $function

  • () (optional) The function to be called to output the content for this page.

    • Default:

  • The function must be referenced in one of two ways:

    1. if the function is a member of a class within the plugin it should be referenced as array( $this, 'function_name' ) if the class is instantiated as an object or array( __CLASS__, 'function_name' ) if its called statically

    2. in all other cases, using the function name itself is sufficient

Return values

  • string

  • The resulting page's hook_suffix, or false if the user does not have the capability required.

Notes

  • For $menu_slug please don't use __FILE__ it makes for an ugly URL, and is a minor security nuisance.

  • Within the rendering function $function you may want to access parameters you used in add_submenu_page(), such as the $page_title. Typically, these will work:

    • $parent_slug: get_admin_page_parent()

    • $page_title: get_admin_page_title(), or simply global $title

    • $menu_slug: global $plugin_page

Example

add_action('admin_menu', 'register_my_custom_submenu_page');function register_my_custom_submenu_page() {	add_submenu_page( 'tools.php', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' ); }function my_custom_submenu_page_callback() {		echo '
'; echo '

My Custom Submenu Page

'; echo '';}

To hide your submenu link from a top level menu item to which it belongs you would instead do,

add_action('admin_menu', 'register_my_custom_submenu_page');function register_my_custom_submenu_page() {   add_submenu_page(           null   //or 'options.php'         , 'My Custom Submenu Page'         , 'My Custom Submenu Page'        , 'manage_options'        , 'my-custom-submenu-page'        , 'my_custom_submenu_page_callback'    );}

If you are attempting to add a sub menu page to a menu page created via add_menu_page() the first sub_menu_page will duplicate your add_menu_page().

If you want a sub_menu_page in this scenario, you should first create a duplicate of your add_menu_page() and then add your sub_menu_page() second:

add_menu_page('My Custom Page', 'My Custom Page', 'manage_options', 'my-top-level-slug');add_submenu_page( 'my-top-level-slug', 'My Custom Page', 'My Custom Page', 'manage_options', 'my-top-level-slug');add_submenu_page( 'my-top-level-slug', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-secondary-slug');

Change Log

  • Since:

Source File

add_submenu_page() is located in .

转载于:https://my.oschina.net/ajian2014/blog/309186

你可能感兴趣的文章
NOI2011 智能车比赛
查看>>
(旧)子数涵数·C语言——条件语句
查看>>
java_泛型(构造器)部分实例
查看>>
hdu 1161 Eddy's mistakes
查看>>
C++中关于cons和字符串t的一些注意事项
查看>>
[AX]AX2012 AIF(二):文档服务编程模型
查看>>
[AX]AX2012 SSRS报表使用Report Data Method
查看>>
Spring Boot 乐观锁加锁失败 - 集成AOP
查看>>
1-3-顺时针旋转矩阵
查看>>
可行性研究
查看>>
Linux文件查找命令find,xargs详述
查看>>
Spring WebFlux 响应式编程学习笔记(一)
查看>>
Dynamics CRM 2015 站点地图公告配置实体显示名称的变更
查看>>
java操作elasticsearch实现前缀查询、wildcard、fuzzy模糊查询、ids查询
查看>>
commons-fileupload、smartUpload和commons-net-ftp
查看>>
Simulated Annealing(模拟退火算法)
查看>>
面向对象-多态,反射
查看>>
sort函数
查看>>
用来做 favicon 的站点
查看>>
去除vue项目中的#及其ie9兼容性
查看>>