I think that the best approach is to add the edit_other_posts
capability to “author” role in plugin/theme activation and remove that capability on plugin/theme deactivation. With this method you only run the task once and you don’t need further coding.
Using plugin activation/deactivation:
register_activation_hook( __FILE__, 'cyb_activation_function' );
function cyb_activation_function() {
$author = get_role( 'author' );
$author->add_cap( 'edit_others_posts' );
}
register_deactivation_hook( __FILE__, 'cyb_deactivation_function');
function cyb_deactivation_function() {
$author = get_role( 'author' );
$author->remove_cap( 'edit_others_posts' );
}
Using theme activation/deactivation:
add_action('after_switch_theme', 'cyb_activation_function');
function cyb_activation_function() {
$author = get_role( 'author' );
$author->add_cap( 'edit_others_posts' );
}
add_action('switch_theme', 'cyb_deactivation_function');
function cyb_deactivation_function() {
$author = get_role( 'author' );
$author->remove_cap( 'edit_others_posts' );
}