Ticket #5650: get_lastcommentmodified.diff

File get_lastcommentmodified.diff, 2.2 KB (added by ryan, 4 years ago)
  • wp-includes/comment.php

     
    199199 */ 
    200200function get_lastcommentmodified($timezone = 'server') { 
    201201        global $cache_lastcommentmodified, $wpdb; 
     202 
     203        if ( isset($cache_lastcommentmodified[$timezone]) ) 
     204                return $cache_lastcommentmodified[$timezone]; 
     205 
    202206        $add_seconds_server = date('Z'); 
    203         $now = current_time('mysql', 1); 
    204         if ( !isset($cache_lastcommentmodified[$timezone]) ) { 
    205                 switch ( strtolower($timezone)) { 
    206                         case 'gmt': 
    207                                 $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_date_gmt <= %s AND comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $now)); 
    208                                 break; 
    209                         case 'blog': 
    210                                 $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT comment_date FROM $wpdb->comments WHERE comment_date_gmt <= %s AND comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $now)); 
    211                                 break; 
    212                         case 'server': 
    213                                 $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_date_gmt <= %s AND comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server, $now)); 
    214                                 break; 
    215                 } 
    216                 $cache_lastcommentmodified[$timezone] = $lastcommentmodified; 
    217         } else { 
    218                 $lastcommentmodified = $cache_lastcommentmodified[$timezone]; 
     207 
     208        switch ( strtolower($timezone)) { 
     209                case 'gmt': 
     210                        $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1"); 
     211                        break; 
     212                case 'blog': 
     213                        $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1"); 
     214                        break; 
     215                case 'server': 
     216                        $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server)); 
     217                        break; 
    219218        } 
     219 
     220        $cache_lastcommentmodified[$timezone] = $lastcommentmodified; 
     221 
    220222        return $lastcommentmodified; 
    221223} 
    222224