Ticket #20487: comment_search_20487_v2.diff
| File comment_search_20487_v2.diff, 3.0 KB (added by , 14 years ago) |
|---|
-
wp-includes/comment.php
222 222 'type' => '', 223 223 'user_id' => '', 224 224 'search' => '', 225 'search_type' => '', 226 'search_field' => '', 225 227 'count' => false 226 228 ); 227 229 … … 322 324 if ( '' !== $user_id ) 323 325 $where .= $wpdb->prepare( ' AND user_id = %d', $user_id ); 324 326 if ( '' !== $search ) 325 $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) );327 $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ), $search_field, $search_type ); 326 328 327 329 $post_fields = array_filter( compact( array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type', ) ) ); 328 330 if ( ! empty( $post_fields ) ) { … … 359 361 * @param array $cols 360 362 * @return string 361 363 */ 362 function get_search_sql( $string, $cols ) {364 function get_search_sql( $string, $cols, $search_field='', $search_type='' ) { 363 365 $string = esc_sql( like_escape( $string ) ); 366 $wildcard = '%'; 367 if($search_type == 'exact') $wildcard = ''; 364 368 365 369 $searches = array(); 366 foreach ( $cols as $col ) 367 $searches[] = "$col LIKE '%$string%'"; 370 if($this->query_vars['search_field'] && in_array($search_field, $cols)) { 371 $searches[] = $this->query_vars['search_field'] . " LIKE '$wildcard$string$wildcard'"; 372 } else { 373 foreach ( $cols as $col ) 374 $searches[] = "$col LIKE '%$string%'"; 375 } 368 376 377 if (count($searches) == 1) return ' AND ' . $searches[0]; 369 378 return ' AND (' . implode(' OR ', $searches) . ')'; 370 379 } 371 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_type = ( isset( $_REQUEST['s_type'] ) ) ? $_REQUEST['s_type'] : ''; 54 $search_field = ( isset( $_REQUEST['s_field'] ) ) ? $_REQUEST['s_field'] : ''; 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_type' => $search_type, 93 'search_field' => $search_field, 90 94 'user_id' => $user_id, 91 95 'offset' => $start, 92 96 'number' => $number, … … 462 466 } 463 467 echo '<a href="edit-comments.php?s='; 464 468 comment_author_IP(); 465 echo '&mode=detail ';469 echo '&mode=detail&s_type=exact&s_field=comment_author_IP'; 466 470 if ( 'spam' == $comment_status ) 467 471 echo '&comment_status=spam'; 468 472 echo '">';