[wp-trac] [WordPress Trac] #4575: Add functions to return the last-modified timestamp of a category/tag
WordPress Trac
noreply at wordpress.org
Tue Apr 16 02:25:14 UTC 2019
#4575: Add functions to return the last-modified timestamp of a category/tag
-----------------------------------------+------------------------------
Reporter: delusions | Owner: adamsilverstein
Type: enhancement | Status: reopened
Priority: normal | Milestone: 5.2
Component: Feeds | Version: 2.2.1
Severity: normal | Resolution:
Keywords: dev-feedback needs-dev-note | Focuses: template
-----------------------------------------+------------------------------
Changes (by pento):
* keywords: has-patch has-unit-tests commit early => dev-feedback needs-
dev-note
* status: closed => reopened
* resolution: fixed =>
Comment:
I have some feedback on [44948]. 🙂
It seems like all of the places where `get_last_build_date()` is called
could be simplified if it accepted a formatting string parameter. For
example, `feed-rss2.php` would go from
{{{#!php
<lastBuildDate>
<?php
$date = get_last_build_date();
echo $date ? mysql2date( 'r', $date, false ) : date( 'r'
);
?>
</lastBuildDate>
}}}
to
{{{#!php
<lastBuildDate><?php echo get_last_build_date( 'r' );
?></lastBuildDate>
}}}
This same pattern is repeated in all feed templates.
When `get_last_build_date()` returns the value of `get_lastpostmodified(
'GMT' )`, it doesn't go through the `get_last_build_date` filter.
Using `max()` for the string comparison is cute, but confusing, as
@adamsilverstein ran into earlier in the thread. Relying on string sorting
behaviour for sorting dates is also a recipe for subtle bugs. I would be
inclined to explicitly sort by timestamp, instead:
{{{#!php
// Determine the maximum modified time.
$max_modified_time = max(
array_map(
function ( $time ) {
return mysql2date( 'G', $time, false );
},
$modified_times
)
);
}}}
The `get_last_build_date()` name is very generic, it doesn't indicate that
this is a feed template function. Perhaps `get_feed_build_date()`, or
something of that nature would work better.
This change also needs a dev-note, particularly as it includes back compat
breaks.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/4575#comment:89>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list