The capabilities that you are trying to restrict are
- delete_others_posts
- edit_others_posts
Apart from Super Admin and Administrator, the only Role that have these permission is Editor. So, removing these capabilities from Editor should accomplish this.
/**
* Remove capabilities from editors.
*
* Call the function when your plugin/theme is activated.
*/
function wpcodex_set_capabilities() {
// Get the role object.
$editor = get_role( 'editor' );
// A list of capabilities to remove from editors.
$caps = array(
'delete_others_posts',
'edit_others_posts',
);
foreach ( $caps as $cap ) {
// Remove the capability.
$editor->remove_cap( $cap );
}
}
add_action( 'init', 'wpcodex_set_capabilities' );
You should only run this code during a plugin or theme activation. From Codex
Note: This setting is saved to the database (in table wp_options, field ‘wp_user_roles’), so you should run this only once, on theme/plugin activation and/or deactivation.