remove_submenu_page()移除后台管理界面的二级菜单

目录

描述

Remove an admin submenu.

Depending on when this function is called, it may not prevent users from accessing the screen for the removed submenu directly (see ticket #18850). Removing a menu does not replace the need to filter a user's permissions as appropriate.

remove_submenu_page() 描述

用法

<?php remove_submenu_page$menu_slug$submenu_slug ); ?>

remove_submenu_page() 用法

参数

$menu_slug

(string) (必填) The slug for the parent menu

默认值: None

$submenu_slug

(string) (必填) The slug of the submenu

默认值: None

remove_submenu_page() 参数

返回值

(array|boolean) 

The removed submenu on success, false if not found.

remove_submenu_page() 返回值

示例

Removes the Widgets submenu page.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php

add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
function 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
}

?>

In the above example, the value of $page would have been:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

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

Remove custom post type submenu pages. The secret is in converting the second argument `&` to `&amp;`.

remove_submenu_page() 示例

注意

  • 使用到 global: (array) $submenu
  • In order to remove the theme-editor.php submenu of themes.php (and others) in more recent versions of WordPress, you need to bind to the admin_menu hook with a very high priority (about 110, depending on the submenus to remove). Don't use admin_init as previously stated here, hence it will break wp-admin/admin-ajax.php.

remove_submenu_page() 注意

历史

添加于 版本: 3.1.0

remove_submenu_page() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Remove an admin submenu
 *
 * @since 3.1.0
 *
 * @global array $submenu
 *
 * @param string $menu_slug The slug for the parent menu
 * @param string $submenu_slug The slug of the submenu
 * @return array|bool The removed submenu on success, False if not found
 */
function remove_submenu_page( $menu_slug, $submenu_slug ) {
	global $submenu;

	if ( !isset( $submenu[$menu_slug] ) )
		return false;

	foreach ( $submenu[$menu_slug] as $i => $item ) {
		if ( $submenu_slug == $item[2] ) {
			unset( $submenu[$menu_slug][$i] );
			return $item;
		}
	}

	return false;
}

remove_submenu_page() 源文件

相关