WordPress.org

Make WordPress Core

Ticket #9211: 9211.diff

File 9211.diff, 1.5 KB (added by Denis-de-Bernardy, 5 years ago)
  • wp-includes/default-widgets.php

     
    628628                else if ( $number > 15 ) 
    629629                        $number = 15; 
    630630 
    631                 if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) { 
    632                         $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 15"); 
     631                $can_view_private_comments = current_user_can('read_private_posts') 
     632                        || current_user_can('read_private_pages') 
     633                        || current_user_can('edit_posts') 
     634                        || current_user_can('edit_pages'); 
     635 
     636                if ( $can_view_private_comments ) { 
     637                        $comments = $wpdb->get_results("SELECT $wpdb->comments.* FROM $wpdb->comments JOIN $wpdb->posts ON ID = comment_post_ID AND ( post_type = 'post' AND " . get_private_posts_cap_sql('post') . " OR post_type = 'page' AND " . get_private_posts_cap_sql('page') . " ) WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 15"); 
     638                } elseif ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) { 
     639                        $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments JOIN wpdb->posts ON ID = comment_post_ID AND ( post_type = 'post' AND " . get_private_posts_cap_sql('post') . " OR post_type = 'page' AND " . get_private_posts_cap_sql('page') . " ) WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 15"); 
    633640                        wp_cache_add( 'recent_comments', $comments, 'widget' ); 
    634641                } 
    635642