In the WordPress.org forums, whoaloic asks:
I have a site with multiple authors.
I would like to allow authors who create a post or a page to give rights to other authors.
For now, only administrator and editor can do that.
Is there a solution?
Yep, totally doable. By default, Co-Authors Plus defaults to ‘edit_others_posts’ as the required cap for changing co-authors. With the following code snippet in your theme’s functions.php file, you can make that cap ‘publish_posts’ instead (which authors and above usually have).
[sourcecode language=”php”]
/**
* Filter the Co-Authors Plus current_user_can_set_authors() function
* so that users with ‘publish_posts’ can set Co-Authors
*
* @author danielbachhuber
*
* @see https://github.com/danielbachhuber/Co-Authors-Plus/issues/8
* @see http://wordpress.org/support/topic/plugin-co-authors-plus-allow-authors-post-to-give-access-to-other-authors
*/
add_filter( ‘coauthors_plus_edit_authors’, ‘db_filter_coauthors_edit_cap’ );
function db_filter_coauthors_edit_cap( $cap_result ) {
global $coauthors_plus;
$post_type = $coauthors_plus->get_current_post_type();
if( ! $post_type ) return false;
$post_type_object = get_post_type_object( $post_type );
return current_user_can( $post_type_object->cap->publish_posts );
}
[/sourcecode]
In preparing this snippet, I also opened a couple of issues in Github:
- Allow authors to set co-authors by default – I’m not sure why we restricted it to editors and admins originally. Also, the existing filter could use cleanup.
- Don’t show search box if user doesn’t have capability to change co-authors – We should have a “locked” UI if the user doesn’t have the appropriate cap
4 Comments
This is now broken with 3.0.4 version of co-authors-plus. Could you post an updated snippet?
Yeah, I’ll take a look when I have a moment.
Here’s an updated snippet:
I’ll bump this! Would love to be able to use this capability with our ‘Authors’, but right now the snippet is broken with the new version.