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.



Built from https://develop.svn.wordpress.org/trunk@32765


git-svn-id: http://core.svn.wordpress.org/trunk@32736 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2015-06-14 18:37:24 +00:00
parent df11970e18
commit cbb6f91a29
4 changed files with 37 additions and 3 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.
*

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-alpha-32764';
$wp_version = '4.3-alpha-32765';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.