WordPress.org

Make WordPress Core

Ticket #20487: comment_search_20487_v1.diff

File comment_search_20487_v1.diff, 6.6 KB (added by brokentone, 8 years ago)
  • wp-includes/comment.php

     
    222222                        'type' => '',
    223223                        'user_id' => '',
    224224                        'search' => '',
     225            'search_type' => '',
     226            'search_field' => '',
    225227                        'count' => false
    226228                );
    227229
     
    361363         */
    362364        function get_search_sql( $string, $cols ) {
    363365                $string = esc_sql( like_escape( $string ) );
     366        $wildcard = '%';
     367        if($this->query_vars['search_type'] == 'exact') $wildcard = '';
    364368
    365369                $searches = array();
    366                 foreach ( $cols as $col )
    367                         $searches[] = "$col LIKE '%$string%'";
     370        if($this->query_vars['search_field'] && in_array($this->query_vars['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        }
    368376
     377        if (count($searches) == 1) return ' AND ' . $searches[0];
    369378                return ' AND (' . implode(' OR ', $searches) . ')';
    370379        }
    371380}
  • wp-admin/edit-comments.php

     
    232232<?php if ( $post_id ) : ?>
    233233<input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
    234234<?php endif; ?>
    235 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
    236235<input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
    237236
    238237<input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('total_items') ); ?>" />
  • wp-admin/includes/class-wp-comments-list-table.php

     
    5050                $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
    5151
    5252                $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'] : '';
    5355
    5456                $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
    5557
     
    8789                $args = array(
    8890                        'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
    8991                        'search' => $search,
     92            'search_type' => $search_type,
     93            'search_field' => $search_field,
    9094                        'user_id' => $user_id,
    9195                        'offset' => $start,
    9296                        'number' => $number,
     
    462466                        }
    463467                        echo '<a href="edit-comments.php?s=';
    464468                        comment_author_IP();
    465                         echo '&amp;mode=detail';
     469                        echo '&amp;mode=detail&amp;s_type=exact&amp;s_field=comment_author_IP';
    466470                        if ( 'spam' == $comment_status )
    467471                                echo '&amp;comment_status=spam';
    468472                        echo '">';
     
    506510        function column_default( $comment, $column_name ) {
    507511                do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
    508512        }
     513    function search_box( $text, $input_id ) {
     514        if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
     515            return;
     516
     517        $input_id = $input_id . '-search-input';
     518
     519        if ( ! empty( $_REQUEST['orderby'] ) )
     520            echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
     521        if ( ! empty( $_REQUEST['order'] ) )
     522            echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
     523?>
     524<p class="search-box">
     525    <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
     526    <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
     527    <label for="<?php echo $input_id ?>_field"><strong>Field</strong></label>
     528    <select name="s_field" id="<?php echo $input_id ?>_field" value="">
     529        <option value="">All</option>
     530        <option value="comment_author"<?php print (isset($_REQUEST['s_field']) && $_REQUEST['s_field'] == 'comment_author') ? ' selected="selected"' : ''; ?>>User Name</option>
     531        <option value="comment_author_url"<?php print (isset($_REQUEST['s_field']) && $_REQUEST['s_field'] == 'comment_author_url') ? ' selected="selected"' : ''; ?>>User URL</option>
     532        <option value="comment_author_IP"<?php print (isset($_REQUEST['s_field']) && $_REQUEST['s_field'] == 'comment_author_IP') ? ' selected="selected"' : ''; ?>>User IP</option>
     533        <option value="comment_author_email"<?php print (isset($_REQUEST['s_field']) && $_REQUEST['s_field'] == 'comment_author_email') ? ' selected="selected"' : ''; ?>>User E-mail</option>
     534        <option value="comment_content"<?php print (isset($_REQUEST['s_field']) && $_REQUEST['s_field'] == 'comment_content') ? ' selected="selected"' : ''; ?>>Comment Content</option>
     535    </select>
     536    <label for="<?php echo $input_id ?>_status"><strong>Status</strong></label>
     537    <select name="comment_status" id="<?php echo $input_id ?>_status" value="">     
     538        <option value="">Any</option>
     539        <option value="approved"<?php print (isset($_REQUEST['comment_status']) && $_REQUEST['comment_status'] == 'approved') ? ' selected="selected"' : ''; ?>>Approved</option>
     540        <option value="moderated"<?php print (isset($_REQUEST['comment_status']) && $_REQUEST['comment_status'] == 'moderated') ? ' selected="selected"' : ''; ?>>Pending</option>
     541        <option value="spam"<?php print (isset($_REQUEST['comment_status']) && $_REQUEST['comment_status'] == 'spam') ? ' selected="selected"' : ''; ?>>Spam</option>
     542        <option value="trash"<?php print (isset($_REQUEST['comment_status']) && $_REQUEST['comment_status'] == 'trash') ? ' selected="selected"' : ''; ?>>Trash</option>
     543    </select>
     544    <label for="<?php echo $input_id ?>_type_exact">Exact</label> <input type="radio" name="s_type" id="<?php echo $input_id ?>_type_exact" value="exact"<?php print (isset($_REQUEST['s_type']) && $_REQUEST['s_type'] == 'exact') ? ' checked="checked"' : ''; ?> />
     545    <label for="<?php echo $input_id ?>_type_wildcard">Wildcard</label> <input type="radio" name="s_type" id="<?php echo $input_id ?>_type_wildcard" value="wildcard"<?php print (isset($_REQUEST['s_type']) && $_REQUEST['s_type'] == 'wildcard') ? ' checked="checked"' : ''; ?> />
     546    <?php submit_button( $text, 'button', false, false, array('id' => 'search-submit') ); ?>
     547</p>
     548<?php
     549    }
     550
    509551}
    510552
    511553/**