WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/20/2019 08:37:02 PM (2 years ago)
Author:
adamsilverstein
Message:

Feeds: ensure build/update date matches current query.

Displaying the correct build date in feeds is as important today as it was twelve years ago when this ticket was opened.

Fix an issue where all feeds in WordPress showed the same date for their last build date (the datapoint is lastBuildDate, updated or dc:date depending on the feed type).

Introduce a new get_last_build_date filter to adjust the date used for lastBuildDate. Developers who previously filtered get_lastcommentmodified to alter feed dates should use this filter instead.

  • get_last_build_date extracts the latest post (or comment) in the current WP_Query object.
  • In all feed templates, use get_last_build_date vs get_lastpostmodified( 'GMT' );.

Props stevenkword, spacedmonkey, ryanshoover, mauteri, nacin, jorbin, MikeNGarrett, Denis-de-Bernardy, peaceablewhale.
Fixes #4575.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/feed/rss2.php

    r43571 r44948  
    3737
    3838        // Set a predictable time for testing date archives.
    39         self::$post_date = '2003-05-27 10:07:53';
     39        self::$post_date = strtotime( '2003-05-27 10:07:53' );
    4040
    4141        $count = get_option( 'posts_per_rss' ) + 1;
    4242
     43        self::$posts = array();
    4344        // Create a few posts
    44         self::$posts = $factory->post->create_many(
    45             $count,
    46             array(
    47                 'post_author'  => self::$user_id,
    48                 'post_date'    => self::$post_date,
    49                 '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.',
    50                 'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    51             )
    52         );
     45        for ( $i = 1; $i <= $count; $i++ ) {
     46            self::$posts[] = $factory->post->create(
     47                array(
     48                    'post_author'  => self::$user_id,
     49                    // Separate post dates 5 seconds apart.
     50                    'post_date'    => gmdate( 'Y-m-d H:i:s', self::$post_date + ( 5 * $i ) ),
     51                    '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.',
     52                    'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
     53                )
     54            );
     55        }
    5356
    5457        // Assign a category to those posts
     
    397400        $this->assertTrue( have_posts() );
    398401
     402
    399403        // Check to see if we have the expected XML output from the feed template.
    400404        $feed = $this->do_rss2();
     
    464468        $this->assertEquals( 1, count( $rss ) );
    465469    }
     470
     471    /**
     472     * Test <rss> element has correct last build date.
     473     *
     474     * @ticket 4575
     475     *
     476     * @dataProvider data_test_get_last_build_date
     477     */
     478    public function test_get_last_build_date( $url, $element ) {
     479        $this->go_to( $url );
     480        $feed = $this->do_rss2();
     481        $xml  = xml_to_array( $feed );
     482
     483        // Get the <rss> child element of <xml>.
     484        $rss             = xml_find( $xml, $element );
     485        $last_build_date = $rss[0]['child'][0]['child'][4]['content'];
     486        $this->assertEquals( strtotime( get_last_build_date() ), strtotime( $last_build_date ) );
     487    }
     488
     489
     490    public function data_test_get_last_build_date() {
     491        return array(
     492            array( '/?feed=rss2', 'rss' ),
     493            array( '/?feed=commentsrss2', 'rss' ),
     494        );
     495
     496    }
    466497}
Note: See TracChangeset for help on using the changeset viewer.