WordPress.org

Make WordPress Core

Ticket #12575: 12575.diff

File 12575.diff, 3.8 KB (added by ryan, 8 years ago)

get_lastpostmodified()

  • wp-includes/post.php

     
    37183718}
    37193719
    37203720/**
    3721  * Retrieve the date the the last post was published.
     3721 * Retrieve the date that the last post was published.
    37223722 *
    37233723 * The server timezone is the default and is the difference between GMT and
    37243724 * server time. The 'blog' value is the date when the last post was posted. The
     
    37703770 * @uses $blog_id
    37713771 * @uses apply_filters() Calls 'get_lastpostmodified' filter
    37723772 *
    3773  * @global mixed $cache_lastpostmodified Stores the date the last post was modified
    3774  *
    37753773 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
    37763774 * @return string The date the post was last modified.
    37773775 */
    37783776function get_lastpostmodified($timezone = 'server') {
    3779         global $cache_lastpostmodified, $wpdb, $blog_id;
     3777        global $wpdb;
     3778
    37803779        $add_seconds_server = date('Z');
    3781         if ( !isset($cache_lastpostmodified[$blog_id][$timezone]) ) {
    3782                 switch(strtolower($timezone)) {
    3783                         case 'gmt':
    3784                                 $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
    3785                                 break;
    3786                         case 'blog':
    3787                                 $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
    3788                                 break;
    3789                         case 'server':
    3790                                 $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
    3791                                 break;
    3792                 }
    3793                 $lastpostdate = get_lastpostdate($timezone);
    3794                 if ( $lastpostdate > $lastpostmodified ) {
    3795                         $lastpostmodified = $lastpostdate;
    3796                 }
    3797                 $cache_lastpostmodified[$blog_id][$timezone] = $lastpostmodified;
    3798         } else {
    3799                 $lastpostmodified = $cache_lastpostmodified[$blog_id][$timezone];
     3780        $timezone = strtolower( $timezone );
     3781
     3782        $lastpostmodified = wp_cache_get( "lastpostmodified:$timezone", 'timeinfo' );
     3783        if ( $lastpostmodified )
     3784                return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
     3785       
     3786        switch ( strtolower($timezone) ) {
     3787                case 'gmt':
     3788                        $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3789                        break;
     3790                case 'blog':
     3791                        $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3792                        break;
     3793                case 'server':
     3794                        $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3795                        break;
    38003796        }
     3797       
     3798        $lastpostdate = get_lastpostdate($timezone);
     3799        if ( $lastpostdate > $lastpostmodified )
     3800                $lastpostmodified = $lastpostdate;
     3801
     3802        if ( $lastpostmodified )
     3803                wp_cache_set( "lastpostmodified:$timezone", $lastpostmodified, 'timeinfo' );
     3804
    38013805        return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
    38023806}
    38033807
     
    40164020                do_action('private_to_published', $post->ID);  // Deprecated, use private_to_publish
    40174021        }
    40184022
     4023        // If published posts changed clear the lastpostmodified cache
     4024        if ( 'publish' == $new_status || 'publish' == $old_status) {
     4025                wp_cache_delete( 'lastpostmodified:server', 'timeinfo' );
     4026                wp_cache_delete( 'lastpostmodified:gmt',    'timeinfo' );
     4027                wp_cache_delete( 'lastpostmodified:blog',   'timeinfo' );
     4028        }
     4029
    40194030        // Always clears the hook in case the post status bounced from future to draft.
    40204031        wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) );
    40214032}