WordPress.org

Make WordPress Core

Ticket #4378: widgets.patch

File widgets.patch, 1.5 KB (added by hovenko, 7 years ago)

Adds filters for distinct, join and where to recent comments.

  • widgets.php

     
    710710        else if ( $number > 15 ) 
    711711                $number = 15; 
    712712 
    713         if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) { 
    714                 $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number"); 
    715                 wp_cache_add( 'recent_comments', $comments, 'widget' ); 
     713        $comments_distinct      = apply_filters('comments_distinct', ''); 
     714        $comments_join          = apply_filters('comments_join', ''); 
     715        $comments_where         = apply_filters('comments_where', ''); 
     716         
     717        // Making the cache work with the filters 
     718        $key = md5($comments_join . $comments_where); 
     719        $key = "cache_$key"; 
     720         
     721        $comments_cache = wp_cache_get( "recent_comments", 'widget' ); 
     722        if( empty($comments_cache) ) { 
     723                $comments_cache = array(); 
     724        } 
     725         
     726        if ( !$comments = $comments_cache[$key] ) { 
     727                $comments = $wpdb->get_results("SELECT $comments_distinct comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments $comments_join WHERE comment_approved = '1' $comments_where ORDER BY comment_date_gmt DESC LIMIT $number"); 
     728                $comments_cache[$key] = $comments; 
     729                wp_cache_add( "recent_comments", $comments_cache, 'widget' ); 
    716730        } 
    717731?> 
    718732