remove meta box in the wp editor

Posted in: Newspaper
Post count: 14

hy, in order to remove some metabox in the wp editor for not-administrator users, i’m using this function:

****************************

if (is_admin()) :
function my_remove_meta_boxes() {
if( !current_user_can(‘manage_options’) ) {
remove_meta_box(‘postcustom’, ‘post’, ‘normal’);
}
}
add_action( ‘admin_menu’, ‘my_remove_meta_boxes’ );
endif;

****************************

it works but if i want also to hide some of your theme boxes, the function doesn’t work. for example i add this:

****************************

remove_meta_box(‘td_post_video_metabox’, ‘post’, ‘normal’);
remove_meta_box(‘td_post_theme_settings_metabox’, ‘post’, ‘normal’);
remove_meta_box(‘td_review_metabox’, ‘post’, ‘normal’);
remove_meta_box(‘rs_post_editor’, ‘post’, ‘normal’);
remove_meta_box(‘rs_post_contributor’, ‘post’, ‘normal’);
remove_meta_box(‘rs_private_post_reader’, ‘post’, ‘normal’);

****************************

why? where i am wrong?

thnak you

Post count: 1291

Hi,

The theme uses the WPAlchemy_MetaBox class for adding meta boxes – http://screencast.com/t/O2OJkPt4
You could use the following function – https://codex.wordpress.org/Function_Reference/current_user_can – and replace the is_admin() condition.

Thank you, Emil G.

Post count: 14

sorry, i’m afraid i do not understand how to do.

i need to hide these metaboxes (just some but not all) for no-admin users:

td_post_video_metabox
td_post_theme_settings_metabox
td_review_metabox
rs_post_editor
rs_post_contributor
rs_private_post_reader

can you please tell me what should i add in the functions.php?

thanks

Post count: 1291

Hi,

You have to modify the code like this – http://screencast.com/t/wdxG3EaCLYhttp://screencast.com/t/A6wgqp98

current_user_can( 'manage_options' )

You cannot add it in the functions.php

Thank you, Emil G.

  • This reply was modified 11 years by Emil G.
Post count: 14

i followed your instructions but it doesn’t work. no-admin users can still view the metaboxes 🙁

Post count: 14

i’m using the plugins “user role editor” and “role scoper” with different groups of users. but the administrator is just one… what’s wrong?

thanks

Post count: 6600

Hi,

Replace all code from this file: http://screencast.com/t/CEwcrJj11tT with this one: http://pastebin.com/9ySVNP7L
This will allow access to theme’s meta boxes just for super admin and accounts: https://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table

Thanks

Post count: 14

great! finally it works now. thank you

Post count: 61

How this can be done in the latest theme version?

Thanks

Post count: 35449

Hi pbc,

Yes, that can be done; but now is no need, because you can set for each user what role to have https://www.screencast.com/t/jGhy6aoLoamR

Thank you.

Viewing 10 posts - 1 through 10 (of 10 total)
The forum ‘Newspaper’ is closed to new topics and replies.