我认为最好的方法是添加edit_other_posts
能够在插件/主题激活中“编写”角色,并在插件/主题停用时删除该功能。使用此方法,您只需运行一次任务,无需进一步编码。
使用插件激活/停用:
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\' );
}
使用主题激活/停用:
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\' );
}