• I’m trying to delete some post meta fileds for specific user roles. “Author” to be exact. This is what I have so far. It deletes the field for the “Author” role, but also for admin. I just want to delete the field for “Author’s”.

    function remove_post_excerpt_field() {
    	if(is_author())
    	remove_meta_box('postexcerpt', 'post', 'normal' );
    add_action('admin_menu', 'remove_post_excerpt_field');
    }
Viewing 1 replies (of 1 total)
  • You could remove it for users that can’t edit pages, that would leave the box in place for admins and editors, whilst removing it for other roles(or roles that can’t edit pages at least).

    add_action( 'do_meta_boxes', 'box_perms' );
    
    function box_perms() {
    	if( !current_user_can( 'edit_pages' ) )
    		remove_meta_box( 'postexcerpt', 'post', 'normal' );
    	return;
    }

    NOTES: When you hook onto an action, the hooking should occur outside the function you’re using as a callback. For modifying metaboxes, use the do_meta_boxes hook, admin_menu is more appropriate for adding and removing admin menu items(hence the name).

Viewing 1 replies (of 1 total)
  • The topic ‘Remove metaboxes based on role’ is closed to new replies.