How to give capability (publish contributors posts) to author role?

I am not a PHP programmer, just a simple WordPress user.

  • How can I allow author role to allow publication of contributors posts?
  • What’s the technical name for this?

Related posts

3 comments

  1. I think that the best approach is to add the edit_other_posts capability to “author” role in plugin/theme activation and remove that capability on plugin/theme deactivation. With this method you only run the task once and you don’t need further coding.

    Using plugin activation/deactivation:

    register_activation_hook( __FILE__, 'cyb_activation_function' );
    function cyb_activation_function() {
    
        $author = get_role( 'author' );
        $author->add_cap( 'edit_others_posts' ); 
    
    }
    
    register_deactivation_hook( __FILE__, 'cyb_deactivation_function');
    function cyb_deactivation_function() {
    
        $author = get_role( 'author' );
        $author->remove_cap( 'edit_others_posts' ); 
    
    }
    

    Using theme activation/deactivation:

    add_action('after_switch_theme', 'cyb_activation_function');
    function cyb_activation_function() {
    
        $author = get_role( 'author' );
        $author->add_cap( 'edit_others_posts' ); 
    
    }
    
    add_action('switch_theme', 'cyb_deactivation_function');
    function cyb_deactivation_function() {
    
        $author = get_role( 'author' );
        $author->remove_cap( 'edit_others_posts' ); 
    
    }
    
  2. Obviously, a role’s capabilities can be altered programmatically, but given that you are

    not a PHP programmer, just a simple WordPress user

    you will have to make use of a plugin that allows modification of user roles.
    There’s a bunch out there, but my personal recommendation would be the Members plugin by Justin Tadlock.

    What’s the technical name for this?

    Every role has a bunch of capabilities assigned to them.
    That’s the terms you were looking for.

    How can I allow author role to allow publication of contributors posts?

    The capability you need here is edit_others_posts.

  3. The term that you are looking for is Editor. If you are referring to a user that can edit/publish your contributors’ posts.

    You want to learn about Roles and Capabilities via its codex entry. In order to have your users with the Author user role to be able to edit and publish pending posts, you will need to assign the capability edit_others_posts to this role.

    Add the following to your functions.php file (using add_cap, code based on kaiser’s answer):

    function add_edit_others_posts_to_author_role() 
    {
        if ( ! current_user_can( 'author' ) )
            return;
    
        // here you should check if the role already has_cap already and if so, abort/return;
    
        if ( current_user_can( 'author' ) ) 
        {
            $GLOBALS['wp_roles']->add_cap( 'author','edit_others_posts' );
        }
    }
    add_action( 'admin_init', 'add_edit_others_posts_to_author_role', 10, 0 );
    

    Or alternatively, you could use a plugin like User Role Editor. You may as well consider that this will allow your author leveled users to edit published posts. There is a good solution posted that allow Editors to edit pending posts but not draft ones.

Comments are closed.