Solution:
I don’t usually do this, but you may be better off just using a Role Editor plugin like User Role Editor. The alternatives would be to give the Roles & Capabilities documentation a read, and decide if it’s better to modify an existing role, or creating a new role and give it the select permissions you want.
For instance, you’d probably want to create a new role based on the editor
role, and remove all of the {blank}_others_{blank}
capabilities, such as edit_others_posts
, delete_others_posts
, etc.
If you do go the programatic way instead of plugin, note that the Roles & Capabilities are stored in the database, so you don’t need to include the function that creates/modifies them on every load like the init
hook. If you do put it on a hook like that, you’ll probably want to set a flag of some sort (like with update_option()
) and abort if the new role/cap hasn’t been changed since it was last run.