WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#16473 closed defect (bug) (fixed)

RSS Widget always returns current date when 'Display item date' is checked

Reported by: zipper1976 Owned by:
Milestone: 3.1 Priority: normal
Severity: minor Version: 3.0.4
Component: Widgets Keywords: pubDate RSS
Focuses: Cc:

Description

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.
  1. 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. ;-)

Change History (6)

comment:1 follow-up: @SergeyBiryukov5 years ago

Probably fixed in [16566]. Please check current trunk.

comment:2 in reply to: ↑ 1 @zipper19765 years ago

Replying to SergeyBiryukov:

Probably fixed in [16566]. Please check current trunk.

Thanks for the reply. I'm new here so I don't know how to "check current trunk". Can you point me to a link where I can check this? What version is the "current trunk"? Something > 3.0.4?

comment:3 follow-up: @SergeyBiryukov5 years ago

Yeah, currently it's 3.1-RC3-17409. You can download the latest nightly build from http://wordpress.org/nightly-builds/wordpress-latest.zip or perform SVN checkout from http://core.svn.wordpress.org/trunk/.

comment:4 in reply to: ↑ 3 @zipper19765 years ago

Replying to SergeyBiryukov:

Yeah, currently it's 3.1-RC3-17409. You can download the latest nightly build from http://wordpress.org/nightly-builds/wordpress-latest.zip or perform SVN checkout from http://core.svn.wordpress.org/trunk/.

OK. I dl'ed and installed the latest nightly build and tested the RSS widget. It appears to be working correctly in this build.

Will someone update this ticket accordingly? Or is that my job?

comment:5 @SergeyBiryukov5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

comment:6 @ocean905 years ago

  • Milestone changed from Awaiting Review to 3.1
Note: See TracTickets for help on using tickets.