除了问题中的代码外,
1. To display only the author roles in the user list page of editor:
add_action(\'pre_user_query\',\'editors_edit_author_list\');
function editors_edit_author_list($user_search) {
$user = wp_get_current_user();
if($user->ID != 1) {
$user_meta=get_userdata($user->ID);
//$user_roles= $user_meta->roles;
global $wpdb;
if(in_array(\'editor\', $user_meta->roles))
{
$user_search->query_where = str_replace(
\'WHERE 1=1\',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = \'{$wpdb->prefix}capabilities\'
AND {$wpdb->usermeta}.meta_value LIKE \'%author%\')",
$user_search->query_where
);
}
else
$user_search->query_where = str_replace(\'WHERE 1=1\', "WHERE 1=1 AND {$wpdb->users}.ID<>1", $user_search->query_where);
}
}
<小时/>
2. Make editors only edit the authors:
add_filter(\'editable_roles\', array($this, \'editor_editable_roles\'));
function editor_editable_roles($roles)
{
$user = wp_get_current_user();
$user_meta=get_userdata($user->ID);
if(in_array(\'editor\', $user_meta->roles)) {
$tmp = array_keys($roles);
foreach($tmp as $r) {
if(\'author\' == $r)
continue;
unset($roles[$r]);
}
}
return $roles;
}
<小时/>
3. Change the users added by the editor to author role (from the \'new user default role\'):
add_action( \'profile_update\', \'process_editor_added_user\', 10, 1 );
add_action( \'user_register\', \'process_editor_added_user\', 10, 1 );
function process_editor_added_user($user_id)
{
$user = wp_get_current_user();
if($user->ID != $user_id)
{
$u = new WP_User($user_id);
$u->remove_role(\'subscriber\');
$u->add_role(\'author\');
}
}
第#3点有一个替代方案
hijacking the default new user role. 我没有对此进行测试:
add_filter(\'pre_option_default_role\', function($default_role){
return \'author\';
});
似乎就这些了。