Make WordPress Core

Ticket #14922: 14922.003.diff

File 14922.003.diff, 5.8 KB (added by scribu, 14 years ago)
  • wp-includes/post.php

     
    20742074
    20752075        $post = get_post($postid, $mode);
    20762076
    2077         if ( 
     2077        if (
    20782078                ( OBJECT == $mode && empty( $post->ID ) ) ||
    20792079                ( OBJECT != $mode && empty( $post['ID'] ) )
    20802080        )
     
    38813881 *
    38823882 * @since 0.71
    38833883 *
    3884  * @uses $wpdb
    3885  * @uses $blog_id
    38863884 * @uses apply_filters() Calls 'get_lastpostdate' filter
    38873885 *
    3888  * @global mixed $cache_lastpostdate Stores the last post date
    3889  * @global mixed $pagenow The current page being viewed
    3890  *
    38913886 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
    38923887 * @return string The date of the last post.
    38933888 */
    38943889function get_lastpostdate($timezone = 'server') {
    3895         global $cache_lastpostdate, $wpdb, $blog_id;
    3896         $add_seconds_server = date('Z');
    3897         if ( !isset($cache_lastpostdate[$blog_id][$timezone]) ) {
    3898                 switch(strtolower($timezone)) {
    3899                         case 'gmt':
    3900                                 $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1");
    3901                                 break;
    3902                         case 'blog':
    3903                                 $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1");
    3904                                 break;
    3905                         case 'server':
    3906                                 $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1");
    3907                                 break;
    3908                 }
    3909                 $cache_lastpostdate[$blog_id][$timezone] = $lastpostdate;
    3910         } else {
    3911                 $lastpostdate = $cache_lastpostdate[$blog_id][$timezone];
    3912         }
    3913         return apply_filters( 'get_lastpostdate', $lastpostdate, $timezone );
     3890        return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date' ), $timezone );
    39143891}
    39153892
    39163893/**
     
    39213898 * 'gmt' is when the last post was modified in GMT time.
    39223899 *
    39233900 * @since 1.2.0
    3924  * @uses $wpdb
    3925  * @uses $blog_id
    39263901 * @uses apply_filters() Calls 'get_lastpostmodified' filter
    39273902 *
    39283903 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
    39293904 * @return string The date the post was last modified.
    39303905 */
    39313906function get_lastpostmodified($timezone = 'server') {
    3932         global $wpdb;
     3907        $lastpostmodified = _get_last_post_time( $timezone, 'modified' );
    39333908
    3934         $add_seconds_server = date('Z');
    3935         $timezone = strtolower( $timezone );
    3936 
    3937         $lastpostmodified = wp_cache_get( "lastpostmodified:$timezone", 'timeinfo' );
    3938         if ( $lastpostmodified )
    3939                 return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
    3940 
    3941         switch ( strtolower($timezone) ) {
    3942                 case 'gmt':
    3943                         $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");
    3944                         break;
    3945                 case 'blog':
    3946                         $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");
    3947                         break;
    3948                 case 'server':
    3949                         $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");
    3950                         break;
    3951         }
    3952 
    39533909        $lastpostdate = get_lastpostdate($timezone);
    39543910        if ( $lastpostdate > $lastpostmodified )
    39553911                $lastpostmodified = $lastpostdate;
    39563912
    3957         if ( $lastpostmodified )
    3958                 wp_cache_set( "lastpostmodified:$timezone", $lastpostmodified, 'timeinfo' );
    3959 
    39603913        return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
    39613914}
    39623915
     3916function _get_last_post_time( $timezone, $field ) {
     3917        global $wpdb, $blog_id;
     3918
     3919        if ( !in_array( $field, array( 'date', 'modified' ) ) )
     3920                return false;
     3921
     3922        $post_types = get_query_var('post_type');
     3923        if ( empty($post_types) )
     3924                $post_types = 'post';
     3925
     3926        $post_types = apply_filters( "get_lastpost{$field}_post_types", (array) $post_types );
     3927
     3928        $key = "lastpost{$field}:$blog_id:$timezone:" . wp_cache_key( $post_types );
     3929
     3930        $date = wp_cache_get( $key, 'timeinfo' );
     3931
     3932        if ( !$date ) {
     3933                $add_seconds_server = date('Z');
     3934
     3935                array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );
     3936                $post_types = "'" . implode( "', '", $post_types ) . "'";
     3937
     3938                switch ( strtolower( $timezone ) ) {
     3939                        case 'gmt':
     3940                                $date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
     3941                                break;
     3942                        case 'blog':
     3943                                $date = $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
     3944                                break;
     3945                        case 'server':
     3946                                $date = $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
     3947                                break;
     3948                }
     3949
     3950                if ( $date )
     3951                        wp_cache_set( $key, $date, 'timeinfo' );
     3952        }
     3953
     3954        return $date;
     3955}
     3956
    39633957/**
    39643958 * Updates posts in cache.
    39653959 *
  • wp-includes/functions.php

     
    280280}
    281281
    282282/**
     283 * Generates a unique key from an argument
     284 *
     285 * @since 3.1
     286 *
     287 * @param mixed $arg
     288 * @return string
     289 */
     290function wp_cache_key( $arg ) {
     291        if ( is_scalar( $arg ) )
     292                return md5( $arg );
     293
     294        $arg = (array) $arg;
     295        sort( $arg );
     296
     297        return md5( serialize( $arg ) );
     298}
     299
     300/**
    283301 * Retrieve option value based on name of option.
    284302 *
    285303 * If the option does not exist or does not have a value, then the return value