diff --git a/wp-includes/comment.php b/wp-includes/comment.php index ddb8e47d4..ec93dc0d0 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -199,24 +199,26 @@ function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = fals */ function get_lastcommentmodified($timezone = 'server') { global $cache_lastcommentmodified, $wpdb; + + if ( isset($cache_lastcommentmodified[$timezone]) ) + return $cache_lastcommentmodified[$timezone]; + $add_seconds_server = date('Z'); - $now = current_time('mysql', 1); - if ( !isset($cache_lastcommentmodified[$timezone]) ) { - switch ( strtolower($timezone)) { - case 'gmt': - $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)); - break; - case 'blog': - $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)); - break; - case 'server': - $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)); - break; - } - $cache_lastcommentmodified[$timezone] = $lastcommentmodified; - } else { - $lastcommentmodified = $cache_lastcommentmodified[$timezone]; + + switch ( strtolower($timezone)) { + case 'gmt': + $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1"); + break; + case 'blog': + $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1"); + break; + case 'server': + $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)); + break; } + + $cache_lastcommentmodified[$timezone] = $lastcommentmodified; + return $lastcommentmodified; }