Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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.

share|improve this answer
    
+1 This works as well. The admin header is included after the meta-boxes are set up with p_nav_menu_setup() –  Stephen Harris Mar 30 '12 at 17:09
    
Very cool! Thanks everyone for their help with this one! –  Zach Mar 30 '12 at 17:58

Instead of removing the metabox, you could hide it with CSS, e.g.:

#nav-menu-theme-locations {
    display: none;
}

Your issue with removing the box itself is most likely an issue with ordering, either trying to remove the box before it has been added, or removing it after it has already been sent to the user

share|improve this answer
    
Hey @Tom - I know I'm being a stickler, but would rather find a function to do this -- I figured the 9999 priority would take care of the ordering (making sure it's called last). I'm sure it's just "how" I'm calling it... –  Zach Mar 30 '12 at 16:15
    
No I meant the ordering of actions, e.g. the wp_nav_menu_setup action you're hooking into may be called too late or early in the process. –  Tom J Nowell Mar 30 '12 at 16:16
    
Bah - my bad. K I'll keep digging to see if I can find out. –  Zach Mar 30 '12 at 16:17

I don't think that's a hook. In fact there doesn't seem to be an appropriate one at all. But inside wp_nav_menu_setup(), the manage_nav-menus_columns is called shortly after the metaboxes are added. You can hook into that and remove it:

add_action( 'manage_nav-menus_columns', 'my_remove_meta_locations_box' );
function my_remove_meta_locations_box($columns) {
     if ( ! current_user_can('manage_options') )          
          remove_meta_box('nav-menu-theme-locations', 'nav-menus', 'side');

    return $columns;
}
share|improve this answer
    
By added, I don't mean added to the page, but when add_meta_box is called. –  Stephen Harris Mar 30 '12 at 16:31

A fast an easy option is to use the plugin Adminimize, this support this as option for different roles.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.