I am not an expert in PHP/WordPress and I am running a WP site with multiple user levels. I have already created a custom post type called “race”. I would like to allow the Contributor level able to edit “races” that have been published from any other user, not only by themselves.
Currently, only the Author can do this, while Contributor can only edit the “races” himself has published.
The custom post type was made by CPT UI plugin and I did not code it myself.
I have a user role / capabilities plugin (“User Role Editor” and “Members”) and I know how to use them once the capabilities are registered, but I do not know how to set up the capabilities for a custom type post.
I think this entry is related to my problem (the last bit of code) but I do not know how to adapt it in the case that the post type already exists, and in which files the code should be inserted to.
PS. As a second step, I would like for edits to have to be approved by an Author anytime they are made by a contributor. Currently, if a contributor edits his own “race”, the changes are published immediately. Approval is only needed for initial publication right now.
WordPress has a filter, it is used to check your capability called “user_has_cap”. We can add “edit_other_posts” and “edit_published_posts” for Contributor through this. I have a code here for you, you can put it on your theme functions.php file or any php file in your plugin, try it:
Hope this help!
Add this bit of code to your functions file:
Then assign the capability ‘edit_others_races’ and ‘edit_races’ to the Contributor role and any others that you want to have the capability (Editor, Administrator, etc). Do not assign ‘publish_races’ to the Contributor role, as only the Author is supposed to do that.