Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#20010 closed defect (bug) (invalid)

get_user does not returns specific roles

Reported by: dejudicibus Owned by:
Priority: normal Milestone:
Component: Users Version: 3.3.1
Severity: normal Keywords:
Cc: Focuses:

Description

If I use get_users to return only the 'authors' by using the following code:

$user_options = array(
  'orderby' => 'display_name',
  'order'   => 'ASC',
  'role'    => 'author',
  'who'     => 'authors'
); 
$all_authors = get_users($users_options); 
foreach ($all_authors as $author) {
 if ($author->ID > 1) {
   /* do something */
 }
}

I get back all users but admin, that is, also subscribers.

Change History (2)

#1 @scribu
15 years ago

  • Milestone Awaiting Review
  • Resolution → invalid
  • Status new → closed

If you only want users with the 'author' role, remove the 'who' parameter. If you want all users who can create posts, remove the 'role' parameter. Using both doesn't make sense.

#2 @nacin
15 years ago

To further explain what is going on, 'who' => 'authors' selects all users of the blog who are not subscribers (using user_level != 0).

role=author is more restrictive. However, when who=authors is specified, $blog_id gets set to 0, which prevents role=author from being processed. The processing is a bit wonky, but this is proper behavior. Choose one or the other — who=authors is simply a shortcut that returns a superset of role=author.

You shouldn't be receiving subscribers back. who=authors should prevent that. Your subscribers likely have a wp_user_level of > 0, which is incorrect for subscribers.

Note: See TracTickets for help on using tickets.