// PLUGINS THAT ADD AS DASHBOARD SUBMENU
// IF THIS IS THE URL BELOW - THE PAGE VARIABLE IS WHAT I NEED ( SO WHATEVER COMES AFTER PAGE= )
// http://example.com/wp-admin/index.php?page=iconize-plugin-update-notifier
remove_submenu_page( \'index.php\', \'iconize-plugin-update-notifier\' );
// OR FOR EXAMPLE WOOCOMMERCE DASHBOARD SUBMENU
remove_submenu_page( \'index.php\', \'wc-about\' ); //WOO
remove_submenu_page( \'index.php\', \'wc-credits\' ); //WOO
remove_submenu_page( \'index.php\', \'wc-translators\' ); //WOO
// CUSTOM POST TYPE TOP LEVELS
remove_menu_page( \'edit.php?post_type={$POST_TYPE}\' ); //LOOK FOR WHAT COMES AFTER POST TYPE IN THE URL
remove_menu_page( \'edit.php?post_type=testimonials-widget\' ); //TESTIMONIALS WIDGET
remove_menu_page( \'edit.php?post_type=product\' ); //WOOCOMMERCE
// CUSTOM POST TYPE SUBMENU
remove_submenu_page( \'edit.php?post_type={$POST_TYPE}\', \'{$SUBMENU_URL_VARIABLE}\' ); //EXAMPLE FORMAT
// SO IF BELOW IS THE URL
// http://example.com/wp-admin/edit.php?post_type=testimonials-widget&page=testimonialswidget_settings
// YOU NEED TO SEE WHATS AFTER PAGE
remove_submenu_page( \'edit.php?post_type=testimonials-widget\', \'testimonialswidget_settings\' ); //TESTIMONIALS WIDGET
// OTHER EXAMPLES
remove_menu_page( \'revslider\' ); // REVSLIDER
remove_menu_page( \'woocommerce\' ); // WOOCOMMERCE
remove_menu_page( \'order-post-types-shop_order\' ); // WOOCOMMERCE
remove_menu_page( \'order-post-types-shop_coupons\' ); // WOOCOMMERCE
remove_menu_page( \'shortcodes-ultimate\' ); // SHORTCODES ULTIMATE
remove_menu_page( \'wp-admin-microblog/wp-admin-microblog.php\' ); // ADMIN MICROBLOG
remove_menu_page( \'snippets\' ); //CODE SNIPPETS
remove_menu_page( \'gf_edit_forms\' ); // GRAVITY FORMS
remove_submenu_page( \'gf_edit_forms\', \'gf_settings\' ); // GRAVITY FORMS
remove_submenu_page( \'gf_edit_forms\', \'gf_export\' ); // GRAVITY FORMS
remove_submenu_page( \'gf_edit_forms\', \'gf_update\' ); // GRAVITY FORMS
remove_submenu_page( \'gf_edit_forms\', \'gf_addons\' ); // GRAVITY FORMS
remove_submenu_page( \'gf_edit_forms\', \'gf_help\' ); // GRAVITY FORMS
remove_submenu_page( \'cleverness-to-do-list\', \'cleverness-to-do-list-settings\' ); //Cleverness TODO
您可以使用以下内容调试所有这些内容,以获取所需的所有信息:
if (!function_exists(\'debug_admin_menus\')):
function debug_admin_menus() {
if ( !is_admin())
return;
global $submenu, $menu, $pagenow;
if ( current_user_can(\'manage_options\') ) { // ONLY DO THIS FOR ADMIN
if( $pagenow == \'index.php\' ) { // PRINTS ON DASHBOARD
echo \'<pre>\'; print_r( $menu ); echo \'</pre>\'; // TOP LEVEL MENUS
echo \'<pre>\'; print_r( $submenu ); echo \'</pre>\'; // SUBMENUS
}
}
}
add_action( \'admin_notices\', \'debug_admin_menus\' );
endif;
这些键将为您提供数组值,允许您使用wordpress全局变量执行所有这些操作(尽管不推荐)
function remove_submenus_all_please() {
if ( !is_admin())
return;
global $submenu;
unset($submenu[\'index.php\'][10]); // Removes Updates
//Posts menu
// unset($submenu[\'edit.php\'][5]); // Leads to listing of available posts to edit
// unset($submenu[\'edit.php\'][10]); // Add new post
// unset($submenu[\'edit.php\'][15]); // Remove categories
// unset($submenu[\'edit.php\'][16]); // Removes Post Tags
}
add_action(\'admin_menu\', \'remove_submenus_all_please\', 999);
要为某些用户删除,只需执行相同的操作,只需添加功能即可:
function remove_by_caps_admin_menu() {
if ( !is_admin())
return;
if ( !current_user_can(\'manage_options\') ) {
remove_menu_page( \'revslider\' ); // REVSLIDER
} elseif ( !current_user_can(\'edit_posts\') ) {
remove_menu_page( \'woocommerce\' ); // WOO
} else {
}
}
add_action(\'admin_menu\', \'remove_by_caps_admin_menu\', 999);
为了把它们联系在一起,为什么不缩短我们的代码?可以使用数组避免将remove\\u submenu\\u page写入50次。这也适用于工具栏节点:
if ( !function_exists( \'remove_admin_menupages_in_array\' ) ) {
function remove_admin_menupages_in_array() {
if ( !is_admin())
return;
$admin_menus = array(
\'revslider\',
\'woocommerce\',
\'shortcodes-ultimate\',
);
foreach ( $admin_menus as $menu_page ) {
if ( !current_user_can(\'manage_options\') ) {
remove_menu_page( $menu_page );
}
} // foreach
} // function
add_action(\'admin_menu\', \'remove_admin_menupages_in_array\', 9999);
} // exists