[wp-trac] [WordPress Trac] #37499: WP_User_Query:prepare_query() bug leads to user meta query with blog_id 0

WordPress Trac noreply at wordpress.org
Thu Jul 28 17:10:59 UTC 2016


#37499: WP_User_Query:prepare_query() bug leads to user meta query with blog_id 0
-------------------------------------------------+-------------------------
 Reporter:  stephdau                             |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  4.6
Component:  Users                                |     Version:  trunk
 Severity:  normal                               |  Resolution:
 Keywords:  needs-patch needs-unit-tests         |     Focuses:  multisite
  reporter-feedback                              |
-------------------------------------------------+-------------------------
Changes (by boonebgorges):

 * keywords:  needs-patch needs-unit-tests => needs-patch needs-unit-tests
     reporter-feedback


Comment:

 Hi @stephdau - Thanks for the report.

 At a glance, I'm not seeing how to reproduce the problem. Here's the
 `WP_User_Query` object (including its `request` and query results), as
 generated at the end of `prepare_query()`, when created via
 `wp_dropdown_users()` on the Author metabox of a single post on a
 secondary site in a multisite network:

 {{{
  WP_User_Query Object
 (
     [query_vars] => Array
         (
             [blog_id] => 0
             [role] =>
             [role__in] => Array
                 (
                 )

             [role__not_in] => Array
                 (
                 )

             [meta_key] =>
             [meta_value] =>
             [meta_compare] =>
             [include] =>
             [exclude] =>
             [search] =>
             [search_columns] => Array
                 (
                 )

             [orderby] => display_name
             [order] => ASC
             [offset] =>
             [number] =>
             [paged] => 1
             [count_total] =>
             [fields] => Array
                 (
                     [0] => ID
                     [1] => user_login
                     [2] => display_name
                 )

             [who] => authors
             [has_published_posts] =>
         )

     [results:WP_User_Query:private] =>
     [total_users:WP_User_Query:private] => 0
     [meta_query] => WP_Meta_Query Object
         (
             [queries] => Array
                 (
                     [0] => Array
                         (
                             [key] => wp_2_user_level
                             [value] => 0
                             [compare] => !=
                         )

                 )

             [relation] =>
             [meta_table] => wp_usermeta
             [meta_id_column] => user_id
             [primary_table] => wp_users
             [primary_id_column] => ID
             [table_aliases:protected] => Array
                 (
                     [0] => wp_usermeta
                 )

             [clauses:protected] => Array
                 (
                     [wp_usermeta] => Array
                         (
                             [key] => wp_2_user_level
                             [value] => 0
                             [compare] => !=
                             [alias] => wp_usermeta
                             [cast] => CHAR
                         )

                 )

             [has_or_relation:protected] =>
         )

     [request] =>
     [compat_fields:WP_User_Query:private] => Array
         (
             [0] => results
             [1] => total_users
         )

     [query_fields] =>
 wp_users.ID,wp_users.user_login,wp_users.display_name
     [query_from] => FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID
 = wp_usermeta.user_id )
     [query_where] => WHERE 1=1 AND (
   ( wp_usermeta.meta_key = 'wp_2_user_level' AND wp_usermeta.meta_value !=
 '0' )
 )
     [query_orderby] => ORDER BY display_name ASC
     [query_limit] =>
 )
 }}}

 The `blog_id` "zeroing" happens inside of the `who` block. The idea here
 (introduced in [17088]) is that if you're doing `who=authors`, then
 further `role` queries are not relevant. Even after [37360], this still
 seems to be the case. You mention that after [37360], "more processing" is
 taking place after the reset; but as far as I can see, the *opposite* is
 true, since the reset was moved later in the method. Indeed, in my tests,
 the correct users are showing up in the dropdown. (See also
 http://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/user/query.php,
 which contains a number of `who_authors` tests that seem to say the
 opposite of what you're saying here.)

 Can you give more details about exactly what you're seeing on the Author
 dropdown, and other places where you're experiencing the issue? Is the
 dropdown being populated with *all* users from the network? Or is it
 specifically looking for users who are members of blog_id=0 (ie, users who
 are not members of any sites)?

 One thing that is true - though doesn't appear to be new to 4.6 - is that
 the reset `blog_id` is being passed to the 'pre_user_query' hook and other
 filters. As such, it's possible that a callback is expecting to get the
 original `blog_id`, but is getting 0 instead, and is doing something
 weird. Is it possible that something like this is happening in your case?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37499#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list