3 * User API: WP_User_Query class
11 * Core class used for querying users.
15 * @see WP_User_Query::prepare_query() for information on accepted arguments.
20 * Query vars, after parsing
26 public $query_vars = array();
29 * List of found user ids
38 * Total number of found users for the current query
44 private $total_users = 0;
47 * Metadata query container.
53 public $meta_query = false;
56 * The SQL query used to fetch matching users.
64 private $compat_fields = array( 'results', 'total_users' );
70 public $query_orderby;
78 * @param null|string|array $query Optional. The query variables.
80 public function __construct( $query = null ) {
81 if ( ! empty( $query ) ) {
82 $this->prepare_query( $query );
88 * Fills in missing query variables with default values.
93 * @param array $args Query vars, as passed to `WP_User_Query`.
94 * @return array Complete query variables with undefined ones filled in with defaults.
96 public static function fill_query_vars( $args ) {
98 'blog_id' => get_current_blog_id(),
100 'role__in' => array(),
101 'role__not_in' => array(),
104 'meta_compare' => '',
105 'include' => array(),
106 'exclude' => array(),
108 'search_columns' => array(),
109 'orderby' => 'login',
114 'count_total' => true,
117 'has_published_posts' => null,
119 'nicename__in' => array(),
120 'nicename__not_in' => array(),
122 'login__in' => array(),
123 'login__not_in' => array()
126 return wp_parse_args( $args, $defaults );
130 * Prepare the query variables.
133 * @since 4.1.0 Added the ability to order by the `include` value.
134 * @since 4.2.0 Added 'meta_value_num' support for `$orderby` parameter. Added multi-dimensional array syntax
135 * for `$orderby` parameter.
136 * @since 4.3.0 Added 'has_published_posts' parameter.
137 * @since 4.4.0 Added 'paged', 'role__in', and 'role__not_in' parameters. The 'role' parameter was updated to
138 * permit an array or comma-separated list of values. The 'number' parameter was updated to support
139 * querying for all users with using -1.
140 * @since 4.7.0 Added 'nicename', 'nicename__in', 'nicename__not_in', 'login', 'login__in',
141 * and 'login__not_in' parameters.
145 * @global wpdb $wpdb WordPress database abstraction object.
146 * @global int $blog_id
148 * @param string|array $query {
149 * Optional. Array or string of Query parameters.
151 * @type int $blog_id The site ID. Default is the current site.
152 * @type string|array $role An array or a comma-separated list of role names that users must match
153 * to be included in results. Note that this is an inclusive list: users
154 * must match *each* role. Default empty.
155 * @type array $role__in An array of role names. Matched users must have at least one of these
156 * roles. Default empty array.
157 * @type array $role__not_in An array of role names to exclude. Users matching one or more of these
158 * roles will not be included in results. Default empty array.
159 * @type string $meta_key User meta key. Default empty.
160 * @type string $meta_value User meta value. Default empty.
161 * @type string $meta_compare Comparison operator to test the `$meta_value`. Accepts '=', '!=',
162 * '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN',
163 * 'BETWEEN', 'NOT BETWEEN', 'EXISTS', 'NOT EXISTS', 'REGEXP',
164 * 'NOT REGEXP', or 'RLIKE'. Default '='.
165 * @type array $include An array of user IDs to include. Default empty array.
166 * @type array $exclude An array of user IDs to exclude. Default empty array.
167 * @type string $search Search keyword. Searches for possible string matches on columns.
168 * When `$search_columns` is left empty, it tries to determine which
169 * column to search in based on search string. Default empty.
170 * @type array $search_columns Array of column names to be searched. Accepts 'ID', 'login',
171 * 'nicename', 'email', 'url'. Default empty array.
172 * @type string|array $orderby Field(s) to sort the retrieved users by. May be a single value,
173 * an array of values, or a multi-dimensional array with fields as
174 * keys and orders ('ASC' or 'DESC') as values. Accepted values are
175 * 'ID', 'display_name' (or 'name'), 'include', 'user_login'
176 * (or 'login'), 'login__in', 'user_nicename' (or 'nicename'),
177 * 'nicename__in', 'user_email (or 'email'), 'user_url' (or 'url'),
178 * 'user_registered' (or 'registered'), 'post_count', 'meta_value',
179 * 'meta_value_num', the value of `$meta_key`, or an array key of
180 * `$meta_query`. To use 'meta_value' or 'meta_value_num', `$meta_key`
181 * must be also be defined. Default 'user_login'.
182 * @type string $order Designates ascending or descending order of users. Order values
183 * passed as part of an `$orderby` array take precedence over this
184 * parameter. Accepts 'ASC', 'DESC'. Default 'ASC'.
185 * @type int $offset Number of users to offset in retrieved results. Can be used in
186 * conjunction with pagination. Default 0.
187 * @type int $number Number of users to limit the query for. Can be used in
188 * conjunction with pagination. Value -1 (all) is supported, but
189 * should be used with caution on larger sites.
190 * Default empty (all users).
191 * @type int $paged When used with number, defines the page of results to return.
193 * @type bool $count_total Whether to count the total number of users found. If pagination
194 * is not needed, setting this to false can improve performance.
196 * @type string|array $fields Which fields to return. Single or all fields (string), or array
197 * of fields. Accepts 'ID', 'display_name', 'user_login',
198 * 'user_nicename', 'user_email', 'user_url', 'user_registered'.
199 * Use 'all' for all fields and 'all_with_meta' to include
200 * meta fields. Default 'all'.
201 * @type string $who Type of users to query. Accepts 'authors'.
202 * Default empty (all users).
203 * @type bool|array $has_published_posts Pass an array of post types to filter results to users who have
204 * published posts in those post types. `true` is an alias for all
206 * @type string $nicename The user nicename. Default empty.
207 * @type array $nicename__in An array of nicenames to include. Users matching one of these
208 * nicenames will be included in results. Default empty array.
209 * @type array $nicename__not_in An array of nicenames to exclude. Users matching one of these
210 * nicenames will not be included in results. Default empty array.
211 * @type string $login The user login. Default empty.
212 * @type array $login__in An array of logins to include. Users matching one of these
213 * logins will be included in results. Default empty array.
214 * @type array $login__not_in An array of logins to exclude. Users matching one of these
215 * logins will not be included in results. Default empty array.
218 public function prepare_query( $query = array() ) {
221 if ( empty( $this->query_vars ) || ! empty( $query ) ) {
222 $this->query_limit = null;
223 $this->query_vars = $this->fill_query_vars( $query );
227 * Fires before the WP_User_Query has been parsed.
229 * The passed WP_User_Query object contains the query variables, not
230 * yet passed into SQL.
234 * @param WP_User_Query $this The current WP_User_Query instance,
235 * passed by reference.
237 do_action( 'pre_get_users', $this );
239 // Ensure that query vars are filled after 'pre_get_users'.
240 $qv =& $this->query_vars;
241 $qv = $this->fill_query_vars( $qv );
243 if ( is_array( $qv['fields'] ) ) {
244 $qv['fields'] = array_unique( $qv['fields'] );
246 $this->query_fields = array();
247 foreach ( $qv['fields'] as $field ) {
248 $field = 'ID' === $field ? 'ID' : sanitize_key( $field );
249 $this->query_fields[] = "$wpdb->users.$field";
251 $this->query_fields = implode( ',', $this->query_fields );
252 } elseif ( 'all' == $qv['fields'] ) {
253 $this->query_fields = "$wpdb->users.*";
255 $this->query_fields = "$wpdb->users.ID";
258 if ( isset( $qv['count_total'] ) && $qv['count_total'] )
259 $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
261 $this->query_from = "FROM $wpdb->users";
262 $this->query_where = "WHERE 1=1";
264 // Parse and sanitize 'include', for use by 'orderby' as well as 'include' below.
265 if ( ! empty( $qv['include'] ) ) {
266 $include = wp_parse_id_list( $qv['include'] );
272 if ( isset( $qv['blog_id'] ) ) {
273 $blog_id = absint( $qv['blog_id'] );
276 if ( $qv['has_published_posts'] && $blog_id ) {
277 if ( true === $qv['has_published_posts'] ) {
278 $post_types = get_post_types( array( 'public' => true ) );
280 $post_types = (array) $qv['has_published_posts'];
283 foreach ( $post_types as &$post_type ) {
284 $post_type = $wpdb->prepare( '%s', $post_type );
287 $posts_table = $wpdb->get_blog_prefix( $blog_id ) . 'posts';
288 $this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . join( ", ", $post_types ) . " ) )";
292 if ( '' !== $qv['nicename']) {
293 $this->query_where .= $wpdb->prepare( ' AND user_nicename = %s', $qv['nicename'] );
296 if ( ! empty( $qv['nicename__in'] ) ) {
297 $sanitized_nicename__in = array_map( 'esc_sql', $qv['nicename__in'] );
298 $nicename__in = implode( "','", $sanitized_nicename__in );
299 $this->query_where .= " AND user_nicename IN ( '$nicename__in' )";
302 if ( ! empty( $qv['nicename__not_in'] ) ) {
303 $sanitized_nicename__not_in = array_map( 'esc_sql', $qv['nicename__not_in'] );
304 $nicename__not_in = implode( "','", $sanitized_nicename__not_in );
305 $this->query_where .= " AND user_nicename NOT IN ( '$nicename__not_in' )";
309 if ( '' !== $qv['login']) {
310 $this->query_where .= $wpdb->prepare( ' AND user_login = %s', $qv['login'] );
313 if ( ! empty( $qv['login__in'] ) ) {
314 $sanitized_login__in = array_map( 'esc_sql', $qv['login__in'] );
315 $login__in = implode( "','", $sanitized_login__in );
316 $this->query_where .= " AND user_login IN ( '$login__in' )";
319 if ( ! empty( $qv['login__not_in'] ) ) {
320 $sanitized_login__not_in = array_map( 'esc_sql', $qv['login__not_in'] );
321 $login__not_in = implode( "','", $sanitized_login__not_in );
322 $this->query_where .= " AND user_login NOT IN ( '$login__not_in' )";
326 $this->meta_query = new WP_Meta_Query();
327 $this->meta_query->parse_query_vars( $qv );
329 if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) {
331 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'user_level',
336 // Prevent extra meta query.
337 $qv['blog_id'] = $blog_id = 0;
339 if ( empty( $this->meta_query->queries ) ) {
340 $this->meta_query->queries = array( $who_query );
342 // Append the cap query to the original queries and reparse the query.
343 $this->meta_query->queries = array(
345 array( $this->meta_query->queries, $who_query ),
349 $this->meta_query->parse_query_vars( $this->meta_query->queries );
353 if ( isset( $qv['role'] ) ) {
354 if ( is_array( $qv['role'] ) ) {
355 $roles = $qv['role'];
356 } elseif ( is_string( $qv['role'] ) && ! empty( $qv['role'] ) ) {
357 $roles = array_map( 'trim', explode( ',', $qv['role'] ) );
362 if ( isset( $qv['role__in'] ) ) {
363 $role__in = (array) $qv['role__in'];
366 $role__not_in = array();
367 if ( isset( $qv['role__not_in'] ) ) {
368 $role__not_in = (array) $qv['role__not_in'];
371 if ( $blog_id && ( ! empty( $roles ) || ! empty( $role__in ) || ! empty( $role__not_in ) || is_multisite() ) ) {
372 $role_queries = array();
374 $roles_clauses = array( 'relation' => 'AND' );
375 if ( ! empty( $roles ) ) {
376 foreach ( $roles as $role ) {
377 $roles_clauses[] = array(
378 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
379 'value' => '"' . $role . '"',
384 $role_queries[] = $roles_clauses;
387 $role__in_clauses = array( 'relation' => 'OR' );
388 if ( ! empty( $role__in ) ) {
389 foreach ( $role__in as $role ) {
390 $role__in_clauses[] = array(
391 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
392 'value' => '"' . $role . '"',
397 $role_queries[] = $role__in_clauses;
400 $role__not_in_clauses = array( 'relation' => 'AND' );
401 if ( ! empty( $role__not_in ) ) {
402 foreach ( $role__not_in as $role ) {
403 $role__not_in_clauses[] = array(
404 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
405 'value' => '"' . $role . '"',
406 'compare' => 'NOT LIKE',
410 $role_queries[] = $role__not_in_clauses;
413 // If there are no specific roles named, make sure the user is a member of the site.
414 if ( empty( $role_queries ) ) {
415 $role_queries[] = array(
416 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
417 'compare' => 'EXISTS',
421 // Specify that role queries should be joined with AND.
422 $role_queries['relation'] = 'AND';
424 if ( empty( $this->meta_query->queries ) ) {
425 $this->meta_query->queries = $role_queries;
427 // Append the cap query to the original queries and reparse the query.
428 $this->meta_query->queries = array(
430 array( $this->meta_query->queries, $role_queries ),
434 $this->meta_query->parse_query_vars( $this->meta_query->queries );
437 if ( ! empty( $this->meta_query->queries ) ) {
438 $clauses = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );
439 $this->query_from .= $clauses['join'];
440 $this->query_where .= $clauses['where'];
442 if ( $this->meta_query->has_or_relation() ) {
443 $this->query_fields = 'DISTINCT ' . $this->query_fields;
448 $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
449 $order = $this->parse_order( $qv['order'] );
451 if ( empty( $qv['orderby'] ) ) {
452 // Default order is by 'user_login'.
453 $ordersby = array( 'user_login' => $order );
454 } elseif ( is_array( $qv['orderby'] ) ) {
455 $ordersby = $qv['orderby'];
457 // 'orderby' values may be a comma- or space-separated list.
458 $ordersby = preg_split( '/[,\s]+/', $qv['orderby'] );
461 $orderby_array = array();
462 foreach ( $ordersby as $_key => $_value ) {
467 if ( is_int( $_key ) ) {
468 // Integer key means this is a flat array of 'orderby' fields.
472 // Non-integer key means this the key is the field and the value is ASC/DESC.
477 $parsed = $this->parse_orderby( $_orderby );
483 if ( 'nicename__in' === $_orderby || 'login__in' === $_orderby ) {
484 $orderby_array[] = $parsed;
486 $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
490 // If no valid clauses were found, order by user_login.
491 if ( empty( $orderby_array ) ) {
492 $orderby_array[] = "user_login $order";
495 $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
498 if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
499 if ( $qv['offset'] ) {
500 $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
502 $this->query_limit = $wpdb->prepare( "LIMIT %d, %d", $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
507 if ( isset( $qv['search'] ) )
508 $search = trim( $qv['search'] );
511 $leading_wild = ( ltrim($search, '*') != $search );
512 $trailing_wild = ( rtrim($search, '*') != $search );
513 if ( $leading_wild && $trailing_wild )
515 elseif ( $leading_wild )
517 elseif ( $trailing_wild )
522 $search = trim($search, '*');
524 $search_columns = array();
525 if ( $qv['search_columns'] )
526 $search_columns = array_intersect( $qv['search_columns'], array( 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename' ) );
527 if ( ! $search_columns ) {
528 if ( false !== strpos( $search, '@') )
529 $search_columns = array('user_email');
530 elseif ( is_numeric($search) )
531 $search_columns = array('user_login', 'ID');
532 elseif ( preg_match('|^https?://|', $search) && ! ( is_multisite() && wp_is_large_network( 'users' ) ) )
533 $search_columns = array('user_url');
535 $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name');
539 * Filters the columns to search in a WP_User_Query search.
541 * The default columns depend on the search term, and include 'user_email',
542 * 'user_login', 'ID', 'user_url', 'display_name', and 'user_nicename'.
546 * @param array $search_columns Array of column names to be searched.
547 * @param string $search Text being searched.
548 * @param WP_User_Query $this The current WP_User_Query instance.
550 $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this );
552 $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
555 if ( ! empty( $include ) ) {
556 // Sanitized earlier.
557 $ids = implode( ',', $include );
558 $this->query_where .= " AND $wpdb->users.ID IN ($ids)";
559 } elseif ( ! empty( $qv['exclude'] ) ) {
560 $ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
561 $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";
564 // Date queries are allowed for the user_registered field.
565 if ( ! empty( $qv['date_query'] ) && is_array( $qv['date_query'] ) ) {
566 $date_query = new WP_Date_Query( $qv['date_query'], 'user_registered' );
567 $this->query_where .= $date_query->get_sql();
571 * Fires after the WP_User_Query has been parsed, and before
572 * the query is executed.
574 * The passed WP_User_Query object contains SQL parts formed
575 * from parsing the given query.
579 * @param WP_User_Query $this The current WP_User_Query instance,
580 * passed by reference.
582 do_action_ref_array( 'pre_user_query', array( &$this ) );
586 * Execute the query, with the current variables.
590 * @global wpdb $wpdb WordPress database abstraction object.
592 public function query() {
595 $qv =& $this->query_vars;
597 $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
599 if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
600 $this->results = $wpdb->get_results( $this->request );
602 $this->results = $wpdb->get_col( $this->request );
606 * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance.
610 * @global wpdb $wpdb WordPress database abstraction object.
612 * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query.
614 if ( isset( $qv['count_total'] ) && $qv['count_total'] )
615 $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
617 if ( !$this->results )
620 if ( 'all_with_meta' == $qv['fields'] ) {
621 cache_users( $this->results );
624 foreach ( $this->results as $userid )
625 $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] );
628 } elseif ( 'all' == $qv['fields'] ) {
629 foreach ( $this->results as $key => $user ) {
630 $this->results[ $key ] = new WP_User( $user, '', $qv['blog_id'] );
636 * Retrieve query variable.
641 * @param string $query_var Query variable key.
644 public function get( $query_var ) {
645 if ( isset( $this->query_vars[$query_var] ) )
646 return $this->query_vars[$query_var];
652 * Set query variable.
657 * @param string $query_var Query variable key.
658 * @param mixed $value Query variable value.
660 public function set( $query_var, $value ) {
661 $this->query_vars[$query_var] = $value;
665 * Used internally to generate an SQL string for searching across multiple columns
670 * @global wpdb $wpdb WordPress database abstraction object.
672 * @param string $string
674 * @param bool $wild Whether to allow wildcard searches. Default is false for Network Admin, true for single site.
675 * Single site allows leading and trailing wildcards, Network Admin only trailing.
678 protected function get_search_sql( $string, $cols, $wild = false ) {
682 $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : '';
683 $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : '';
684 $like = $leading_wild . $wpdb->esc_like( $string ) . $trailing_wild;
686 foreach ( $cols as $col ) {
687 if ( 'ID' == $col ) {
688 $searches[] = $wpdb->prepare( "$col = %s", $string );
690 $searches[] = $wpdb->prepare( "$col LIKE %s", $like );
694 return ' AND (' . implode(' OR ', $searches) . ')';
698 * Return the list of users.
703 * @return array Array of results.
705 public function get_results() {
706 return $this->results;
710 * Return the total number of users for the current query.
715 * @return int Number of total users.
717 public function get_total() {
718 return $this->total_users;
722 * Parse and sanitize 'orderby' keys passed to the user query.
727 * @global wpdb $wpdb WordPress database abstraction object.
729 * @param string $orderby Alias for the field to order by.
730 * @return string Value to used in the ORDER clause, if `$orderby` is valid.
732 protected function parse_orderby( $orderby ) {
735 $meta_query_clauses = $this->meta_query->get_clauses();
738 if ( in_array( $orderby, array( 'login', 'nicename', 'email', 'url', 'registered' ) ) ) {
739 $_orderby = 'user_' . $orderby;
740 } elseif ( in_array( $orderby, array( 'user_login', 'user_nicename', 'user_email', 'user_url', 'user_registered' ) ) ) {
741 $_orderby = $orderby;
742 } elseif ( 'name' == $orderby || 'display_name' == $orderby ) {
743 $_orderby = 'display_name';
744 } elseif ( 'post_count' == $orderby ) {
745 // todo: avoid the JOIN
746 $where = get_posts_by_author_sql( 'post' );
747 $this->query_from .= " LEFT OUTER JOIN (
748 SELECT post_author, COUNT(*) as post_count
752 ) p ON ({$wpdb->users}.ID = p.post_author)
754 $_orderby = 'post_count';
755 } elseif ( 'ID' == $orderby || 'id' == $orderby ) {
757 } elseif ( 'meta_value' == $orderby || $this->get( 'meta_key' ) == $orderby ) {
758 $_orderby = "$wpdb->usermeta.meta_value";
759 } elseif ( 'meta_value_num' == $orderby ) {
760 $_orderby = "$wpdb->usermeta.meta_value+0";
761 } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
762 $include = wp_parse_id_list( $this->query_vars['include'] );
763 $include_sql = implode( ',', $include );
764 $_orderby = "FIELD( $wpdb->users.ID, $include_sql )";
765 } elseif ( 'nicename__in' === $orderby ) {
766 $sanitized_nicename__in = array_map( 'esc_sql', $this->query_vars['nicename__in'] );
767 $nicename__in = implode( "','", $sanitized_nicename__in );
768 $_orderby = "FIELD( user_nicename, '$nicename__in' )";
769 } elseif ( 'login__in' === $orderby ) {
770 $sanitized_login__in = array_map( 'esc_sql', $this->query_vars['login__in'] );
771 $login__in = implode( "','", $sanitized_login__in );
772 $_orderby = "FIELD( user_login, '$login__in' )";
773 } elseif ( isset( $meta_query_clauses[ $orderby ] ) ) {
774 $meta_clause = $meta_query_clauses[ $orderby ];
775 $_orderby = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) );
782 * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
787 * @param string $order The 'order' query variable.
788 * @return string The sanitized 'order' query variable.
790 protected function parse_order( $order ) {
791 if ( ! is_string( $order ) || empty( $order ) ) {
795 if ( 'ASC' === strtoupper( $order ) ) {
803 * Make private properties readable for backward compatibility.
808 * @param string $name Property to get.
809 * @return mixed Property.
811 public function __get( $name ) {
812 if ( in_array( $name, $this->compat_fields ) ) {
818 * Make private properties settable for backward compatibility.
823 * @param string $name Property to check if set.
824 * @param mixed $value Property value.
825 * @return mixed Newly-set property.
827 public function __set( $name, $value ) {
828 if ( in_array( $name, $this->compat_fields ) ) {
829 return $this->$name = $value;
834 * Make private properties checkable for backward compatibility.
839 * @param string $name Property to check if set.
840 * @return bool Whether the property is set.
842 public function __isset( $name ) {
843 if ( in_array( $name, $this->compat_fields ) ) {
844 return isset( $this->$name );
849 * Make private properties un-settable for backward compatibility.
854 * @param string $name Property to unset.
856 public function __unset( $name ) {
857 if ( in_array( $name, $this->compat_fields ) ) {
858 unset( $this->$name );
863 * Make private/protected methods readable for backward compatibility.
868 * @param callable $name Method to call.
869 * @param array $arguments Arguments to pass when calling.
870 * @return mixed Return value of the callback, false otherwise.
872 public function __call( $name, $arguments ) {
873 if ( 'get_search_sql' === $name ) {
874 return call_user_func_array( array( $this, $name ), $arguments );