Ticket #10668: extend_get_comments.10668.diff
| File extend_get_comments.10668.diff, 2.6 KB (added by , 17 years ago) |
|---|
-
wp-includes/comment.php
182 182 function get_comments( $args = '' ) { 183 183 global $wpdb; 184 184 185 $defaults = array('status' => '', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0); 185 $defaults = array( 186 'author_email' => '', 187 'ID' => '', 188 'karma' => '', 189 'number' => '', 190 'offset' => '', 191 'orderby' => '', 192 'order' => 'DESC', 193 'parent' => '', 194 'post_ID' => '', 195 'post_id' => 0, 196 'status' => '', 197 'type' => '', 198 'user_id' => '', 199 ); 186 200 187 201 $args = wp_parse_args( $args, $defaults ); 188 202 extract( $args, EXTR_SKIP ); … … 215 229 216 230 $order = ( 'ASC' == $order ) ? 'ASC' : 'DESC'; 217 231 218 $orderby = 'comment_date_gmt'; // Hard code for now 232 if ( ! empty( $orderby ) ) { 233 $ordersby = is_array($orderby) ? $orderby : preg_split('/[,\s]/', $orderby); 234 $ordersby = array_intersect( 235 $ordersby, 236 array( 237 'comment_agent', 238 'comment_approved', 239 'comment_author', 240 'comment_author_email', 241 'comment_author_IP', 242 'comment_author_url', 243 'comment_content', 244 'comment_date', 245 'comment_date_gmt', 246 'comment_ID', 247 'comment_karma', 248 'comment_parent', 249 'comment_post_ID', 250 'comment_type', 251 'user_id', 252 ) 253 ); 254 $orderby = empty( $ordersby ) ? 'comment_date_gmt' : implode(', ', $ordersby); 255 } else { 256 $orderby = 'comment_date_gmt'; 257 } 219 258 220 259 $number = absint($number); 221 260 $offset = absint($offset); … … 230 269 $number = ''; 231 270 } 232 271 272 $post_where = ''; 273 233 274 if ( ! empty($post_id) ) 234 $post_where = $wpdb->prepare( 'comment_post_ID = %d AND', $post_id ); 235 else 236 $post_where = ''; 275 $post_where .= $wpdb->prepare( 'comment_post_ID = %d AND ', $post_id ); 276 if ( '' !== $author_email ) 277 $post_where .= $wpdb->prepare( 'comment_author_email = %s AND ', $author_email ); 278 if ( '' !== $karma ) 279 $post_where .= $wpdb->prepare( 'comment_karma = %d AND ', $karma ); 280 if ( 'comment' == $type ) 281 $post_where .= "comment_type = '' AND "; 282 elseif ( ! empty( $type ) ) 283 $post_where .= $wpdb->prepare( 'comment_type = %s AND ', $type ); 284 if ( '' !== $parent ) 285 $post_where .= $wpdb->prepare( 'comment_parent = %d AND ', $parent ); 286 if ( '' !== $user_id ) 287 $post_where .= $wpdb->prepare( 'user_id = %d AND ', $user_id ); 237 288 238 289 $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE $post_where $approved ORDER BY $orderby $order $number" ); 239 290 wp_cache_add( $cache_key, $comments, 'comment' );
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)