Ticket #17455: 17455.2.diff
File 17455.2.diff, 3.8 KB (added by , 14 years ago) |
---|
-
wp-includes/post.php
4138 4138 * @uses apply_filters() Calls 'get_lastpostdate' filter 4139 4139 * 4140 4140 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. 4141 * @param string $post_type The post type to check. Default is 'any' for any publicly queryable post type. 4141 4142 * @return string The date of the last post. 4142 4143 */ 4143 function get_lastpostdate( $timezone = 'server') {4144 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date' ), $timezone );4144 function get_lastpostdate( $timezone = 'server', $post_type = 'any' ) { 4145 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone ); 4145 4146 } 4146 4147 4147 4148 /** … … 4155 4156 * @uses apply_filters() Calls 'get_lastpostmodified' filter 4156 4157 * 4157 4158 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. 4159 * @param string $post_type The post type to check. Default is 'any' for any publicly queryable post type. 4158 4160 * @return string The date the post was last modified. 4159 4161 */ 4160 function get_lastpostmodified( $timezone = 'server') {4161 $lastpostmodified = _get_last_post_time( $timezone, 'modified' );4162 function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) { 4163 $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type ); 4162 4164 4163 4165 $lastpostdate = get_lastpostdate($timezone); 4164 4166 if ( $lastpostdate > $lastpostmodified ) … … 4175 4177 * 4176 4178 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. 4177 4179 * @param string $field Field to check. Can be 'date' or 'modified'. 4180 * @param string $post_type The post type to check. Can be 'any' for any publicly queryable post type. 4178 4181 * @return string The date. 4179 4182 */ 4180 function _get_last_post_time( $timezone, $field ) {4183 function _get_last_post_time( $timezone, $field, $post_type ) { 4181 4184 global $wpdb; 4182 4185 4183 4186 if ( !in_array( $field, array( 'date', 'modified' ) ) ) … … 4186 4189 $timezone = strtolower( $timezone ); 4187 4190 4188 4191 $key = "lastpost{$field}:$timezone"; 4192 if ( 'any' != $post_type ) 4193 $key .= ':' . sanitize_key( $post_type ); 4189 4194 4190 4195 $date = wp_cache_get( $key, 'timeinfo' ); 4191 4196 4192 4197 if ( !$date ) { 4193 $add_seconds_server = date('Z'); 4198 if ( 'any' == $post_type ) { 4199 $post_types = get_post_types( array( 'publicly_queryable' => true ) ); 4200 array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) ); 4201 $post_types = "'" . implode( "', '", $post_types ) . "'"; 4202 } else { 4203 $post_types = "'" . sanitize_key( $post_type ) . "'"; 4204 } 4194 4205 4195 $post_types = get_post_types( array( 'publicly_queryable' => true ) );4196 array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );4197 $post_types = "'" . implode( "', '", $post_types ) . "'";4198 4199 4206 switch ( $timezone ) { 4200 4207 case 'gmt': 4201 4208 $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"); … … 4204 4211 $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"); 4205 4212 break; 4206 4213 case 'server': 4214 $add_seconds_server = date('Z'); 4207 4215 $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"); 4208 4216 break; 4209 4217 } … … 4462 4470 foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { 4463 4471 wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); 4464 4472 wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' ); 4473 wp_cache_delete( "lastpostdate:$timezone:{$post->post_type}", 'timeinfo' ); 4465 4474 } 4466 4475 } 4467 4476