Commit a966bf14 authored by Scott Taylor's avatar Scott Taylor
Browse files

Make `WP_User_Query::prepare_query()` public by allowing it to be passed an...

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: https://core.svn.wordpress.org/trunk@27045 1a063a9b-81f0-0310-95a4-ce76da25c4cd
parent 7c5e2802
Loading
Loading
Loading
Loading
+22 −17
Original line number Diff line number Diff line
@@ -432,6 +432,23 @@ class WP_User_Query {
	 */
	function __construct( $query = null ) {
		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,21 +467,8 @@ 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;

		if ( is_array( $qv['fields'] ) ) {
@@ -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 );
		}

		/**