Make `WP_User_Query::prepare_query()` public by allowing it to be passed an array of args. Previously, if the `WP_User_Query` constructor was not passed args, the object was basically unusable. Adds unit tests, all other tests pass.

Props scribu, for the initial patch.
Fixes #21119.


Built from https://develop.svn.wordpress.org/trunk@27185


git-svn-id: http://core.svn.wordpress.org/trunk@27045 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-02-17 21:41:12 +00:00
parent 14fba3c926
commit 55b4eee4c2
1 changed files with 22 additions and 17 deletions

View File

@ -431,7 +431,24 @@ class WP_User_Query {
* @return WP_User_Query
*/
function __construct( $query = null ) {
if ( !empty( $query ) ) {
if ( ! empty( $query ) ) {
$this->prepare_query( $query );
$this->query();
}
}
/**
* Prepare the query variables
*
* @since 3.1.0
*
* @param string|array $args The query variables
*/
function prepare_query( $query = array() ) {
global $wpdb;
if ( empty( $this->query_vars ) || ! empty( $query ) ) {
$this->query_limit = null;
$this->query_vars = wp_parse_args( $query, array(
'blog_id' => $GLOBALS['blog_id'],
'role' => '',
@ -450,20 +467,7 @@ class WP_User_Query {
'fields' => 'all',
'who' => ''
) );
$this->prepare_query();
$this->query();
}
}
/**
* Prepare the query variables
*
* @since 3.1.0
* @access private
*/
function prepare_query() {
global $wpdb;
$qv =& $this->query_vars;
@ -649,17 +653,18 @@ class WP_User_Query {
* Execute the query, with the current variables
*
* @since 3.1.0
* @access private
*/
function query() {
global $wpdb;
$qv =& $this->query_vars;
$query = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
$this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
$this->results = $wpdb->get_results( $query );
} else {
$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( $query );
}
/**