Ticket #8071: 8071.diff
File 8071.diff, 6.4 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class-wp-comment-query.php
136 136 * @type string $order How to order retrieved comments. Accepts 'ASC', 'DESC'. 137 137 * Default: 'DESC'. 138 138 * @type int $parent Parent ID of comment to retrieve children of. Default empty. 139 * @type array $parent__in Array of parent IDs of comments to retrieve children for. Default empty. 140 * @type array $parent__not_in Array of parent IDs of comments *not* to retrieve children for. Default empty. 139 141 * @type array $post_author__in Array of author IDs to retrieve comments for. Default empty. 140 142 * @type array $post_author__not_in Array of author IDs *not* to retrieve comments for. Default empty. 141 143 * @type int $post_ID Currently unused. … … 387 389 $_order = $_value; 388 390 } 389 391 390 if ( ! $found_orderby_comment_ID && 'comment_ID' === $_orderby) {392 if ( ! $found_orderby_comment_ID && in_array( $_orderby, array( 'comment_ID', 'comment__in' ) ) ) { 391 393 $found_orderby_comment_ID = true; 392 394 } 393 395 … … 397 399 continue; 398 400 } 399 401 402 if ( 'comment__in' === $_orderby ) { 403 $orderby_array[] = $parsed; 404 continue; 405 } 406 400 407 $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); 401 408 } 402 409 … … 486 493 $where[] = "$wpdb->comments.comment_ID NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['comment__not_in'] ) ) . ' )'; 487 494 } 488 495 496 // Parse comment parent IDs for an IN clause. 497 if ( ! empty( $this->query_vars['parent__in'] ) ) { 498 $where[] = 'comment_parent IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__in'] ) ) . ' )'; 499 } 500 501 // Parse comment parent IDs for a NOT IN clause. 502 if ( ! empty( $this->query_vars['parent__not_in'] ) ) { 503 $where[] = 'comment_parent NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['parent__not_in'] ) ) . ' )'; 504 } 505 489 506 // Parse comment post IDs for an IN clause. 490 507 if ( ! empty( $this->query_vars['post__in'] ) ) { 491 508 $where[] = 'comment_post_ID IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post__in'] ) ) . ' )'; … … 759 776 $parsed = "$wpdb->commentmeta.meta_value"; 760 777 } elseif ( $orderby == 'meta_value_num' ) { 761 778 $parsed = "$wpdb->commentmeta.meta_value+0"; 779 } elseif ( $orderby == 'comment__in' ) { 780 $comment__in = implode( ',', array_map( 'absint', $this->query_vars['comment__in'] ) ); 781 $parsed = "FIELD( {$wpdb->comments}.comment_ID, $comment__in )"; 762 782 } elseif ( in_array( $orderby, $allowed_keys ) ) { 763 783 764 784 if ( isset( $meta_query_clauses[ $orderby ] ) ) { -
src/wp-includes/comment-functions.php
761 761 function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) { 762 762 global $wp_query; 763 763 764 if ( null === $comments && !empty($wp_query->comment_pages_count) ) 765 return $wp_query->comment_pages_count; 766 764 767 if ( null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages) ) 765 768 return $wp_query->max_num_comment_pages; 766 769 -
src/wp-includes/comment-template.php
1117 1117 } 1118 1118 } 1119 1119 1120 function wp_comments_per_page() { 1121 $per_page = (int) get_query_var( 'comments_per_page' ); 1122 if ( 0 === $per_page ) { 1123 $per_page = (int) get_option( 'comments_per_page' ); 1124 } 1125 return $per_page; 1126 } 1127 1128 function wp_comment_pages_count( $total, $top_level ) { 1129 if ( ! get_option( 'page_comments' ) ) { 1130 return 1; 1131 } 1132 1133 $per_page = wp_comments_per_page(); 1134 if ( 0 === $per_page ) { 1135 return 1; 1136 } 1137 1138 $threaded = get_option( 'thread_comments' ); 1139 1140 if ( $threaded ) { 1141 $count = ceil( $top_level / $per_page ); 1142 } else { 1143 $count = ceil( $total / $per_page ); 1144 } 1145 1146 return $count; 1147 } 1148 1149 function wp_threaded_comment_ids( $comment_ids, $comment_args ) { 1150 $threaded_ids = array(); 1151 $args = $comment_args; 1152 unset( $args['parent'] ); 1153 1154 do { 1155 $threaded_ids = array_merge( $threaded_ids, $comment_ids ); 1156 $args['parent__in'] = $comment_ids; 1157 $comment_ids = get_comments( $args ); 1158 } while ( count( $comment_ids ) ); 1159 1160 return $threaded_ids; 1161 } 1162 1120 1163 /** 1121 1164 * Load the comment template specified in $file. 1122 1165 * … … 1186 1229 1187 1230 $comment_args = array( 1188 1231 'order' => 'ASC', 1232 'fields' => 'ids', 1189 1233 'orderby' => 'comment_date_gmt', 1190 1234 'status' => 'approve', 1191 1235 'post_id' => $post->ID, … … 1197 1241 $comment_args['include_unapproved'] = array( $comment_author_email ); 1198 1242 } 1199 1243 1244 $top_level = 0; 1245 $threaded = get_option( 'thread_comments' ); 1246 if ( $threaded ) { 1247 $comment_args['parent'] = 0; 1248 // array of all top-level comment IDs for the post 1249 $comment_ids = get_comments( $comment_args ); 1250 $top_level = count( $comment_ids ); 1251 } else { 1252 // array of all comment IDs for the post 1253 $comment_ids = get_comments( $comment_args ); 1254 } 1255 1256 $pages = wp_comment_pages_count( $post->comment_count, $top_level ); 1257 $wp_query->comment_pages_count = $pages; 1258 $wp_query->comment_pages_page = 1; 1259 1260 if ( $pages > 1 ) { 1261 $per_page = wp_comments_per_page(); 1262 $page = (int) get_query_var( 'cpage' ); 1263 if ( 0 === $page ) { 1264 $page = 1; 1265 } 1266 $wp_query->comment_pages_page = $page; 1267 1268 $comment_ids = array_slice( $comment_ids, ( $page - 1 ) * $per_page, $per_page ); 1269 if ( $threaded ) { 1270 $comment_ids = wp_threaded_comment_ids( $comment_ids, $comment_args ); 1271 } 1272 1273 $comment_args['comment__in'] = $comment_ids; 1274 $comment_args['orderby'] = 'comment__in'; 1275 unset( $comment_args['order'] ); 1276 } 1277 1278 unset( $comment_args['parent'], $comment_args['fields'] ); 1200 1279 $comments = get_comments( $comment_args ); 1201 1280 1202 1281 /** … … 1818 1897 if ( null === $r['reverse_top_level'] ) 1819 1898 $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ); 1820 1899 1900 if ( null === $comments && 1 < $wp_query->comment_pages_count ) { 1901 $r['page'] = 1; 1902 } 1903 1821 1904 if ( empty( $r['walker'] ) ) { 1822 1905 $walker = new Walker_Comment; 1823 1906 } else {