Allowing authors to set co-authors

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:

4 Comments

Coby Royer January 23, 2013 Reply

This is now broken with 3.0.4 version of co-authors-plus. Could you post an updated snippet?

Daniel Bachhuber January 24, 2013 Reply

Yeah, I’ll take a look when I have a moment.

Rebecca Hum January 8, 2018 Reply

Here’s an updated snippet:

add_filter( 'coauthors_plus_edit_authors', 'filter_coauthors_edit_cap', 10, 2 );

function filter_coauthors_edit_cap( $cap_result ) {
	global $coauthors_plus;

	$post_type = get_current_screen()->post_type;

	if( empty ( $post_type ) ) {
		return false;
	}

	$post_type_object = get_post_type_object( $post_type );

	return current_user_can( $post_type_object->cap->publish_posts );
}
David February 13, 2013 Reply

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.

Leave a Reply