Automattic / Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
https://wordpress.org/plugins/co-authors-plus/
GNU General Public License v2.0
291 stars 204 forks source link

Code Snippet: Allow authors to change co-authors #104

Open danielbachhuber opened 11 years ago

danielbachhuber commented 11 years ago

Once we finish #103, we should write a code snippet to show users how to let their authors change co-authors

Requests:

jongleur1983 commented 11 years ago

I stumbled upon this myself, so if there's anything I could help, please drop me a note. I didn't dive deep enough into the plugin code yet, but shouldn't it work to add coauthors_plus_edit_authors as a privilege to user accounts (true by defaulf for editor role and above) and handle that instead of or additionally to the other ones in current_user_can_set_authors() (co-authors-plus.php)? If somebody would confirm that this is all that has to be done, I probably could make patch.

rebeccahum commented 7 years ago

I fixed the current snippet to work:

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 );
}
JoshJourney commented 5 years ago

@rebeccahum Absolutely fantastic! Now authors can assign authors to post without needing to be an editor. The only downside is that "new authors" can take over a post. So if User1 assigns User2 to a post (both have a role of author) User2 can remove User1 from the post author. DB table wp_posts stores the post_author the same as before assigning a co-author. In other words perhaps the filter could pass a condition check such as if(postAuthor) {add_filter...}. While it sounds unlikely for a user to stoop that low, I've seen petty people "steal pages" followed by admin investigations unfold.