[wp-trac] [WordPress Trac] #38851: WP_User_Query cannot retrieve multisite users who have not been assigned a role on a site

WordPress Trac noreply at wordpress.org
Fri Nov 18 15:11:33 UTC 2016


#38851: WP_User_Query cannot retrieve multisite users who have not been assigned a
role on a site
--------------------------+-----------------------------
 Reporter:  robdxw        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Users         |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 If you add a user to a multisite at network level, but do not proceed to
 assign them a role on a site within the network, `WP_User_Query` cannot
 retrieve those users (even if the query is run at network level), as they
 have no associated `wp_capabilities` meta_key.

 To reproduce the problem:

 1) Add a user to a multisite via Network Admin > Users > Add New.
 2) Run a WP_User_Query at network level (e.g. by doing something like:

 {{{
 add_action('load-users.php', 'myAction');

 function myAction()
 {
   $screen = get_current_screen();
   if( $screen->base === 'users-network' {
     $query = new WP_User_Query();
     $users = $query->results;
   }
 }
 }}}

 The returned results will not include the user added in step 1. In fact,
 it will only return users who have capabilities set on the first site in
 the network, even though this query is not occurring at site level.

 This could be fixed by allowing something like `'blog_id' => 'all'` in a
 `WP_User_Query`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38851>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list