Automattic / Co-Authors-Plus

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

Co-authors can't delete/trash posts #1029

Open mecraft opened 3 months ago

mecraft commented 3 months ago

The first author of a post has the ability to delete it (depending on status, etc), but co-authors can't. Wordpress checks the capability "delete_others_posts" for co-authors, even though they're an "author". Basically, to the co-author, the option to "Move to Trash" is not displayed.

A functional workaround: the co-author can rearrange the authors to make themselves the first author, save, then delete the post.

I added the following fix for our environment. It may not work properly with other environments/workflows.

function allow_coauthor_delete($allcaps, $cap, $args) {
    if ($cap[0] === 'delete_others_posts') {
        if ($allcaps['delete_others_posts'] == true) {
            return $allcaps;
        }
        if (current_user_can('edit_post', $args[2])) {
            $allcaps['delete_others_posts'] = true;
        }
        return $allcaps;
    }
    return $allcaps;
}
add_filter('user_has_cap', 'allow_coauthor_delete', 10, 3);

I don't know if this is the best way to fix this.