Ticket #17455: 17455.3.diff
File 17455.3.diff, 5.8 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post-functions.php
5185 5185 * 'gmt' is when the last post was posted in GMT formatted date. 5186 5186 * 5187 5187 * @since 0.71 5188 * @since 4.3.0 The `$post_type` argument was added. 5188 5189 * 5189 * @param string $timezone The location to get the time. Accepts 'gmt', 'blog', 5190 * or 'server'. Default 'server'. 5190 * @param string $timezone Optional. The location to get the time. Accepts 'gmt', 'blog', 5191 * or 'server'. Default 'server'. 5192 * @param string $post_type Optional. The post type to check. Default 'any'. 5191 5193 * @return string The date of the last post. 5192 5194 */ 5193 function get_lastpostdate( $timezone = 'server' ) {5195 function get_lastpostdate( $timezone = 'server', $post_type = 'any' ) { 5194 5196 /** 5195 5197 * Filter the date the last post was published. 5196 5198 * … … 5200 5202 * 'blog', or 'server'. 5201 5203 * @param string $timezone Location to use for getting the post published date. 5202 5204 */ 5203 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date' ), $timezone );5205 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone ); 5204 5206 } 5205 5207 5206 5208 /** … … 5211 5213 * 'gmt' is when the last post was modified in GMT time. 5212 5214 * 5213 5215 * @since 1.2.0 5216 * @since 4.3.0 The `$post_type` argument was added. 5214 5217 * 5215 * @param string $timezone Optional. The timezone for the timestamp. Uses the server's internal timezone. 5216 * Accepts 'server', 'blog', 'gmt'. or 'server'. 'server' uses the server's 5217 * internal timezone. 'blog' uses the `post_modified` field, which proxies 5218 * to the timezone set for the site. 'gmt' uses the `post_modified_gmt` field. 5219 * Default 'server'. 5218 * @param string $timezone Optional. The timezone for the timestamp. Uses the server's internal timezone. 5219 * Accepts 'server', 'blog', 'gmt'. or 'server'. 'server' uses the server's 5220 * internal timezone. 'blog' uses the `post_modified` field, which proxies 5221 * to the timezone set for the site. 'gmt' uses the `post_modified_gmt` field. 5222 * Default 'server'. 5223 * @param string $post_type Optional. The post type to check. Default 'any'. 5220 5224 * @return string The timestamp. 5221 5225 */ 5222 function get_lastpostmodified( $timezone = 'server' ) {5223 $lastpostmodified = _get_last_post_time( $timezone, 'modified' );5226 function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) { 5227 $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type ); 5224 5228 5225 5229 $lastpostdate = get_lastpostdate($timezone); 5226 5230 if ( $lastpostdate > $lastpostmodified ) … … 5242 5246 * Get the timestamp of the last time any post was modified or published. 5243 5247 * 5244 5248 * @since 3.1.0 5249 * @since 4.3.0 The `$post_type` argument was added. 5245 5250 * @access private 5246 5251 * 5247 5252 * @global wpdb $wpdb 5248 5253 * 5249 * @param string $timezone The timezone for the timestamp. See {@see get_lastpostmodified()} 5250 * for information on accepted values. 5251 * @param string $field Post field to check. Accepts 'date' or 'modified'. 5254 * @param string $timezone The timezone for the timestamp. See {@see get_lastpostmodified()} 5255 * for information on accepted values. 5256 * @param string $field Post field to check. Accepts 'date' or 'modified'. 5257 * @param string $post_type Optional. The post type to check. Default 'any'. 5252 5258 * @return string|false The timestamp. 5253 5259 */ 5254 function _get_last_post_time( $timezone, $field ) {5260 function _get_last_post_time( $timezone, $field, $post_type = 'any' ) { 5255 5261 global $wpdb; 5256 5262 5257 5263 if ( !in_array( $field, array( 'date', 'modified' ) ) ) … … 5260 5266 $timezone = strtolower( $timezone ); 5261 5267 5262 5268 $key = "lastpost{$field}:$timezone"; 5269 if ( 'any' != $post_type ) { 5270 $key .= ':' . sanitize_key( $post_type ); 5271 } 5263 5272 5264 5273 $date = wp_cache_get( $key, 'timeinfo' ); 5265 5274 5266 5275 if ( !$date ) { 5267 $add_seconds_server = date('Z'); 5276 if ( 'any' == $post_type ) { 5277 $post_types = get_post_types( array( 'public' => true ) ); 5278 array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) ); 5279 $post_types = "'" . implode( "', '", $post_types ) . "'"; 5280 } else { 5281 $post_types = "'" . sanitize_key( $post_type ) . "'"; 5282 } 5268 5283 5269 $post_types = get_post_types( array( 'public' => true ) );5270 array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );5271 $post_types = "'" . implode( "', '", $post_types ) . "'";5272 5273 5284 switch ( $timezone ) { 5274 5285 case 'gmt': 5275 5286 $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"); … … 5278 5289 $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"); 5279 5290 break; 5280 5291 case 'server': 5292 $add_seconds_server = date( 'Z' ); 5281 5293 $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"); 5282 5294 break; 5283 5295 } 5284 5296 5285 if ( $date ) 5297 if ( $date ) { 5286 5298 wp_cache_set( $key, $date, 'timeinfo' ); 5299 } 5287 5300 } 5288 5301 5289 5302 return $date; … … 5506 5519 foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { 5507 5520 wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); 5508 5521 wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' ); 5522 wp_cache_delete( "lastpostdate:$timezone:{$post->post_type}", 'timeinfo' ); 5509 5523 } 5510 5524 } 5511 5525