当前浏览:首页 / WordPress函数 / remove_submenu_page()

remove_submenu_page( string $menu_slug, string $submenu_slug ): array|false

删除后台管理子菜单

menu_page 菜单页more...

removemore...


描述

示例用法:

  • remove_submenu_page( 'themes.php', 'nav-menus.php' )
  • remove_submenu_page( 'tools.php', 'plugin_submenu_slug' )
  • remove_submenu_page( 'plugin_menu_slug', 'plugin_submenu_slug' )

参数

$menu_slugstring必填
父菜单的slug。
$submenu_slugstring必填
子菜单的slug。

返回

array|false 成功时删除的子菜单,如果未找到则为false。


更多信息

根据调用此函数的时间,它可能不会阻止用户直接访问已删除子菜单的屏幕(请参见ticket #18850)。删除菜单并不意味着需要根据需要过滤用户的权限。

为了在最新版本的WordPress中删除themes.php(和其他)的theme-editor.php子菜单,您需要以非常高的优先级绑定到admin_menu钩子(大约是110,取决于要删除的子菜单)。不要像之前所说的那样使用admin_init,因此它会破坏wp-admin/admin-ajax.php


源码

查看源码 官方文档


更新日志

版本描述
3.1.0开始引入

使用示例

  • 示例1

    有时,很难弄清楚删除子菜单需要使用什么样的menu/submemiu slug组合。

    您可以通过实际将global $submenu数组打印到debug.log文件,并确定要删除的子菜单来解决这个问题。

     global $submenu;
     error_log(print_r($submenu, true)); //this will print out all the menus/submenus currently available in the admin.
  • 示例2

    示例
    删除Widgets子菜单页面。

    /**
     * Remove the Widgets submenu page.
     */
    function wpdocs_adjust_the_wp_menu() {
    	$page = remove_submenu_page( 'themes.php', 'widgets.php' );
    	// $page[0] is the menu title
    	// $page[1] is the minimum level or capability required
    	// $page[2] is the URL to the item's file
    }
    add_action( 'admin_menu', 'wpdocs_adjust_the_wp_menu', 999 );

    在上述示例中,$page的值为:

    array(3) { [0]=> string(7) "Widgets" [1]=> string(18) "edit_theme_options" [2]=> string(11) "widgets.php" }