admin管理员组

文章数量:1434924

Author dropdown

I am using classic editor and in edit page herer is a 'Author' dropdown and I want to modify value of this edit page (post type = 'page') authors dropdown. I want to show all users in this author dropdown of in edit page only when user logged as Admin/Administrator role type.

Want to change the list of users in the Author select dropdown on the edit page for Admin/Administrator role type users. I tried but not working for post type page.

I have 3 admin role user and when i logged as one of admin role type user i want all users are show in this author dropdown so admin can set any type of user as page(post type = page) author. currently by default only editors names are displaying in this author dropdown and i want to show all users.

I tried this without check user role but is not working for me in edit page in worpdress.

add_filter( 'wp_dropdown_users_args', 'change_user_dropdown', 10, 2 );

function change_user_dropdown( $query_args, $r ){
    // get screen object
    $screen = get_current_screen();

    // list users whose role is e.g. 'Author' for 'post' post type
    if( $screen->post_type == 'page' ):
        $query_args['role'] = array('Author');

        // unset default role 
        unset( $query_args['who'] );
    endif;

    

    return $query_args;
}

Author dropdown

I am using classic editor and in edit page herer is a 'Author' dropdown and I want to modify value of this edit page (post type = 'page') authors dropdown. I want to show all users in this author dropdown of in edit page only when user logged as Admin/Administrator role type.

Want to change the list of users in the Author select dropdown on the edit page for Admin/Administrator role type users. I tried but not working for post type page.

I have 3 admin role user and when i logged as one of admin role type user i want all users are show in this author dropdown so admin can set any type of user as page(post type = page) author. currently by default only editors names are displaying in this author dropdown and i want to show all users.

I tried this without check user role but is not working for me in edit page in worpdress.

add_filter( 'wp_dropdown_users_args', 'change_user_dropdown', 10, 2 );

function change_user_dropdown( $query_args, $r ){
    // get screen object
    $screen = get_current_screen();

    // list users whose role is e.g. 'Author' for 'post' post type
    if( $screen->post_type == 'page' ):
        $query_args['role'] = array('Author');

        // unset default role 
        unset( $query_args['who'] );
    endif;

    

    return $query_args;
}
Share Improve this question edited Nov 20, 2024 at 4:33 Sunshine asked Nov 18, 2024 at 11:20 SunshineSunshine 32 bronze badges 2
  • what do you need in this dropdown is the user is not administrator ? – mmm Commented Nov 18, 2024 at 12:49
  • I have 3 admin role user and when i logged as one of admin role type user i want all users are show in this author dropdown so admin can set any type of user as page(post type page) author. currently by default admin can see editors name in this author dropdown. – Sunshine Commented Nov 19, 2024 at 4:04
Add a comment  | 

2 Answers 2

Reset to default 0
add_filter('wp_dropdown_users_args', function ($query_args, $r) {
if (current_user_can('administrator')) {
    unset($query_args['who']);
}
return $query_args;
}, 10, 2);

as you don't explain if there is something to change when non administrator users edit a page, here is my answer to change the author list when the connected user has the capability edit_others_pages. you can change it according to your needs.

note also that the filter wp_dropdown_users_args works only on classical editor (like we see it on your screenshot) and not on gutenberg editor.

add_filter("wp_dropdown_users_args", function ($query_args, $parsed_args) {
    
    // the capability "edit_others_pages" can be change to another linked at the reason of the customisation
    if (current_user_can("edit_others_pages")) {
        
        // remove the filter on capabilities to return all users
        unset($query_args["capability"]);
        
    }
    
    
    return $query_args;
    
}, 10, 2);

本文标签: