WordPress.org

Make WordPress Core

Ticket #4575: 4575.2.diff

File 4575.2.diff, 5.7 KB (added by spacedmonkey, 4 years ago)
  • src/wp-includes/feed-atom-comments.php

     
    4242        <subtitle type="text"><?php bloginfo_rss('description'); ?></subtitle>
    4343
    4444        <updated><?php
    45                 $date = get_lastcommentmodified( 'GMT' );
     45                $date = get_last_build_date();
    4646                echo $date ? mysql2date( 'Y-m-d\TH:i:s\Z', $date, false ) : date( 'Y-m-d\TH:i:s\Z' );
    4747        ?></updated>
    4848
  • src/wp-includes/feed-atom.php

     
    3131        <subtitle type="text"><?php bloginfo_rss("description") ?></subtitle>
    3232
    3333        <updated><?php
    34                 $date = get_lastpostmodified( 'GMT' );
     34                $date = get_last_build_date();
    3535                echo $date ? mysql2date( 'Y-m-d\TH:i:s\Z', $date, false ) : date( 'Y-m-d\TH:i:s\Z' );
    3636        ?></updated>
    3737
  • src/wp-includes/feed-rss2-comments.php

     
    4848        <link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link>
    4949        <description><?php bloginfo_rss("description") ?></description>
    5050        <lastBuildDate><?php
    51                 $date = get_lastcommentmodified( 'GMT' );
     51                $date = get_last_build_date();
    5252                echo $date ? mysql2date( 'r', $date, false ) : date( 'r' );
    5353        ?></lastBuildDate>
    5454        <sy:updatePeriod><?php
  • src/wp-includes/feed-rss2.php

     
    4343        <link><?php bloginfo_rss('url') ?></link>
    4444        <description><?php bloginfo_rss("description") ?></description>
    4545        <lastBuildDate><?php
    46                 $date = get_lastpostmodified( 'GMT' );
     46                $date = get_last_build_date();
    4747                echo $date ? mysql2date( 'r', $date, false ) : date( 'r' );
    4848        ?></lastBuildDate>
    4949        <language><?php bloginfo_rss( 'language' ); ?></language>
  • src/wp-includes/feed.php

     
    8989}
    9090
    9191/**
     92 * Get the timestamp of the most recently modified post from WP_Query
     93 *
     94 * If viewing a comment feed, the date of the most recently modified
     95 * comment will be returned.
     96 *
     97 * @global WP_Query  $wp_query
     98 *
     99 * @since 4.9.0
     100 *
     101 * @return string The timestamp.
     102 */
     103function get_last_build_date() {
     104        global $wp_query;
     105
     106        if ( ! $wp_query->have_posts() ) {
     107                // Fallback to last time any post was modified or published
     108                return get_lastpostmodified( 'GMT' );
     109        }
     110
     111        // Determine max post time
     112        $post_times    = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' );
     113        $max_post_time = max( $post_times );
     114
     115        // If this is a comment feed, check those objects too
     116        if ( $wp_query->is_comment_feed() && $wp_query->have_comments() ) {
     117                // Determine the max comment time
     118                $comment_times    = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' );
     119                $max_comment_time = max( $comment_times );
     120
     121                // The most recent timestamp between posts and comments
     122                $max_post_time = max( $max_post_time, $max_comment_time );
     123        }
     124
     125        // Return the most recent post timestamp if there are no comments to consider
     126        return $max_post_time;
     127}
     128
     129/**
    92130 * Retrieve the blog title for the feed title.
    93131 *
    94132 * @since 2.2.0
  • tests/phpunit/tests/feed/rss2.php

     
    3232                ) );
    3333
    3434                // Set a predictable time for testing date archives.
    35                 self::$post_date = '2003-05-27 10:07:53';
     35                self::$post_date = strtotime( '2003-05-27 10:07:53' );
    3636
    3737                $count = get_option( 'posts_per_rss' ) + 1;
    3838
    3939                // Create a few posts
    40                 self::$posts = $factory->post->create_many( $count, array(
    41                         'post_author'  => self::$user_id,
    42                         'post_date'    => self::$post_date,
    43                         'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec velit massa, ultrices eu est suscipit, mattis posuere est. Donec vitae purus lacus. Cras vitae odio odio.',
    44                         'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    45                 ) );
     40                self::$posts = array();
     41                for ( $i = 1; $i <= $count; $i ++ ) {
     42                        self::$posts[] = $factory->post->create( array(
     43                                'post_author'  => self::$user_id,
     44                                'post_date'    => gmdate( 'Y-m-d H:i:s', self::$post_date + ( 5 * $i ) ),
     45                                // separate post dates 5 seconds apart.
     46                                'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec velit massa, ultrices eu est suscipit, mattis posuere est. Donec vitae purus lacus. Cras vitae odio odio.',
     47                                'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
     48                        ) );
     49                }
    4650
    4751                // Assign a category to those posts
    4852                foreach ( self::$posts as $post ) {
     
    8387        }
    8488
    8589        /**
     90         * Test <rss> element has correct last build date.
     91         *
     92         * @ticket 4575
     93         */
     94        function test_get_last_build_date() {
     95                $this->go_to( '/?feed=rss2' );
     96                $feed = $this->do_rss2();
     97                $xml  = xml_to_array( $feed );
     98
     99                // Get the <rss> child element of <xml>.
     100                $rss             = xml_find( $xml, 'rss' );
     101                $last_build_date = $rss[0]['child'][0]['child'][4]['content'];
     102                $this->assertEquals( strtotime( get_last_build_date() ), strtotime( $last_build_date ) );
     103        }
     104
     105        /**
    86106         * Test the <rss> element to make sure its present and populated
    87107         * with the expected child elements and attributes.
    88108         */