Feeds: improve structure and naming of feed build date helper function.

Simplify overall code structure by passing the required format to the helper function.
Clarify functionality by renaming `get_last_build_date` to `get_feed_build_date`.

Props pento, spacedmonkey.
Fixes #4575.



git-svn-id: https://develop.svn.wordpress.org/trunk@45247 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein 2019-04-18 17:07:07 +00:00
parent 1eb665b20c
commit 9e3c57c2ff
8 changed files with 35 additions and 47 deletions

View File

@ -43,8 +43,7 @@ do_action( 'rss_tag_pre', 'atom-comments' );
</title>
<subtitle type="text"><?php bloginfo_rss( 'description' ); ?></subtitle>
<?php $date = get_last_build_date(); ?>
<updated><?php echo $date ? mysql2date( 'Y-m-d\TH:i:s\Z', $date, false ) : date( 'Y-m-d\TH:i:s\Z' ); ?></updated>
<updated><?php echo get_feed_build_date( 'Y-m-d\TH:i:s\Z' ); ?></updated>
<?php if ( is_singular() ) { ?>
<link rel="alternate" type="<?php bloginfo_rss( 'html_type' ); ?>" href="<?php comments_link_feed(); ?>" />

View File

@ -30,8 +30,7 @@ do_action( 'rss_tag_pre', 'atom' );
<title type="text"><?php wp_title_rss(); ?></title>
<subtitle type="text"><?php bloginfo_rss( 'description' ); ?></subtitle>
<?php $date = get_last_build_date(); ?>
<updated><?php echo $date ? mysql2date( 'Y-m-d\TH:i:s\Z', $date, false ) : date( 'Y-m-d\TH:i:s\Z' ); ?></updated>
<updated><?php echo get_feed_build_date( 'Y-m-d\TH:i:s\Z' ); ?></updated>
<link rel="alternate" type="<?php bloginfo_rss( 'html_type' ); ?>" href="<?php bloginfo_rss( 'url' ); ?>" />
<id><?php bloginfo( 'atom_url' ); ?></id>

View File

@ -33,12 +33,7 @@ do_action( 'rss_tag_pre', 'rdf' );
<title><?php wp_title_rss(); ?></title>
<link><?php bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description>
<dc:date>
<?php
$date = get_last_build_date();
echo $date ? mysql2date( 'Y-m-d\TH:i:s\Z', $date ) : date( 'Y-m-d\TH:i:s\Z' );
?>
</dc:date>
<dc:date><?php echo get_feed_build_date( 'Y-m-d\TH:i:s\Z' ); ?> </dc:date>
<sy:updatePeriod>
<?php
/** This filter is documented in wp-includes/feed-rss2.php */

View File

@ -14,12 +14,7 @@ echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>
<title><?php wp_title_rss(); ?></title>
<link><?php bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description>
<lastBuildDate>
<?php
$date = get_last_build_date();
echo $date ? mysql2date( 'D, d M Y H:i:s +0000', $date ) : date( 'D, d M Y H:i:s +0000' );
?>
</lastBuildDate>
<lastBuildDate><?php echo get_feed_build_date( 'D, d M Y H:i:s +0000' ); ?></lastBuildDate>
<docs>http://backend.userland.com/rss092</docs>
<language><?php bloginfo_rss( 'language' ); ?></language>

View File

@ -49,12 +49,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
$date = get_last_build_date();
echo $date ? mysql2date( 'r', $date, false ) : date( 'r' );
?>
</lastBuildDate>
<lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
<sy:updatePeriod>
<?php
/** This filter is documented in wp-includes/feed-rss2.php */

View File

@ -42,12 +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
$date = get_last_build_date();
echo $date ? mysql2date( 'r', $date, false ) : date( 'r' );
?>
</lastBuildDate>
<lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
<language><?php bloginfo_rss( 'language' ); ?></language>
<sy:updatePeriod>
<?php

View File

@ -638,18 +638,20 @@ function self_link() {
}
/*
* 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.
*
* @global WP_Query $wp_query The global WP_Query object.
*
* @since 5.2.0
*
* @return string The timestamp.
*/
function get_last_build_date() {
* Get the timestamp of the most recently modified post from WP_Query.
*
* If viewing a comment feed, the timestamp of the most recently modified
* comment will be returned.
*
* @global WP_Query $wp_query The global WP_Query object.
*
* @since 5.2.0
*
* @param string $format Format of the timestamp to return, passed to mysql2date.
*
* @return string The timestamp.
*/
function get_feed_build_date( $format ) {
global $wp_query;
if ( empty( $wp_query ) || ! $wp_query->have_posts() ) {
@ -670,16 +672,24 @@ function get_last_build_date() {
}
// Determine the maximum modified time.
$max_modified_time = max( $modified_times );
$max_modified_time = max(
array_map(
function ( $time ) use ( $format ) {
return mysql2date( $format, $time, false );
},
$modified_times
)
);
/**
* Filters the date the last post or comment in the query was modified.
*
* @since 5.2.0
*
* @param string $max_modified_times Date the last post or comment was modified in the query.
* @param string $max_modified_time Date the last post or comment was modified in the query.
* @param string $format The date format requested in get_feed_build_date.
*/
return apply_filters( 'get_last_build_date', $max_modified_time );
return apply_filters( 'get_feed_build_date', $max_modified_time, $format );
}
/**

View File

@ -472,9 +472,9 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase {
*
* @ticket 4575
*
* @dataProvider data_test_get_last_build_date
* @dataProvider data_test_get_feed_build_date
*/
public function test_get_last_build_date( $url, $element ) {
public function test_get_feed_build_date( $url, $element ) {
$this->go_to( $url );
$feed = $this->do_rss2();
$xml = xml_to_array( $feed );
@ -482,11 +482,11 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase {
// Get the <rss> child element of <xml>.
$rss = xml_find( $xml, $element );
$last_build_date = $rss[0]['child'][0]['child'][4]['content'];
$this->assertEquals( strtotime( get_last_build_date() ), strtotime( $last_build_date ) );
$this->assertEquals( strtotime( get_feed_build_date( 'r' ) ), strtotime( $last_build_date ) );
}
public function data_test_get_last_build_date() {
public function data_test_get_feed_build_date() {
return array(
array( '/?feed=rss2', 'rss' ),
array( '/?feed=commentsrss2', 'rss' ),