WordPress.org

Ready to get started?Download WordPress

Forums

Remove metaboxes based on role (2 posts)

  1. bweb79
    Member
    Posted 3 years ago #

    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');
    }
  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    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).

Topic Closed

This topic has been closed to new replies.

About this Topic