I have a large number of users with Editor Capabilities that help to go through the post submissions. This is my current setup for this role:
As you can see, they are allowed to edit_posts
and edit_others_posts
but they cannot edit_published_posts
. This means that they can edit posts that are in Draft and Pending status.
Now, I want to restrict them to only be able to edit pending posts. So, they won’t have the ability to touch draft posts (unless if they are the author of the post). Unfortunately there is no capability like edit_pending_posts
… there should be.
How do I solve this?
This is actually not hard. To add a new capability, call
WP_Roles->add_cap()
. You have to do this just once, because it will be stored in the database. So we use a plugin activation hook.Note to other readers: All of the following code is plugin territory.
Now we have to filter all calls for â¦
⦠because that is how WordPress checks if an user can edit a post. Internally, this will be mapped to the
edit_others_posts
capability for other authors posts.So we have to filter
user_has_cap
and look into our newedit_pending_posts
capability when some wants to use theedit_post
capability.I have included
delete_post
too, because this also a kind of an edit.Sound complicated, but it is really simple: