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.




git-svn-id: https://develop.svn.wordpress.org/trunk@32765 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Aaron Jorbin 2015-06-14 18:36:14 +00:00
parent c6bf4b951b
commit caf041d76e
3 changed files with 36 additions and 2 deletions

View File

@ -43,7 +43,7 @@ do_action( 'rss_tag_pre', 'rss2-comments' );
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link>
<description><?php bloginfo_rss("description") ?></description>
<lastBuildDate><?php echo mysql2date('r', get_lastcommentmodified('GMT')); ?></lastBuildDate>
<lastBuildDate><?php echo mysql2date('r', get_last_build_date_feed(), false ); ?></lastBuildDate>
<sy:updatePeriod><?php
/** This filter is documented in wp-includes/feed-rss2.php */
echo apply_filters( 'rss_update_period', 'hourly' );

View File

@ -42,7 +42,7 @@ do_action( 'rss_tag_pre', 'rss2' );
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss("description") ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_last_build_date_feed(), false); ?></lastBuildDate>
<language><?php bloginfo_rss( 'language' ); ?></language>
<sy:updatePeriod><?php
$duration = 'hourly';

View File

@ -87,6 +87,40 @@ function get_default_feed() {
return 'rss' == $default_feed ? 'rss2' : $default_feed;
}
/**
* Get the timestamp of the most recently modified post from WP_Query
*
* If viewing a comment feed, the date of the most recently modified
* comment will be returned.
*
* @since 4.3.0
*
* @return string Date ('Y-m-d H:i:s' for use with mysql2date() )
*/
function get_last_build_date_feed() {
global $wp_query, $wpdb;
if ( $wp_query->have_posts() ) {
$post_ids = array();
foreach( $wp_query->posts as $post ) {
$post_ids[] = $post->ID;
$post_times[] = $post->post_modified_gmt;
}
$postids = implode( "','", $post_ids );
$max_post_time = max( $post_times );
if( $wp_query->is_comment_feed() ) {
$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 ) );
return max( $max_post_time, $max_comment_time );
}
return $max_post_time;
}
// Fallback to last time any post was modified or published.
return get_lastpostmodified( 'GMT' );
}
/**
* Retrieve the blog title for the feed title.
*