Ticket #20487: comment_search_20487_v4.diff
| File comment_search_20487_v4.diff, 4.0 KB (added by , 14 years ago) |
|---|
-
wp-includes/comment.php
222 222 'type' => '', 223 223 'user_id' => '', 224 224 'search' => '', 225 'search_wild' => 'both', 226 'search_columns' => array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ), 225 227 'count' => false 226 228 ); 229 if( isset( $query_vars['search_columns'] ) ) $query_vars['search_columns'] = array_intersect( $query_vars['search_columns'], $defaults['search_columns'] ); 227 230 228 231 $this->query_vars = wp_parse_args( $query_vars, $defaults ); 229 232 do_action_ref_array( 'pre_get_comments', array( &$this ) ); … … 322 325 if ( '' !== $user_id ) 323 326 $where .= $wpdb->prepare( ' AND user_id = %d', $user_id ); 324 327 if ( '' !== $search ) 325 $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ));328 $where .= $this->get_search_sql( $search, $search_columns, $search_wild ); 326 329 327 330 $post_fields = array_filter( compact( array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type', ) ) ); 328 331 if ( ! empty( $post_fields ) ) { … … 337 340 $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 338 341 339 342 $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where ORDER BY $orderby $order $limits"; 340 343 do_action_ref_array( 'pre_comment_query', array( &$query ) ); 341 344 if ( $count ) 342 345 return $wpdb->get_var( $query ); 343 346 … … 357 360 * 358 361 * @param string $string 359 362 * @param array $cols 363 * @param string $wild Allowing wildcard searches, false, leading, trailing, or both. 360 364 * @return string 361 365 */ 362 function get_search_sql( $string, $cols ) {363 $string = esc_sql( like_escape( $string ));366 function get_search_sql( $string, $cols, $wild = false ) { 367 $string = esc_sql( $string ); 364 368 365 369 $searches = array(); 366 foreach ( $cols as $col )367 $searches[] = "$col LIKE '%$string%'";370 $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : ''; 371 $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : ''; 368 372 369 return ' AND (' . implode(' OR ', $searches) . ')'; 373 foreach ( $cols as $col ) { 374 $searches[] = "$col LIKE '$leading_wild" . like_escape( $string ) . "$trailing_wild'"; 375 } 376 377 return ' AND (' . implode( ' OR ', $searches ) . ')'; 370 378 } 371 379 } 372 380 -
wp-admin/includes/class-wp-comments-list-table.php
50 50 $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : ''; 51 51 52 52 $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : ''; 53 $search_wild = ( isset( $_REQUEST['s_wild'] ) ) ? $_REQUEST['s_wild'] : ''; 54 $search_columns = ( isset( $_REQUEST['s_columns'] ) ) ? $_REQUEST['s_columns'] : ''; 53 55 54 56 $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : ''; 55 57 … … 87 89 $args = array( 88 90 'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status, 89 91 'search' => $search, 92 'search_wild' => $search_wild ? $search_wild : 'both', 90 93 'user_id' => $user_id, 91 94 'offset' => $start, 92 95 'number' => $number, … … 95 98 'orderby' => $orderby, 96 99 'order' => $order, 97 100 ); 101 // Only set $args['search_columns'] if $search_columns exists so that default columns override otherwise 102 if( $search_columns ) $args['search_columns'] = (array) $search_columns; 98 103 99 104 $_comments = get_comments( $args ); 100 105 … … 462 467 } 463 468 echo '<a href="edit-comments.php?s='; 464 469 comment_author_IP(); 465 echo '&mode=detail ';470 echo '&mode=detail&s_wild=none&s_columns=comment_author_IP'; 466 471 if ( 'spam' == $comment_status ) 467 472 echo '&comment_status=spam'; 468 473 echo '">';