Been digging into WP files for a bit and think I just might be missing something. The end-goal is to remove the Theme Locations
metabox from the Menus screen if someone doesn’t have a certain capability manage_options
. I know, a little odd for usability, but there’s only one menu and we’re trying to make this harder to screw up 😉
Looking at /wp-admin/nav-menu.php
around line 383
I see wp_nav_menu_setup()
so I tried to add the following as a filter, but with no luck so far:
function roots_remove_nav_menu_metaboxes() {
// Remove Theme Locations from users without the 'manage_options' capability
if (current_user_can('manage_options') == false) {
remove_meta_box('wp_nav_menu_locations_meta_box', 'nav-menus', 'side'); // theme locations
}
}
add_action('wp_nav_menu_setup', 'roots_remove_nav_menu_metaboxes',9999);
Any help would be really appreciated. Thanks!
4 Answers
The box gets added in wp_nav_menu_setup(), so you’ll have to remove it sometime after that and before it’s being output later in nav-menus.php. There don’t seem to be any action hooks you can use there, but admin-header.php has a few. You could try this:
add_action( 'admin_head-nav-menus.php', 'roots_remove_nav_menu_metaboxes' );
I’ve never tried removing metaboxes from the menu screen, though, and it’s untested, so no idea if it works.