* Add isset()
checks all over WP_User_Query::prepare_query()
and WP_User_Query::query()
. When a WP_User_Query
instance is constructed without passing args, no query vars are filled in, thus $qv
doesn't contain most of the expected indices.
* Suppress an undefined index notice in `tests/user/query.php` Fixes #25292. See #25282. Built from https://develop.svn.wordpress.org/trunk@25392 git-svn-id: http://core.svn.wordpress.org/trunk@25326 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
71430cd29a
commit
6744355f70
@ -409,13 +409,14 @@ class WP_User_Query {
|
|||||||
$this->query_fields = "$wpdb->users.ID";
|
$this->query_fields = "$wpdb->users.ID";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $qv['count_total'] )
|
if ( isset( $qv['count_total'] ) && $qv['count_total'] )
|
||||||
$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
|
$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
|
||||||
|
|
||||||
$this->query_from = "FROM $wpdb->users";
|
$this->query_from = "FROM $wpdb->users";
|
||||||
$this->query_where = "WHERE 1=1";
|
$this->query_where = "WHERE 1=1";
|
||||||
|
|
||||||
// sorting
|
// sorting
|
||||||
|
if ( isset( $qv['orderby'] ) ) {
|
||||||
if ( in_array( $qv['orderby'], array('nicename', 'email', 'url', 'registered') ) ) {
|
if ( in_array( $qv['orderby'], array('nicename', 'email', 'url', 'registered') ) ) {
|
||||||
$orderby = 'user_' . $qv['orderby'];
|
$orderby = 'user_' . $qv['orderby'];
|
||||||
} elseif ( in_array( $qv['orderby'], array('user_nicename', 'user_email', 'user_url', 'user_registered') ) ) {
|
} elseif ( in_array( $qv['orderby'], array('user_nicename', 'user_email', 'user_url', 'user_registered') ) ) {
|
||||||
@ -440,8 +441,12 @@ class WP_User_Query {
|
|||||||
} else {
|
} else {
|
||||||
$orderby = 'user_login';
|
$orderby = 'user_login';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$qv['order'] = strtoupper( $qv['order'] );
|
if ( empty( $orderby ) )
|
||||||
|
$orderby = 'user_login';
|
||||||
|
|
||||||
|
$qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
|
||||||
if ( 'ASC' == $qv['order'] )
|
if ( 'ASC' == $qv['order'] )
|
||||||
$order = 'ASC';
|
$order = 'ASC';
|
||||||
else
|
else
|
||||||
@ -449,14 +454,17 @@ class WP_User_Query {
|
|||||||
$this->query_orderby = "ORDER BY $orderby $order";
|
$this->query_orderby = "ORDER BY $orderby $order";
|
||||||
|
|
||||||
// limit
|
// limit
|
||||||
if ( $qv['number'] ) {
|
if ( isset( $qv['number'] ) && $qv['number'] ) {
|
||||||
if ( $qv['offset'] )
|
if ( $qv['offset'] )
|
||||||
$this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
|
$this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
|
||||||
else
|
else
|
||||||
$this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
|
$this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$search = '';
|
||||||
|
if ( isset( $qv['search'] ) )
|
||||||
$search = trim( $qv['search'] );
|
$search = trim( $qv['search'] );
|
||||||
|
|
||||||
if ( $search ) {
|
if ( $search ) {
|
||||||
$leading_wild = ( ltrim($search, '*') != $search );
|
$leading_wild = ( ltrim($search, '*') != $search );
|
||||||
$trailing_wild = ( rtrim($search, '*') != $search );
|
$trailing_wild = ( rtrim($search, '*') != $search );
|
||||||
@ -490,15 +498,19 @@ class WP_User_Query {
|
|||||||
$this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
|
$this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$blog_id = 0;
|
||||||
|
if ( isset( $qv['blog_id'] ) )
|
||||||
$blog_id = absint( $qv['blog_id'] );
|
$blog_id = absint( $qv['blog_id'] );
|
||||||
|
|
||||||
if ( 'authors' == $qv['who'] && $blog_id ) {
|
if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) {
|
||||||
$qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';
|
$qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';
|
||||||
$qv['meta_value'] = 0;
|
$qv['meta_value'] = 0;
|
||||||
$qv['meta_compare'] = '!=';
|
$qv['meta_compare'] = '!=';
|
||||||
$qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
|
$qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$role = '';
|
||||||
|
if ( isset( $qv['role'] ) )
|
||||||
$role = trim( $qv['role'] );
|
$role = trim( $qv['role'] );
|
||||||
|
|
||||||
if ( $blog_id && ( $role || is_multisite() ) ) {
|
if ( $blog_id && ( $role || is_multisite() ) ) {
|
||||||
@ -553,7 +565,7 @@ class WP_User_Query {
|
|||||||
$this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
|
$this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $qv['count_total'] )
|
if ( isset( $qv['count_total'] ) && $qv['count_total'] )
|
||||||
$this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
|
$this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
|
||||||
|
|
||||||
if ( !$this->results )
|
if ( !$this->results )
|
||||||
|
Loading…
Reference in New Issue
Block a user