WordPress.org

Make WordPress Core

Changeset 32765


Ignore:
Timestamp:
06/14/2015 06:36:14 PM (4 years ago)
Author:
jorbin
Message:

Improve lastBuildDate timestamp in rss feeds

RSS feed timestamps should reflect the actual timestamps for those RSS feeds rather than the generic timestamp for all posts and all comments.

Props stevenkword.
Fixes #4575.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/feed-rss2-comments.php

    r32468 r32765  
    4444    <link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link>
    4545    <description><?php bloginfo_rss("description") ?></description>
    46     <lastBuildDate><?php echo mysql2date('r', get_lastcommentmodified('GMT')); ?></lastBuildDate>
     46    <lastBuildDate><?php echo mysql2date('r', get_last_build_date_feed(), false ); ?></lastBuildDate>
    4747    <sy:updatePeriod><?php
    4848        /** This filter is documented in wp-includes/feed-rss2.php */
  • trunk/src/wp-includes/feed-rss2.php

    r32468 r32765  
    4343    <link><?php bloginfo_rss('url') ?></link>
    4444    <description><?php bloginfo_rss("description") ?></description>
    45     <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
     45    <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_last_build_date_feed(), false); ?></lastBuildDate>
    4646    <language><?php bloginfo_rss( 'language' ); ?></language>
    4747    <sy:updatePeriod><?php
  • trunk/src/wp-includes/feed.php

    r32469 r32765  
    8686    $default_feed = apply_filters( 'default_feed', 'rss2' );
    8787    return 'rss' == $default_feed ? 'rss2' : $default_feed;
     88}
     89
     90/**
     91 * Get the timestamp of the most recently modified post from WP_Query
     92 *
     93 * If viewing a comment feed, the date of the most recently modified
     94 * comment will be returned.
     95 *
     96 * @since 4.3.0
     97 *
     98 * @return string Date ('Y-m-d H:i:s' for use with mysql2date() )
     99 */
     100function get_last_build_date_feed() {
     101    global $wp_query, $wpdb;
     102
     103    if ( $wp_query->have_posts() ) {
     104        $post_ids = array();
     105        foreach( $wp_query->posts as $post ) {
     106            $post_ids[] = $post->ID;
     107            $post_times[] = $post->post_modified_gmt;
     108        }
     109        $postids = implode( "','", $post_ids );
     110        $max_post_time = max( $post_times );
     111
     112        if( $wp_query->is_comment_feed() ) {
     113            $max_comment_time = $wpdb->get_var( $wpdb->prepare( "SELECT MAX(comment_date_gmt) FROM $wpdb->comments WHERE comment_post_ID IN ('%s') AND comment_approved = '1'", $postids ) );
     114
     115            return max( $max_post_time, $max_comment_time );
     116        }
     117        return $max_post_time;
     118    }
     119
     120    // Fallback to last time any post was modified or published.
     121    return get_lastpostmodified( 'GMT' );
    88122}
    89123
Note: See TracChangeset for help on using the changeset viewer.