1

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?
3
  • I may be mistaken but the word that you are looking for may be 'Editor', if you want a user to edit/publish your contributors' posts. Let me write up an answer for you...
    – Christine Cooper
    Sep 22, 2013 at 16:20
  • If you're not a developer or at least like to dabble in code, it's probably better to use a plugin. Try: wordpress.org/plugins/user-role-editor You'll want to give them the edit_other_posts capability. Keep in mind this will let authors edit other authors posts as well. Sep 22, 2013 at 16:33
  • @AndrewBartel there is a solution to that issue linked in my answer.
    – Christine Cooper
    Sep 22, 2013 at 16:39

3 Answers 3

2

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' ); 

}
1
  • 1
    This turned out to be some comprehensive answers to a relatively poor question that has been asked (in way better form) numerous times. ;)
    – Christine Cooper
    Jun 26, 2014 at 14:41
0

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.

-1

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.

4
  • the parameter for current_user_can is a capability and 'author' is not a capability, it is a role. Also, instead of using $GLOBALS['wp_roles'] it is much better use get_role to get the role object you want to modify.
    – cybmeta
    Jun 18, 2014 at 5:34
  • @cybmeta While it is true that 'author' is not a capability, you can still add a role for the $capability parameter. Glad you shared an improvement to this solution, but not entirely certain if it was necessary to downvote the otherwise correct answer.
    – Christine Cooper
    Jun 21, 2014 at 14:49
  • See notes about passing roles to current_user_can and read the reference of the function. It is not intended to accept a role as parameter. I'm sorry for the downvote but I really think that your answer is not good.
    – cybmeta
    Jun 25, 2014 at 18:12
  • See my answer to see why it can not be an edition of yours.
    – cybmeta
    Jun 26, 2014 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.