#39141 closed defect (bug) (fixed)
RSS feeds have incorrect lastBuildDate when using alternate languages
Reported by: | __jester | Owned by: | dd32 |
---|---|---|---|
Milestone: | 4.7.1 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Feeds | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
When setting my site in English, the RSS feed says:
<lastBuildDate>Wed, 30 Nov 2016 15:47:34 +0000</lastBuildDate>
But when I set it up in Dutch, it says:
<lastBuildDate>wo, 30 nov 2016 15:47:34 +0000</lastBuildDate>
This date should be a valid RFC date. Otherwise feed validators won't validate the feed.
Possible fix:
<lastBuildDate><?php date = get_lastpostmodified( 'GMT' ); echo $date ? mysql2date( 'D, d M Y H:i:s +0000', $date, false ) : date( 'D, d M Y H:i:s +0000' }}}</lastBuildDate>
Attachments (2)
Change History (22)
#3
@
8 years ago
Yes this was working differently in 4.6.1. It happens in the mysql2date
function. The date get actually gets translated if you don't set the $translate
parameter to false
#4
@
8 years ago
In WP 4.6.1 is worked like this:
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
#5
@
8 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 4.7.1
You're right, thanks. Looks like the third parameter got lost in some files in [38925] or has always been. Seems like it has always been missing in wp-includes/feed-rss2-comments.php
.
#7
@
8 years ago
The translation doesn't seem to effect Atom feeds due to the 'Z' format, but I went ahead and added the parameter anyways for consistency.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
#9
@
8 years ago
While this is not fixed in the core yet, you can use this code to make the RSS feeds validate again:
<?php add_filter('date_i18n','rssfeeds_date_donttranslate',10,4); function rssfeeds_date_donttranslate($j, $req_format, $i, $gmt){ if(is_feed()) return date($req_format); else return $j; }
#10
@
8 years ago
- Keywords needs-unit-tests added
Unit tests would be helpful here, to avoid this bug being re-introduced in the future.
#11
@
8 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
39141.unit-test.diff is an attempt at a unit test for this, unfortunately we have very little feed coverage right now. Testing the non-RSS2 feeds doesn't have much benefit either, as the date formats don't have any translated tokens.
If someone would like to extend 39141.unit-test.diff to cover the RSS2 Comments feed, please do.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
#13
@
8 years ago
Having taken another look at this, feed-rss2.php
is the only RSS feed which actually had a date format which has any translatable components in it in the first place. Still makes sense to mark all of them as $translate = false
though.
Digging into it further, the format D, d M Y H:i:s +0000
is the same as r
- and as we don't need to translate it here we could probably just switch it back to that. It was changed back in r1041 (later follow up commits marked it as no-translate, this would be at least the 3rd time it's lost the no-translate flag).
#14
@
8 years ago
- Owner set to dd32
- Resolution set to fixed
- Status changed from new to closed
In 39613:
#17
@
8 years ago
- Keywords needs-testing removed
As only the main RSS feed was affected, I only backported that specific change to 4.7.1.
For 4.8+ I've added it for all feeds, and then converted it to the r
date format anyway.
Was this working before? Doesn't seem like we changed the date format here. See #38027