Changeset 42343 for trunk/src/wp-includes/class-wp-comment-query.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-comment-query.php (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-comment-query.php
r42201 r42343 243 243 * `$fields` is 'ids' or 'counts'. Accepts 'threaded', 244 244 * 'flat', or false. Default: false. 245 * @type string $cache_domain Unique cache key to be produced when this query is stored in245 * @type string $cache_domain Unique cache key to be produced when this query is stored in 246 246 * an object cache. Default is 'core'. 247 247 * @type bool $update_comment_meta_cache Whether to prime the metadata cache for found comments. … … 253 253 public function __construct( $query = '' ) { 254 254 $this->query_var_defaults = array( 255 'author_email' => '',256 'author_url' => '',257 'author__in' => '',258 'author__not_in' => '',259 'include_unapproved' => '',260 'fields' => '',261 'ID' => '',262 'comment__in' => '',263 'comment__not_in' => '',264 'karma' => '',265 'number' => '',266 'offset' => '',267 'no_found_rows' => true,268 'orderby' => '',269 'order' => 'DESC',270 'paged' => 1,271 'parent' => '',272 'parent__in' => '',273 'parent__not_in' => '',274 'post_author__in' => '',275 'post_author__not_in' => '',276 'post_ID' => '',277 'post_id' => 0,278 'post__in' => '',279 'post__not_in' => '',280 'post_author' => '',281 'post_name' => '',282 'post_parent' => '',283 'post_status' => '',284 'post_type' => '',285 'status' => 'all',286 'type' => '',287 'type__in' => '',288 'type__not_in' => '',289 'user_id' => '',290 'search' => '',291 'count' => false,292 'meta_key' => '',293 'meta_value' => '',294 'meta_query' => '',295 'date_query' => null, // See WP_Date_Query296 'hierarchical' => false,297 'cache_domain' => 'core',255 'author_email' => '', 256 'author_url' => '', 257 'author__in' => '', 258 'author__not_in' => '', 259 'include_unapproved' => '', 260 'fields' => '', 261 'ID' => '', 262 'comment__in' => '', 263 'comment__not_in' => '', 264 'karma' => '', 265 'number' => '', 266 'offset' => '', 267 'no_found_rows' => true, 268 'orderby' => '', 269 'order' => 'DESC', 270 'paged' => 1, 271 'parent' => '', 272 'parent__in' => '', 273 'parent__not_in' => '', 274 'post_author__in' => '', 275 'post_author__not_in' => '', 276 'post_ID' => '', 277 'post_id' => 0, 278 'post__in' => '', 279 'post__not_in' => '', 280 'post_author' => '', 281 'post_name' => '', 282 'post_parent' => '', 283 'post_status' => '', 284 'post_type' => '', 285 'status' => 'all', 286 'type' => '', 287 'type__in' => '', 288 'type__not_in' => '', 289 'user_id' => '', 290 'search' => '', 291 'count' => false, 292 'meta_key' => '', 293 'meta_value' => '', 294 'meta_query' => '', 295 'date_query' => null, // See WP_Date_Query 296 'hierarchical' => false, 297 'cache_domain' => 'core', 298 298 'update_comment_meta_cache' => true, 299 299 'update_comment_post_cache' => false, … … 309 309 * 310 310 * @since 4.2.0 Extracted from WP_Comment_Query::query(). 311 *312 311 * 313 312 * @param string|array $query WP_Comment_Query arguments. See WP_Comment_Query::__construct() … … 388 387 unset( $_args['fields'] ); 389 388 390 $key = md5( serialize( $_args ) );389 $key = md5( serialize( $_args ) ); 391 390 $last_changed = wp_cache_get_last_changed( 'comment' ); 392 391 … … 482 481 // 'status' accepts an array or a comma-separated string. 483 482 $status_clauses = array(); 484 $statuses = $this->query_vars['status'];483 $statuses = $this->query_vars['status']; 485 484 if ( ! is_array( $statuses ) ) { 486 485 $statuses = preg_split( '/[\s,]+/', $statuses ); … … 491 490 foreach ( $statuses as $status ) { 492 491 switch ( $status ) { 493 case 'hold' :492 case 'hold': 494 493 $status_clauses[] = "comment_approved = '0'"; 495 494 break; 496 495 497 case 'approve' :496 case 'approve': 498 497 $status_clauses[] = "comment_approved = '1'"; 499 498 break; 500 499 501 case 'all' :502 case '' :500 case 'all': 501 case '': 503 502 $status_clauses[] = "( comment_approved = '0' OR comment_approved = '1' )"; 504 503 break; 505 504 506 default :507 $status_clauses[] = $wpdb->prepare( "comment_approved = %s", $status );505 default: 506 $status_clauses[] = $wpdb->prepare( 'comment_approved = %s', $status ); 508 507 break; 509 508 } … … 530 529 $approved_clauses[] = $wpdb->prepare( "( user_id = %d AND comment_approved = '0' )", $unapproved_identifier ); 531 530 532 // Otherwise we match against email addresses.531 // Otherwise we match against email addresses. 533 532 } else { 534 533 $approved_clauses[] = $wpdb->prepare( "( comment_author_email = %s AND comment_approved = '0' )", $unapproved_identifier ); … … 556 555 preg_split( '/[,\s]/', $this->query_vars['orderby'] ); 557 556 558 $orderby_array = array();557 $orderby_array = array(); 559 558 $found_orderby_comment_ID = false; 560 559 foreach ( $ordersby as $_key => $_value ) { … … 565 564 if ( is_int( $_key ) ) { 566 565 $_orderby = $_value; 567 $_order = $order;566 $_order = $order; 568 567 } else { 569 568 $_orderby = $_key; 570 $_order = $_value;569 $_order = $_value; 571 570 } 572 571 … … 634 633 $number = absint( $this->query_vars['number'] ); 635 634 $offset = absint( $this->query_vars['offset'] ); 636 $paged = absint( $this->query_vars['paged'] );635 $paged = absint( $this->query_vars['paged'] ); 637 636 638 637 if ( ! empty( $number ) ) { … … 699 698 // Filtering by comment_type: 'type', 'type__in', 'type__not_in'. 700 699 $raw_types = array( 701 'IN' => array_merge( (array) $this->query_vars['type'], (array) $this->query_vars['type__in'] ),700 'IN' => array_merge( (array) $this->query_vars['type'], (array) $this->query_vars['type__in'] ), 702 701 'NOT IN' => (array) $this->query_vars['type__not_in'], 703 702 ); … … 711 710 // An empty translates to 'all', for backward compatibility 712 711 case '': 713 case 'all' :712 case 'all': 714 713 break; 715 714 … … 732 731 if ( ! empty( $comment_types[ $operator ] ) ) { 733 732 $types_sql = implode( ', ', $comment_types[ $operator ] ); 734 $this->sql_clauses['where'][ 'comment_type__' . strtolower( str_replace( ' ', '_', $operator ) ) ] = "comment_type $operator ($types_sql)";733 $this->sql_clauses['where'][ 'comment_type__' . strtolower( str_replace( ' ', '_', $operator ) ) ] = "comment_type $operator ($types_sql)"; 735 734 } 736 735 } … … 764 763 // If any post-related query vars are passed, join the posts table. 765 764 $join_posts_table = false; 766 $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) );767 $post_fields = array_filter( $plucked );765 $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) ); 766 $post_fields = array_filter( $plucked ); 768 767 769 768 if ( ! empty( $post_fields ) ) { … … 771 770 foreach ( $post_fields as $field_name => $field_value ) { 772 771 // $field_value may be an array. 773 $esses = array_fill( 0, count( (array) $field_value ), '%s' );772 $esses = array_fill( 0, count( (array) $field_value ), '%s' ); 774 773 $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value ); 775 774 } … … 792 791 $join_posts_table = true; 793 792 794 $esses = array_fill( 0, count( $q_values ), '%s' );795 $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values );793 $esses = array_fill( 0, count( $q_values ), '%s' ); 794 $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $q_values ); 796 795 } 797 796 } … … 809 808 // Post author IDs for an IN clause. 810 809 if ( ! empty( $this->query_vars['post_author__in'] ) ) { 811 $join_posts_table = true;810 $join_posts_table = true; 812 811 $this->sql_clauses['where']['post_author__in'] = 'post_author IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__in'] ) ) . ' )'; 813 812 } … … 815 814 // Post author IDs for a NOT IN clause. 816 815 if ( ! empty( $this->query_vars['post_author__not_in'] ) ) { 817 $join_posts_table = true;816 $join_posts_table = true; 818 817 $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__not_in'] ) ) . ' )'; 819 818 } … … 837 836 838 837 if ( ! empty( $this->query_vars['date_query'] ) && is_array( $this->query_vars['date_query'] ) ) { 839 $this->date_query = new WP_Date_Query( $this->query_vars['date_query'], 'comment_date' );838 $this->date_query = new WP_Date_Query( $this->query_vars['date_query'], 'comment_date' ); 840 839 $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() ); 841 840 } … … 854 853 $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) ); 855 854 856 $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields'] : '';857 $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join'] : '';858 $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where'] : '';859 $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby'] : '';860 $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits'] : '';861 $groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby'] : '';855 $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : ''; 856 $join = isset( $clauses['join'] ) ? $clauses['join'] : ''; 857 $where = isset( $clauses['where'] ) ? $clauses['where'] : ''; 858 $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : ''; 859 $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; 860 $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : ''; 862 861 863 862 $this->filtered_where_clause = $where; … … 942 941 ); 943 942 944 $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) );943 $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) ); 945 944 $last_changed = wp_cache_get_last_changed( 'comment' ); 946 945 947 946 // Fetch an entire level of the descendant tree at a time. 948 $level = 0;947 $level = 0; 949 948 $exclude_keys = array( 'parent', 'parent__in', 'parent__not_in' ); 950 949 do { 951 950 // Parent-child relationships may be cached. Only query for those that are not. 952 $child_ids = $uncached_parent_ids = array();951 $child_ids = $uncached_parent_ids = array(); 953 952 $_parent_ids = $levels[ $level ]; 954 953 foreach ( $_parent_ids as $parent_id ) { 955 $cache_key = "get_comment_child_ids:$parent_id:$key:$last_changed";954 $cache_key = "get_comment_child_ids:$parent_id:$key:$last_changed"; 956 955 $parent_child_ids = wp_cache_get( $cache_key, 'comment' ); 957 956 if ( false !== $parent_child_ids ) { … … 980 979 foreach ( $level_comments as $level_comment ) { 981 980 $parent_map[ $level_comment->comment_parent ][] = $level_comment->comment_ID; 982 $child_ids[] = $level_comment->comment_ID;981 $child_ids[] = $level_comment->comment_ID; 983 982 } 984 983 … … 1016 1015 if ( ! isset( $ref[ $c->comment_parent ] ) ) { 1017 1016 $threaded_comments[ $_c->comment_ID ] = $_c; 1018 $ref[ $_c->comment_ID ] = $threaded_comments[ $_c->comment_ID ];1019 1020 // Otherwise, set it as a child of its parent.1017 $ref[ $_c->comment_ID ] = $threaded_comments[ $_c->comment_ID ]; 1018 1019 // Otherwise, set it as a child of its parent. 1021 1020 } else { 1022 1021 … … 1060 1059 } 1061 1060 1062 return ' AND (' . implode( ' OR ', $searches) . ')';1061 return ' AND (' . implode( ' OR ', $searches ) . ')'; 1063 1062 } 1064 1063 … … 1112 1111 } elseif ( $orderby == 'comment__in' ) { 1113 1112 $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) ); 1114 $parsed = "FIELD( {$wpdb->comments}.comment_ID, $comment__in )";1113 $parsed = "FIELD( {$wpdb->comments}.comment_ID, $comment__in )"; 1115 1114 } elseif ( in_array( $orderby, $allowed_keys ) ) { 1116 1115 1117 1116 if ( isset( $meta_query_clauses[ $orderby ] ) ) { 1118 1117 $meta_clause = $meta_query_clauses[ $orderby ]; 1119 $parsed = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) );1118 $parsed = sprintf( 'CAST(%s.meta_value AS %s)', esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) ); 1120 1119 } else { 1121 1120 $parsed = "$wpdb->comments.$orderby";
Note: See TracChangeset
for help on using the changeset viewer.