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.


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


git-svn-id: http://core.svn.wordpress.org/trunk@45056 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Adam Silverstein 2019-04-18 17:08:52 +00:00
parent 2d58638ba0
commit b287642342
8 changed files with 32 additions and 44 deletions

View File

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

View File

@ -33,12 +33,7 @@ do_action( 'rss_tag_pre', 'rdf' );
<title><?php wp_title_rss(); ?></title> <title><?php wp_title_rss(); ?></title>
<link><?php bloginfo_rss( 'url' ); ?></link> <link><?php bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description> <description><?php bloginfo_rss( 'description' ); ?></description>
<dc:date> <dc:date><?php echo get_feed_build_date( 'Y-m-d\TH:i:s\Z' ); ?> </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>
<sy:updatePeriod> <sy:updatePeriod>
<?php <?php
/** This filter is documented in wp-includes/feed-rss2.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> <title><?php wp_title_rss(); ?></title>
<link><?php bloginfo_rss( 'url' ); ?></link> <link><?php bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description> <description><?php bloginfo_rss( 'description' ); ?></description>
<lastBuildDate> <lastBuildDate><?php echo get_feed_build_date( 'D, d M Y H:i:s +0000' ); ?></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>
<docs>http://backend.userland.com/rss092</docs> <docs>http://backend.userland.com/rss092</docs>
<language><?php bloginfo_rss( 'language' ); ?></language> <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" /> <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php ( is_single() ) ? the_permalink_rss() : bloginfo_rss( 'url' ); ?></link> <link><?php ( is_single() ) ? the_permalink_rss() : bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description> <description><?php bloginfo_rss( 'description' ); ?></description>
<lastBuildDate> <lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
<?php
$date = get_last_build_date();
echo $date ? mysql2date( 'r', $date, false ) : date( 'r' );
?>
</lastBuildDate>
<sy:updatePeriod> <sy:updatePeriod>
<?php <?php
/** This filter is documented in wp-includes/feed-rss2.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" /> <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss( 'url' ); ?></link> <link><?php bloginfo_rss( 'url' ); ?></link>
<description><?php bloginfo_rss( 'description' ); ?></description> <description><?php bloginfo_rss( 'description' ); ?></description>
<lastBuildDate> <lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
<?php
$date = get_last_build_date();
echo $date ? mysql2date( 'r', $date, false ) : date( 'r' );
?>
</lastBuildDate>
<language><?php bloginfo_rss( 'language' ); ?></language> <language><?php bloginfo_rss( 'language' ); ?></language>
<sy:updatePeriod> <sy:updatePeriod>
<?php <?php

View File

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

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.2-beta3-45246'; $wp_version = '5.2-beta3-45247';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.