- This topic has 9 replies, 2 voices, and was last updated 8 years, 11 months ago by
Tom.
-
AuthorPosts
-
October 17, 2014 at 9:05 am #39762
Manny
Hello All,
Does anyone know how to remove the sidebar layout meta box OR the footer widget meta box from the backend view for those who aren’t admins?
I’ve been trying the following with no luck. A look inside the inc/metaboxes file didn’t help as I guess I cannot pinpoint the id. The code below should work. Thank you!
if( !current_user_can(‘administrator’) ) {
// Function: Removes Sidebar Layout and Footer Widget Meta Boxes
function remove_generate_metaboxes() {
remove_meta_box( ‘generate_add_layout_meta_box’, ‘post’, ‘high’);
remove_meta_box( ‘generate_layout_meta_box’, ‘post’, ‘high’);
remove_meta_box( ‘generate_show_layout_meta_box’, ‘post’, ‘high’ );
}
add_action(‘add_meta_boxes_page’, ‘remove_generate_metaboxes’);
} //end function
} //end if not adminOctober 17, 2014 at 9:08 am #39763Manny
CORRECTION:
add_action(‘add_meta_boxes’, ‘remove_generate_metaboxes’);
INSTEAD OF:
add_action(‘add_meta_boxes_page’, ‘remove_generate_metaboxes’);
October 17, 2014 at 10:00 am #39787Tom
Lead DeveloperLead DeveloperHi Manny,
By default, only administrators should be able to see these metaboxes.
You can try that same function, but with this instead:
add_action('add_meta_boxes', 'remove_generate_metaboxes', 9999);
October 17, 2014 at 10:10 am #39796Manny
Thanks for the prompt reply Tom.
Admins only yes, but I don’t want it to show for anyone below the ‘Editor’ role which, currently, it does. I log in with a contributors account and see the layout and footer widget metaboxes. Tried the recommended solution and the metaboxes remained. Will continue tinkering with this code. Again, much appreciate the support.
October 17, 2014 at 10:15 am #39800Tom
Lead DeveloperLead DeveloperInteresting – I’ll have to look into that, as I agree only administrators should be able to change those options.
What might be happening is you have “post” set in your remove_metabox function:
remove_meta_box( ‘generate_add_layout_meta_box’, ‘post‘, ‘high’);
That will only remove it on the “post” post type, but not on “Pages” or any other post type.
Just a guess?
October 17, 2014 at 10:44 am #39811Manny
Again, thank you Tom.
That is where I am specifically attempting to hide it from (“posts”) but I have also tried “pages” to no avail.
Just tried it on another site to confirm and sidebar/footer widget metaboxes appears there as well for contributors. Contributors should be able to post but not alter the layout or footer widgets (at least that is how I am attempting to set it up).
Tried seeing if a contributor can actually alter the sidebar/footer and indeed they can.
Will continue to tinker on the code above to create a sort of patch. I could probably just edit the inc/metaboxes.php file with is_admin(); but upon an update that would go bye-bye.
Much appreciate the prompt and courteous support.
October 17, 2014 at 10:50 am #39812Tom
Lead DeveloperLead DeveloperThis may work:
if (is_admin()) : function my_remove_meta_boxes() { if(!current_user_can('administrator')) { //remove_meta_box stuff } } add_action( 'admin_menu', 'my_remove_meta_boxes' ); endif;
October 17, 2014 at 10:54 am #39816Manny
Tom,
I added to the inc/metaboxes.php file the following on the first line:
if( current_user_can('administrator') ) {
Then closed at bottom with:
}
And this has removed both metaboxes from all but admins view. I just have to remember upon an update to redo this 🙂
Interestingly enough, it wouldn’t work if only applied to the function generate_add_layout_meta_box(). All related functions had to be encased to get it to work.
Posted this ‘horrible fix’ in case another needs it in a pinch. I do not recommend this at all.
October 17, 2014 at 11:13 am #39817Manny
Went back because your solution would be better (updating the functions.php file within child theme). However, after multiple attempted variations I was unable to achieve the desired effect. I even tried just removing the metaboxes for all users .
function my_remove_meta_boxes() { remove_meta_box( 'generate_layout_meta_box', 'post', 99999); remove_meta_box( 'generate_save_layout_meta', 'post', 99999); } add_action( 'add_meta_boxes', 'my_remove_meta_boxes', 99999 ); add_action( 'admin_menu', 'my_remove_meta_boxes', 99999 ); add_action('save_post', 'my_remove_meta_boxes', 99999);
October 20, 2014 at 10:03 am #40497Tom
Lead DeveloperLead DeveloperI’ve made it so the next version will only show these metaboxes for admins.
For those of you who want to change that, I added a filter so you can change the required capability.
-
AuthorPosts
- You must be logged in to reply to this topic.