WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 4 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
Milestone: 4.2 Priority: normal
Severity: normal Version: 3.5
Component: Users Keywords:
Focuses: multisite Cc:

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
5 years ago

  • Milestone changed from Awaiting Review to 4.2
  • Version changed from 4.1.1 to 3.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
5 years ago

In 32000:

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

See #31878.

#3 @boonebgorges
5 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

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.


4 years ago

Note: See TracTickets for help on using tickets.