Changeset 34201
- Timestamp:
- 09/15/2015 03:24:04 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-functions.php
r34163 r34201 5228 5228 * 5229 5229 * @since 0.71 5230 * 5231 * @param string $timezone The location to get the time. Accepts 'gmt', 'blog', 5232 * or 'server'. Default 'server'. 5230 * @since 4.4.0 The `$post_type` argument was added. 5231 * 5232 * @param string $timezone Optional. The location to get the time. Accepts 'gmt', 'blog', 5233 * or 'server'. Default 'server'. 5234 * @param string $post_type Optional. The post type to check. Default 'any'. 5233 5235 * @return string The date of the last post. 5234 5236 */ 5235 function get_lastpostdate( $timezone = 'server' ) {5237 function get_lastpostdate( $timezone = 'server', $post_type = 'any' ) { 5236 5238 /** 5237 5239 * Filter the date the last post was published. … … 5243 5245 * @param string $timezone Location to use for getting the post published date. 5244 5246 */ 5245 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date' ), $timezone );5247 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone ); 5246 5248 } 5247 5249 … … 5254 5256 * 5255 5257 * @since 1.2.0 5256 * 5257 * @param string $timezone Optional. The timezone for the timestamp. Uses the server's internal timezone. 5258 * Accepts 'server', 'blog', 'gmt'. or 'server'. 'server' uses the server's 5259 * internal timezone. 'blog' uses the `post_modified` field, which proxies 5260 * to the timezone set for the site. 'gmt' uses the `post_modified_gmt` field. 5261 * Default 'server'. 5258 * @since 4.4.0 The `$post_type` argument was added. 5259 * 5260 * @param string $timezone Optional. The timezone for the timestamp. Uses the server's internal timezone. 5261 * Accepts 'server', 'blog', 'gmt'. or 'server'. 'server' uses the server's 5262 * internal timezone. 'blog' uses the `post_modified` field, which proxies 5263 * to the timezone set for the site. 'gmt' uses the `post_modified_gmt` field. 5264 * Default 'server'. 5265 * @param string $post_type Optional. The post type to check. Default 'any'. 5262 5266 * @return string The timestamp. 5263 5267 */ 5264 function get_lastpostmodified( $timezone = 'server' ) {5265 $lastpostmodified = _get_last_post_time( $timezone, 'modified' );5268 function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) { 5269 $lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type ); 5266 5270 5267 5271 $lastpostdate = get_lastpostdate($timezone); 5268 if ( $lastpostdate > $lastpostmodified ) 5272 if ( $lastpostdate > $lastpostmodified ) { 5269 5273 $lastpostmodified = $lastpostdate; 5274 } 5270 5275 5271 5276 /** … … 5285 5290 * 5286 5291 * @since 3.1.0 5292 * @since 4.4.0 The `$post_type` argument was added. 5287 5293 * @access private 5288 5294 * 5289 5295 * @global wpdb $wpdb 5290 5296 * 5291 * @param string $timezone The timezone for the timestamp. See {@see get_lastpostmodified()} 5292 * for information on accepted values. 5293 * @param string $field Post field to check. Accepts 'date' or 'modified'. 5297 * @param string $timezone The timezone for the timestamp. See {@see get_lastpostmodified()} 5298 * for information on accepted values. 5299 * @param string $field Post field to check. Accepts 'date' or 'modified'. 5300 * @param string $post_type Optional. The post type to check. Default 'any'. 5294 5301 * @return string|false The timestamp. 5295 5302 */ 5296 function _get_last_post_time( $timezone, $field ) {5303 function _get_last_post_time( $timezone, $field, $post_type = 'any' ) { 5297 5304 global $wpdb; 5298 5305 5299 if ( ! in_array( $field, array( 'date', 'modified' ) ) )5306 if ( ! in_array( $field, array( 'date', 'modified' ) ) ) { 5300 5307 return false; 5308 } 5301 5309 5302 5310 $timezone = strtolower( $timezone ); 5303 5311 5304 5312 $key = "lastpost{$field}:$timezone"; 5313 if ( 'any' !== $post_type ) { 5314 $key .= ':' . sanitize_key( $post_type ); 5315 } 5305 5316 5306 5317 $date = wp_cache_get( $key, 'timeinfo' ); 5307 5318 5308 if ( !$date ) { 5309 $add_seconds_server = date('Z'); 5310 5311 $post_types = get_post_types( array( 'public' => true ) ); 5312 array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) ); 5313 $post_types = "'" . implode( "', '", $post_types ) . "'"; 5319 if ( ! $date ) { 5320 if ( 'any' === $post_type ) { 5321 $post_types = get_post_types( array( 'public' => true ) ); 5322 array_walk( $post_types, array( $wpdb, 'escape_by_ref' ) ); 5323 $post_types = "'" . implode( "', '", $post_types ) . "'"; 5324 } else { 5325 $post_types = "'" . sanitize_key( $post_type ) . "'"; 5326 } 5314 5327 5315 5328 switch ( $timezone ) { … … 5321 5334 break; 5322 5335 case 'server': 5336 $add_seconds_server = date( 'Z' ); 5323 5337 $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"); 5324 5338 break; 5325 5339 } 5326 5340 5327 if ( $date ) 5341 if ( $date ) { 5328 5342 wp_cache_set( $key, $date, 'timeinfo' ); 5343 } 5329 5344 } 5330 5345 … … 5549 5564 wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); 5550 5565 wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' ); 5566 wp_cache_delete( "lastpostdate:$timezone:{$post->post_type}", 'timeinfo' ); 5551 5567 } 5552 5568 }
Note: See TracChangeset
for help on using the changeset viewer.