Make WordPress Core

Ticket #24826: comment.php.diff

File comment.php.diff, 3.1 KB (added by westonruter, 12 years ago)
  • wp-includes/comment.php

     
    200200        var $meta_query = false;
    201201
    202202        /**
    203          * Execute the query
     203         * Query vars set by the user
    204204         *
    205205         * @since 3.1.0
     206         * @access public
     207         * @var array
     208         */
     209        var $query_vars;
     210
     211        /**
     212         * List of comments.
    206213         *
    207          * @param string|array $query_vars
    208          * @return int|array
     214         * @since 3.7
     215         * @access public
     216         * @var array
    209217         */
    210         function query( $query_vars ) {
    211                 global $wpdb;
     218        var $comments;
    212219
     220        /**
     221         * Constructor.
     222         *
     223         * Sets up the comment query, if parameter is not empty.
     224         *
     225         * @since 3.7
     226         * @access public
     227         *
     228         * @param string $query URL query string.
     229         * @return WP_Comment_Query
     230         */
     231        function __construct($query = '') {
     232                if ( ! empty($query) ) {
     233                        $this->query($query);
     234                }
     235        }
     236
     237        /**
     238         * Parse a query string and set query type booleans.
     239         *
     240         * @since 1.5.0
     241         * @access public
     242         *
     243         * @param string|array $query Optional query.
     244         */
     245        function parse_query( $query =  '' ) {
     246                if ( empty( $query ) ) {
     247                        $query = $this->query_vars;
     248                }
    213249                $defaults = array(
    214250                        'author_email' => '',
    215251                        'ID' => '',
     
    236272                        'meta_query' => '',
    237273                );
    238274
     275                $this->query_vars = wp_parse_args( $query, $defaults );
     276                do_action_ref_array('parse_comment_query', array(&$this));
     277        }
     278
     279        /**
     280         * Sets up the WordPress query by parsing query string.
     281         *
     282         * @since 1.5.0
     283         * @access public
     284         *
     285         * @param string $query_vars URL query string.
     286         * @return array List of posts.
     287         */
     288        function query( $query_vars ) {
     289                $this->query_vars = wp_parse_args( $query_vars );
     290                return $this->get_comments();
     291        }
     292
     293        /**
     294         * Execute the query
     295         *
     296         * @since 3.7
     297         *
     298         * @return int|array
     299         */
     300        function get_comments() {
     301                global $wpdb;
     302
    239303                $groupby = '';
    240304
    241                 $this->query_vars = wp_parse_args( $query_vars, $defaults );
     305                $this->parse_query();
    242306
    243307                // Parse meta query
    244308                $this->meta_query = new WP_Meta_Query();
     
    247311                do_action_ref_array( 'pre_get_comments', array( &$this ) );
    248312                extract( $this->query_vars, EXTR_SKIP );
    249313
    250                 // $args can be whatever, only use the args defined in defaults to compute the key
    251                 $key = md5( serialize( compact(array_keys($defaults)) )  );
     314                // $args can be whatever, only use the args defined in the query_vars to compute the key
     315                $key = md5( serialize( compact(array_keys($this->query_vars)) )  );
    252316                $last_changed = wp_cache_get( 'last_changed', 'comment' );
    253317                if ( ! $last_changed ) {
    254318                        $last_changed = microtime();
     
    256320                }
    257321                $cache_key = "get_comments:$key:$last_changed";
    258322
    259                 if ( $cache = wp_cache_get( $cache_key, 'comment' ) )
     323                if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {
     324                        $this->comments = $cache;
    260325                        return $cache;
     326                }
    261327
    262328                $post_id = absint($post_id);
    263329
     
    380446                $comments = apply_filters_ref_array( 'the_comments', array( $comments, &$this ) );
    381447
    382448                wp_cache_add( $cache_key, $comments, 'comment' );
     449                $this->comments = $comments;
    383450
    384451                return $comments;
    385452        }