[wp-trac] [WordPress Trac] #62003: User_Query cache triggers fatal error by ignoring 'fields' query var

WordPress Trac noreply at wordpress.org
Fri Sep 6 20:43:57 UTC 2024


#62003: User_Query cache triggers fatal error by ignoring 'fields' query var
--------------------------+------------------------------
 Reporter:  sermitr       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Users         |     Version:  6.6.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by sermitr):

 The workaround here is cleaning the cache and disabling it for requests
 where `fields` is an array of one element:

 {{{#!php
 <?php
 add_filter( 'users_pre_query', function( $null, $query ) {
     if ( ! empty( $query->query_vars['fields'] ) && is_array(
 $query->query_vars['fields'] ) && count( $query->query_vars['fields'] )
 === 1 ) {
         $query->query_vars['cache_results'] = false;
     }

     return $null;
 }, 10, 2 );
 }}}

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


More information about the wp-trac mailing list