WordPress.org

Make WordPress Core

Ticket #17020: dashboard-recent-comments-3.2.diff

File dashboard-recent-comments-3.2.diff, 1.9 KB (added by adamsewell, 7 years ago)

Modifies the wp_dashboard_recent_comments function to use get_comments - updated to remove reference to $wpdb

  • wp-admin/includes/dashboard.php

     
    594594 * @since 2.5.0
    595595 */
    596596function wp_dashboard_recent_comments() {
    597         global $wpdb;
    598 
    599         if ( current_user_can('edit_posts') )
    600                 $allowed_states = array('0', '1');
    601         else
    602                 $allowed_states = array('1');
    603 
    604597        // Select all comment types and filter out spam later for better query performance.
    605598        $comments = array();
    606         $start = 0;
    607599
    608600        $widgets = get_option( 'dashboard_widget_options' );
    609601        $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] )
    610602                ? absint( $widgets['dashboard_recent_comments']['items'] ) : 5;
     603       
     604        $comment_args = array(
     605                'status' => (current_user_can('edit_posts') ? null : 'hold'),
     606                'number' => $total_items,
     607                'offset' => 0,
     608                'orderby' => 'comment_date_gmt',
     609                'order' => 'DESC'
     610                );
     611       
     612        $comments = get_comments( $comment_args );
    611613
    612         while ( count( $comments ) < $total_items && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
    613 
    614                 foreach ( $possible as $comment ) {
    615                         if ( count( $comments ) >= $total_items )
    616                                 break;
    617                         if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) )
    618                                 $comments[] = $comment;
    619                 }
    620 
    621                 $start = $start + 50;
    622         }
    623 
    624614        if ( $comments ) :
    625615?>
    626616
    627617                <div id="the-comment-list" class="list:comment">
    628618<?php
    629619                foreach ( $comments as $comment )
    630                         _wp_dashboard_recent_comments_row( $comment );
     620                        if( current_user_can( 'read_post', $comment->comment_post_ID) )
     621                                _wp_dashboard_recent_comments_row( $comment );
    631622?>
    632623
    633624                </div>