Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#31878 closed defect (bug) (fixed)

get_users() on multisite returns empty user roles when other blog_id provided

Reported by: Kubitomakita Owned by: boonebgorges
Priority: normal Milestone: 4.2
Component: Users Version: 3.5
Severity: normal Keywords:
Cc: Focuses: multisite

Description

For example if you'll query:

get_users( array( 'blog_id' => 2 ) );

This will return:

[0] => WP_User Object
        (
            [data] => stdClass Object
                (
                    [ID] => XX
                    [user_login] => XXX
                    [user_pass] => XXX
                    [user_nicename] => XXX
                    [user_email] => XXX
                    [user_url] => 
                    [user_registered] => XXX
                    [user_activation_key] => 
                    [user_status] => 0
                    [display_name] => XXX
                    [spam] => 0
                    [deleted] => 0
                )

            [ID] => XX
            [caps] => Array
                (
                )

            [cap_key] => wp_capabilities
            [roles] => Array
                (
                )

            [allcaps] => Array
                (
                )

            [filter] => 
        )

Even if user got role specified for the blog with ID 2.

Change History (4)

#1 @boonebgorges
11 years ago

  • Milestone Awaiting Review4.2
  • Version 4.1.13.5

Thanks for the report.

I've confirmed the issue. The problem is not that 'roles' is *empty* per se, it's that roles/caps are being populated from the wrong site in some cases (and in your situation, the user doesn't have any role at all on the current site). In [15566], WP_User_Query was modified to ensure that caps are fetched from the proper 'blog_id'; in [22248], WP_User_Query was modified to return WP_User objects when 'fields=all', but the blog_id fix from [15566] was not included in the latter changeset.

#2 @boonebgorges
11 years ago

In 32000:

Unit tests verifying the filling of the 'roles' and 'caps' user properties during WP_User_Query.

See #31878.

#3 @boonebgorges
11 years ago

  • Owner set to boonebgorges
  • Resolutionfixed
  • Status newclosed

In 32001:

WP_User_Query: When querying users with 'fields=all', ensure that caps and roles are filled for the current site.

See [15566] for a parallel fix for 'fields=all_with_meta'.

Fixes #31878.

This ticket was mentioned in Slack in #core by ryanduff. View the logs.


10 years ago

Note: See TracTickets for help on using tickets.