Users with new role created with add_role don't appear in author meta box (2 posts)

  1. Ross Wintle
    Posted 4 years ago #

    Hi folks,

    I've created a new role, let's call it "Posters". I've assigned this role three capabilities, the same three as a contributor gets:
    - read
    - edit_posts
    - delete_posts

    Users with this new role don't appear in the author meta box.

    From what I can tell, the author meta box uses wp_dropdown_users to generate the list, and it passes 'who' => 'authors'

    This is then picked up, eventually, by WP_User_Query->prepare_query() which does this:

    if ( 'authors' == $qv['who'] && $blog_id ) {
    	$qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';
    	$qv['meta_value'] = '_wp_zero_value'; // Hack to pass '0'
    	$qv['meta_compare'] = '!=';
    	$qv['blog_id'] = $blog_id = 0; // Prevent extra meta query

    I don't know the exact ins and outs but am I right in saying that this still uses user levels to generate the list, and it only gives users who have a user level greater than zero?

    My assumption here is that users in a role created with add_role don't have a user level, and are therefore not included by this query.

    This seems odd. I'd even class it as a bug! This list should contain any user with the edit_posts capability, not any user with a non-zero user level.

    Can anyone confirm that my understanding is correct? And if so should I log it as a bug? Also, is there a quick-and-easy way to get, say, users with the edit_posts capability included in this list?

    It would also be nice to have some filter hooks in post_author_meta_box() and wp_dropdown_users() to allow some modification of the parameters used to build the query. The only way to edit this list from a theme/plugin seems to be to edit the HTML output of wp_dropdown_users using the wp_dropdown_users filter. Not ideal! Anyone agree?


  2. Ross Wintle
    Posted 4 years ago #

    Looks like this was introduced in Trac ID 15871 and spotted in Trac ID 16841. Adding to those discussions.

Topic Closed

This topic has been closed to new replies.

About this Topic