I have added some extra capabilities to the existing 'editor' role in wordpress with:

function add_uedit_caps() {
    $role = get_role('editor');
add_action('admin_init', 'add_uedit_caps');

This piece works fine.


The above code works to list and view all types of users by the 'editor'. But if a new user added by the 'editor', it takes up the 'new user default role' set up in wordpress (reference), ie the role set in settings > general. No role change option is available too in the user edit mode.

I want the 'editors' to list/view/add/edit only the users with the role 'author'. How can I achieve this through code (a method or class with action) and WITHOUT any plugin or tampering the core files?

1 Answer 1


In addition to the code piece in the question,

1. To display only the author roles in the user list page of editor:


function editors_edit_author_list($user_search) {
        $user = wp_get_current_user();
        if($user->ID != 1) {
            //$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 = 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();
        if(in_array('editor', $user_meta->roles)) {
            $tmp = array_keys($roles);
            foreach($tmp as $r) {
                if('author' == $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);

There is an alternative to point #3 by hijacking the default new user role. I have not tested this:

add_filter('pre_option_default_role', function($default_role){
    return 'author';

That's seems to be all.

  • This still works great! Thanks!
    – Gavin
    Commented Apr 17, 2023 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.