Changeset 46977
- Timestamp:
- 12/17/2019 08:52:44 PM (5 years ago)
- Location:
- branches/5.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.3
- Property svn:mergeinfo changed
/trunk merged: 46973-46974
- Property svn:mergeinfo changed
-
branches/5.3/src/wp-includes/feed.php
r46774 r46977 650 650 651 651 /** 652 * Get the timestampof the most recently modified post from WP_Query.653 * 654 * If viewing a comment feed, the time stampof the most recently modified652 * Get the UTC time of the most recently modified post from WP_Query. 653 * 654 * If viewing a comment feed, the time of the most recently modified 655 655 * comment will be returned. 656 656 * … … 659 659 * @since 5.2.0 660 660 * 661 * @param string $format Format of the timestamp to return, passed to mysql2date. 662 * 663 * @return string The timestamp. 661 * @param string $format Date format string to return the time in. 662 * @return string|false The time in requested format, or false on failure. 664 663 */ 665 664 function get_feed_build_date( $format ) { 666 665 global $wp_query; 667 666 668 if ( empty( $wp_query ) || ! $wp_query->have_posts() ) { 669 // Fallback to last time any post was modified or published. 670 return get_lastpostmodified( 'GMT' ); 671 } 672 673 // Extract the post modified times from the posts. 674 $modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' ); 675 676 // If this is a comment feed, check those objects too. 677 if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) { 678 // Extract the comment modified times from the comments. 679 $comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' ); 680 681 // Add the comment times to the post times for comparison. 682 $modified_times = array_merge( $modified_times, $comment_times ); 683 } 684 685 // Determine the maximum modified time. 686 $datetime = date_create_immutable_from_format( 687 'Y-m-d H:i:s', 688 max( $modified_times ), 689 new DateTimeZone( 'UTC' ) 690 ); 691 692 $max_modified_time = $datetime->format( $format ); 667 $datetime = false; 668 $max_modified_time = false; 669 $utc = new DateTimeZone( 'UTC' ); 670 671 if ( ! empty( $wp_query ) && $wp_query->have_posts() ) { 672 // Extract the post modified times from the posts. 673 $modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' ); 674 675 // If this is a comment feed, check those objects too. 676 if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) { 677 // Extract the comment modified times from the comments. 678 $comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' ); 679 680 // Add the comment times to the post times for comparison. 681 $modified_times = array_merge( $modified_times, $comment_times ); 682 } 683 684 // Determine the maximum modified time. 685 $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', max( $modified_times ), $utc ); 686 } 687 688 if ( false === $datetime ) { 689 // Fall back to last time any post was modified or published. 690 $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', get_lastpostmodified( 'GMT' ), $utc ); 691 } 692 693 if ( false !== $datetime ) { 694 $max_modified_time = $datetime->format( $format ); 695 } 693 696 694 697 /** … … 697 700 * @since 5.2.0 698 701 * 699 * @param string $max_modified_time Date the last post or comment was modified in the query. 700 * @param string $format The date format requested in get_feed_build_date. 702 * @param string|false $max_modified_time Date the last post or comment was modified in the query, in UTC. 703 * False on failure. 704 * @param string $format The date format requested in get_feed_build_date(). 701 705 */ 702 706 return apply_filters( 'get_feed_build_date', $max_modified_time, $format ); -
branches/5.3/src/wp-includes/post.php
r46975 r46977 6387 6387 * Default 'server'. 6388 6388 * @param string $post_type Optional. The post type to check. Default 'any'. 6389 * @return string The date of the last post .6389 * @return string The date of the last post, or false on failure. 6390 6390 */ 6391 6391 function get_lastpostdate( $timezone = 'server', $post_type = 'any' ) { … … 6395 6395 * @since 2.3.0 6396 6396 * 6397 * @param string $date Date the last post was published.6398 * @param string $timezone Location to use for getting the post published date.6399 * See get_lastpostdate() for accepted `$timezone` values.6397 * @param string|false $date Date the last post was published. False on failure. 6398 * @param string $timezone Location to use for getting the post published date. 6399 * See get_lastpostdate() for accepted `$timezone` values. 6400 6400 */ 6401 6401 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone ); … … 6416 6416 * Default 'server'. 6417 6417 * @param string $post_type Optional. The post type to check. Default 'any'. 6418 * @return string The timestamp in 'Y-m-d H:i:s' format .6418 * @return string The timestamp in 'Y-m-d H:i:s' format, or false on failure. 6419 6419 */ 6420 6420 function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) { … … 6447 6447 * @since 2.3.0 6448 6448 * 6449 * @param string $lastpostmodified The most recent time that a post was modified, in 'Y-m-d H:i:s' format. 6450 * @param string $timezone Location to use for getting the post modified date. 6451 * See get_lastpostdate() for accepted `$timezone` values. 6449 * @param string|false $lastpostmodified The most recent time that a post was modified, in 'Y-m-d H:i:s' format. 6450 * False on failure. 6451 * @param string $timezone Location to use for getting the post modified date. 6452 * See get_lastpostdate() for accepted `$timezone` values. 6452 6453 */ 6453 6454 return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone ); … … 6467 6468 * @param string $field Post field to check. Accepts 'date' or 'modified'. 6468 6469 * @param string $post_type Optional. The post type to check. Default 'any'. 6469 * @return string|false The timestamp in 'Y-m-d H:i:s' format, or false on error.6470 * @return string|false The timestamp in 'Y-m-d H:i:s' format, or false on failure. 6470 6471 */ 6471 6472 function _get_last_post_time( $timezone, $field, $post_type = 'any' ) { -
branches/5.3/tests/phpunit/tests/date/getFeedBuildDate.php
r46774 r46977 37 37 $this->assertEquals( '2018-07-23T03:13:23+00:00', get_feed_build_date( DATE_RFC3339 ) ); 38 38 } 39 40 /** 41 * Test that get_feed_build_date() works with invalid post dates. 42 * 43 * @ticket 48957 44 */ 45 public function test_should_fall_back_to_last_post_modified() { 46 global $wp_query; 47 48 update_option( 'timezone_string', 'Europe/Kiev' ); 49 $datetime = new DateTimeImmutable( 'now', wp_timezone() ); 50 $datetime_utc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); 51 52 $wp_query->posts = array(); 53 54 $this->assertFalse( get_feed_build_date( DATE_RFC3339 ), 'False when unable to determine valid time' ); 55 56 $this->factory->post->create( 57 array( 58 'post_date' => $datetime->format( 'Y-m-d H:i:s' ), 59 ) 60 ); 61 62 $this->assertEquals( 63 $datetime_utc->format( DATE_RFC3339 ), 64 get_feed_build_date( DATE_RFC3339 ), 65 'Fall back to time of last post modified with no posts' 66 ); 67 68 $post_id_broken = $this->factory->post->create(); 69 $post_broken = get_post( $post_id_broken ); 70 71 $post_broken->post_modified_gmt = 0; 72 73 $wp_query->posts = array( $post_broken ); 74 75 $this->assertEquals( 76 $datetime_utc->format( DATE_RFC3339 ), 77 get_feed_build_date( DATE_RFC3339 ), 78 'Fall back to time of last post modified with broken post object' 79 ); 80 } 39 81 }
Note: See TracChangeset
for help on using the changeset viewer.