Make WordPress Core

Ticket #7552: comment_type-filter.patch

File comment_type-filter.patch, 4.2 KB (added by Viper007Bond, 16 years ago)

Add comment_type filtering to Edit Comments page

  • wp-admin/edit-comments.php

     
    7272
    7373$mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : attribute_escape($_GET['mode']);
    7474
    75 $comment_status = isset($_GET['comment_status']) ? attribute_escape($_GET['comment_status']) : '';
     75$comment_status = !empty($_GET['comment_status']) ? attribute_escape($_GET['comment_status']) : '';
    7676
     77$comment_type = !empty($_GET['comment_type']) ? attribute_escape($_GET['comment_type']) : '';
     78
    7779$post_id = isset($_GET['p']) ? (int) $_GET['p'] : 0;
    7880
    7981$search_dirty = ( isset($_GET['s']) ) ? $_GET['s'] : '';
     
    134136        );
    135137$class = ( '' === $comment_status ) ? ' class="current"' : '';
    136138$status_links[] = "<li><a href=\"edit-comments.php\"$class>".__('Show All Comments')."</a>";
     139$type = ( !$comment_type && 'all' != $comment_type ) ? '' : "&amp;comment_type=$comment_type";
    137140foreach ( $stati as $status => $label ) {
    138141        $class = '';
    139142
    140143        if ( $status == $comment_status )
    141144                $class = ' class="current"';
    142145
    143         $status_links[] = "<li class='$status'><a href=\"edit-comments.php?comment_status=$status\"$class>$label</a>";
     146        $status_links[] = "<li class='$status'><a href=\"edit-comments.php?comment_status=$status$type\"$class>$label</a>";
    144147}
    145148
    146149$status_links = apply_filters( 'comment_status_links', $status_links );
     
    150153?>
    151154</ul>
    152155
     156<div class="filter">
     157<form id="list-filter" action="" method="get">
     158<?php if ( $comment_status ) echo "<input type='hidden' name='comment_status' value='$comment_status' />\n"; ?>
     159<select name="comment_type">
     160        <option value="all"><?php _e('Show all comment types'); ?></option>
    153161<?php
     162        $comment_types = array(
     163                'comment' => __('Comments'),
     164                'pingback' => __('Pingbacks'),
     165                'trackback' => __('Trackbacks'),
     166        );
     167
     168        foreach ( $comment_types as $type => $label ) {
     169                echo "  <option value='$type'";
     170                selected( $comment_type, $type );
     171                echo ">$label</option>\n";
     172        }
     173?>
     174</select>
     175<input type="submit" id="post-query-submit" value="<?php _e('Filter'); ?>" class="button-secondary" />
     176</form>
     177</div>
     178
     179<?php
    154180$comments_per_page = apply_filters('comments_per_page', 20, $comment_status);
    155181
    156182if ( isset( $_GET['apage'] ) )
     
    160186
    161187$start = $offset = ( $page - 1 ) * $comments_per_page;
    162188
    163 list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 5, $post_id ); // Grab a few extra
     189list($_comments, $total) = _wp_get_comment_list( $comment_status, $search_dirty, $start, $comments_per_page + 5, $post_id, $comment_type ); // Grab a few extra
    164190
    165191$comments = array_slice($_comments, 0, $comments_per_page);
    166192$extra_comments = array_slice($_comments, $comments_per_page);
  • wp-admin/includes/template.php

     
    15311531        return $r;
    15321532}
    15331533
    1534 function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0 ) {
     1534function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0, $type = '' ) {
    15351535        global $wpdb;
    15361536
    15371537        $start = abs( (int) $start );
     
    15521552        else
    15531553                $post = '';
    15541554
     1555        if ( 'comment' == $type )
     1556                $typesql = "AND comment_type = ''";
     1557        elseif ( 'pingback' == $type )
     1558                $typesql = "AND comment_type = 'pingback'";
     1559        elseif ( 'trackback' == $type )
     1560                $typesql = "AND comment_type = 'trackback'";
     1561        else
     1562                $typesql = '';
     1563
    15551564        if ( $s ) {
    15561565                $s = $wpdb->escape($s);
    15571566                $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
     
    15611570                        comment_author_IP LIKE ('%$s%') OR
    15621571                        comment_content LIKE ('%$s%') ) AND
    15631572                        $approved
     1573                        $typesql
    15641574                        ORDER BY comment_date_gmt DESC LIMIT $start, $num");
    15651575        } else {
    1566                 $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE $approved $post ORDER BY comment_date_gmt DESC LIMIT $start, $num" );
     1576                $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE $approved $post $typesql ORDER BY comment_date_gmt DESC LIMIT $start, $num" );
    15671577        }
    15681578
    15691579        update_comment_cache($comments);