Make WordPress Core


Ignore:
Timestamp:
02/17/2014 09:40:04 PM (13 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r26904 r27185  
    432432         */
    433433        function __construct( $query = null ) {
    434                 if ( !empty( $query ) ) {
     434                if ( ! empty( $query ) ) {
     435                        $this->prepare_query( $query );
     436                        $this->query();
     437                }
     438        }
     439
     440        /**
     441         * Prepare the query variables
     442         *
     443         * @since 3.1.0
     444         *
     445         * @param string|array $args The query variables
     446         */
     447        function prepare_query( $query = array() ) {
     448                global $wpdb;
     449
     450                if ( empty( $this->query_vars ) || ! empty( $query ) ) {
     451                        $this->query_limit = null;
    435452                        $this->query_vars = wp_parse_args( $query, array(
    436453                                'blog_id' => $GLOBALS['blog_id'],
     
    451468                                'who' => ''
    452469                        ) );
    453 
    454                         $this->prepare_query();
    455                         $this->query();
    456                 }
    457         }
    458 
    459         /**
    460          * Prepare the query variables
    461          *
    462          * @since 3.1.0
    463          * @access private
    464          */
    465         function prepare_query() {
    466                 global $wpdb;
     470                }
    467471
    468472                $qv =& $this->query_vars;
     
    650654         *
    651655         * @since 3.1.0
    652          * @access private
    653656         */
    654657        function query() {
     
    657660                $qv =& $this->query_vars;
    658661
     662                $query = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
     663
    659664                if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
    660                         $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
     665                        $this->results = $wpdb->get_results( $query );
    661666                } else {
    662                         $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
     667                        $this->results = $wpdb->get_col( $query );
    663668                }
    664669
Note: See TracChangeset for help on using the changeset viewer.