Changeset 38925 for trunk/src/wp-includes/comment.php
- Timestamp:
- 10/25/2016 08:47:06 PM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/comment.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r38852 r38925 294 294 * 295 295 * @since 1.5.0 296 * @since 4.7.0 Replaced caching the modified date in a local static variable 297 * with the Object Cache API. 296 298 * 297 299 * @global wpdb $wpdb WordPress database abstraction object. 298 * @staticvar array $cache_lastcommentmodified 299 * 300 * @param string $timezone Which timezone to use in reference to 'gmt', 'blog', 301 * or 'server' locations. 302 * @return string Last comment modified date. 303 */ 304 function get_lastcommentmodified($timezone = 'server') { 300 * 301 * @param string $timezone Which timezone to use in reference to 'gmt', 'blog', or 'server' locations. 302 * @return string|false Last comment modified date on success, false on failure. 303 */ 304 function get_lastcommentmodified( $timezone = 'server' ) { 305 305 global $wpdb; 306 static $cache_lastcommentmodified = array(); 307 308 if ( isset($cache_lastcommentmodified[$timezone]) ) 309 return $cache_lastcommentmodified[$timezone]; 310 311 $add_seconds_server = date('Z'); 312 313 switch ( strtolower($timezone)) { 306 307 $timezone = strtolower( $timezone ); 308 $key = "lastcommentmodified:$timezone"; 309 310 $comment_modified_date = wp_cache_get( $key, 'timeinfo' ); 311 if ( false !== $comment_modified_date ) { 312 return $comment_modified_date; 313 } 314 315 switch ( $timezone ) { 314 316 case 'gmt': 315 $ lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");317 $comment_modified_date = $wpdb->get_var( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" ); 316 318 break; 317 319 case 'blog': 318 $ lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");320 $comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" ); 319 321 break; 320 322 case 'server': 321 $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)); 323 $add_seconds_server = date( 'Z' ); 324 325 $comment_modified_date = $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 ) ); 322 326 break; 323 327 } 324 328 325 $cache_lastcommentmodified[$timezone] = $lastcommentmodified; 326 327 return $lastcommentmodified; 329 if ( $comment_modified_date ) { 330 wp_cache_set( $key, $comment_modified_date, 'timeinfo' ); 331 332 return $comment_modified_date; 333 } 334 335 return false; 328 336 } 329 337 … … 1574 1582 1575 1583 /** 1584 * Clear the lastcommentmodified cached value when a comment status is changed. 1585 * 1586 * Deletes the lastcommentmodified cache key when a comment enters or leaves 1587 * 'approved' status. 1588 * 1589 * @since 4.7.0 1590 * @access private 1591 * 1592 * @param string $new_status The new comment status. 1593 * @param string $old_status The old comment status. 1594 */ 1595 function _clear_modified_cache_on_transition_comment_status( $new_status, $old_status ) { 1596 if ( 'approved' === $new_status || 'approved' === $old_status ) { 1597 foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { 1598 wp_cache_delete( "lastcommentmodified:$timezone", 'timeinfo' ); 1599 } 1600 } 1601 } 1602 1603 /** 1576 1604 * Get current commenter's name, email, and URL. 1577 1605 * … … 1682 1710 if ( $comment_approved == 1 ) { 1683 1711 wp_update_comment_count( $comment_post_ID ); 1712 1713 foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { 1714 wp_cache_delete( "lastcommentmodified:$timezone", 'timeinfo' ); 1715 } 1684 1716 } 1685 1717
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)