[wp-trac] [WordPress Trac] #16473: RSS Widget always returns current date when 'Display item date' is checked
WordPress Trac
wp-trac at lists.automattic.com
Sun Feb 6 20:26:31 UTC 2011
#16473: RSS Widget always returns current date when 'Display item date' is checked
--------------------------+-----------------------------
Reporter: zipper1976 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Widgets | Version: 3.0.4
Severity: minor | Keywords: pubDate RSS
--------------------------+-----------------------------
See [http://zippersoftware.com/wp/] for an example of this bug.
Problem:
About line 837 in function wp_widget_rss_output (default-widgets.php) you
now have...
{{{
$date = '';
if ( $show_date ) {
$date = $item->get_date();
if ( $date ) {
if ( $date_stamp = strtotime( $date ) )
$date = ' <span class="rss-date">' . date_i18n( get_option(
'date_format' ), $date_stamp ) . '</span>';
else
$date = '';
}
}
}}}
There are two problems in this code...
1. It assumes strtotime returns 'false' for failure. Previous to PHP
5.1.0, this function would return -1 on failure.
2. If the pubDate ($date) contains one or more commas, strtotime will
fail. Some RSS feeds use commas in pubDate.
My solution:
{{{
$date = '';
if ( $show_date ) {
$date = $item->get_date();
if ( $date ) {
$date = str_replace( ",", "", $date );
if ((( $date_stamp = strtotime( $date )) != -1) && (( $date_stamp =
strtotime( $date )) != false ))
$date = ' <span class="rss-date">' . date_i18n( get_option(
'date_format' ), $date_stamp ) . '</span>';
else
$date = '';
}
}
}}}
This solution works with PHP versions prior to 5.1.0 and also strips
commas from the pubDate so strtotime won't fail for this reason.
Note: I will be applying this patch to default-widgets.php on the above
website in a couple of days, so if you need to see this bug in action
you'd better be quick. ;-)
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16473>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list