Skip to content

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

Open
@mecraft

Description

@mecraft

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions