Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mecraft opened this issue Mar 21, 2024 · 0 comments
Open

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

mecraft opened this issue Mar 21, 2024 · 0 comments

Comments

@mecraft
Copy link

mecraft commented Mar 21, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant