Skip to content

Commit 8b288e9

Browse files
authored
Fix wporg_last_updated always being empty for active plugins (#547)
1 parent 7e35f62 commit 8b288e9

2 files changed

Lines changed: 174 additions & 12 deletions

File tree

‎features/plugin-list-wporg-status.feature‎

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,145 @@ Feature: Check the status of plugins on WordPress.org
111111
| no-longer-in-directory | closed | 2017-11-13 |
112112
| never-wporg | | |
113113

114+
@require-wp-5.2
115+
Scenario: The wp.org last updated date for an active plugin does not depend on a second, rate-limited request
116+
Given a WP install
117+
And I run `wp plugin install wordpress-importer --version=0.5 --force`
118+
And that HTTP requests to https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request%5Blocale%5D=en_US&request%5Bslug%5D=wordpress-importer will respond with:
119+
"""
120+
HTTP/1.1 200
121+
Content-Type: application/json
122+
123+
{
124+
"name": "WordPress Importer",
125+
"slug": "wordpress-importer",
126+
"last_updated": "2025-09-26 9:07pm GMT"
127+
}
128+
"""
129+
# plugins.trac.wordpress.org is known to rate-limit this scrape (HTTP 429), with no
130+
# pubDate in the response body. wporg_last_updated must still resolve correctly for an
131+
# active plugin, because the date is meant to come from the plugin-info API response
132+
# above, not from a second request to trac.
133+
And that HTTP requests to https://plugins.trac.wordpress.org/log/wordpress-importer/?limit=1&mode=stop_on_copy&format=rss will respond with:
134+
"""
135+
HTTP/1.1 429
136+
Content-Type: text/html
137+
138+
<html><body>429 Too Many Requests</body></html>
139+
"""
140+
141+
When I run `wp plugin list --fields=name,wporg_status,wporg_last_updated`
142+
Then STDOUT should be a table containing rows:
143+
| name | wporg_status | wporg_last_updated |
144+
| wordpress-importer | active | 2025-09-26 |
145+
146+
@require-wp-5.2
147+
Scenario: The wp.org last updated date falls back to the trac log when the plugin-info API omits it
148+
Given a WP install
149+
And I run `wp plugin install wordpress-importer --version=0.5 --force`
150+
And that HTTP requests to https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request%5Blocale%5D=en_US&request%5Bslug%5D=wordpress-importer will respond with:
151+
"""
152+
HTTP/1.1 200
153+
Content-Type: application/json
154+
155+
{
156+
"name": "WordPress Importer",
157+
"slug": "wordpress-importer"
158+
}
159+
"""
160+
And that HTTP requests to https://plugins.trac.wordpress.org/log/wordpress-importer/?limit=1&mode=stop_on_copy&format=rss will respond with:
161+
"""
162+
HTTP/1.1 200
163+
Content-Type: application/rss+xml;charset=utf-8
164+
165+
<?xml version="1.0"?>
166+
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
167+
<channel>
168+
<item>
169+
<pubDate>Fri, 26 Sep 2025 21:07:26 GMT</pubDate>
170+
</item>
171+
</channel>
172+
</rss>
173+
"""
174+
175+
When I run `wp plugin list --fields=name,wporg_status,wporg_last_updated`
176+
Then STDOUT should be a table containing rows:
177+
| name | wporg_status | wporg_last_updated |
178+
| wordpress-importer | active | 2025-09-26 |
179+
180+
@require-wp-5.2
181+
Scenario: The wp.org last updated date falls back to the trac log when the plugin-info API date can't be parsed
182+
Given a WP install
183+
And I run `wp plugin install wordpress-importer --version=0.5 --force`
184+
And that HTTP requests to https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request%5Blocale%5D=en_US&request%5Bslug%5D=wordpress-importer will respond with:
185+
"""
186+
HTTP/1.1 200
187+
Content-Type: application/json
188+
189+
{
190+
"name": "WordPress Importer",
191+
"slug": "wordpress-importer",
192+
"last_updated": "not a date"
193+
}
194+
"""
195+
And that HTTP requests to https://plugins.trac.wordpress.org/log/wordpress-importer/?limit=1&mode=stop_on_copy&format=rss will respond with:
196+
"""
197+
HTTP/1.1 200
198+
Content-Type: application/rss+xml;charset=utf-8
199+
200+
<?xml version="1.0"?>
201+
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
202+
<channel>
203+
<item>
204+
<pubDate>Fri, 26 Sep 2025 21:07:26 GMT</pubDate>
205+
</item>
206+
</channel>
207+
</rss>
208+
"""
209+
210+
# An unparsable API date must not be rendered as today's date, nor stop the
211+
# trac log from being consulted as the fallback source of the date.
212+
When I run `wp plugin list --fields=name,wporg_status,wporg_last_updated`
213+
Then STDOUT should be a table containing rows:
214+
| name | wporg_status | wporg_last_updated |
215+
| wordpress-importer | active | 2025-09-26 |
216+
217+
@require-wp-5.2
218+
Scenario: The wp.org last updated date stays empty when the trac log pubDate can't be parsed
219+
Given a WP install
220+
And I run `wp plugin install wordpress-importer --version=0.5 --force`
221+
And that HTTP requests to https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request%5Blocale%5D=en_US&request%5Bslug%5D=wordpress-importer will respond with:
222+
"""
223+
HTTP/1.1 200
224+
Content-Type: application/json
225+
226+
{
227+
"name": "WordPress Importer",
228+
"slug": "wordpress-importer"
229+
}
230+
"""
231+
And that HTTP requests to https://plugins.trac.wordpress.org/log/wordpress-importer/?limit=1&mode=stop_on_copy&format=rss will respond with:
232+
"""
233+
HTTP/1.1 200
234+
Content-Type: application/rss+xml;charset=utf-8
235+
236+
<?xml version="1.0"?>
237+
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
238+
<channel>
239+
<item>
240+
<pubDate>not a date</pubDate>
241+
</item>
242+
</channel>
243+
</rss>
244+
"""
245+
246+
# With no usable date from either source, wporg_last_updated must stay empty
247+
# rather than being rendered as today's date.
248+
When I run `wp plugin list --fields=name,wporg_status,wporg_last_updated`
249+
Then STDOUT should be a table containing rows:
250+
| name | wporg_status | wporg_last_updated |
251+
| wordpress-importer | active | |
252+
114253
@less-than-wp-5.3
115254
Scenario: The wp.org last updated date is still rendered on WordPress < 5.3
116255
Given a WP install

‎src/Plugin_Command.php‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,17 @@ protected function get_wporg_data( $plugin_name ) {
11281128
if ( ! $this->check_wporg['last_updated'] ) {
11291129
return $data; // The plugin is active on .org, but we don't need the date.
11301130
}
1131+
// The plugins API already reports when the plugin was last updated, so use
1132+
// that instead of also scraping the trac log, which is rate-limited and
1133+
// otherwise unnecessary here. If the value can't be parsed, fall through
1134+
// to the trac log below rather than defaulting to today's date.
1135+
if ( ! empty( $plugin_data['last_updated'] ) && is_string( $plugin_data['last_updated'] ) ) {
1136+
$pub_date = strtotime( $plugin_data['last_updated'] );
1137+
if ( false !== $pub_date ) {
1138+
$data['last_updated'] = $this->format_wporg_last_updated( $pub_date );
1139+
return $data;
1140+
}
1141+
}
11311142
}
11321143
// Just because the plugin is not in the api, does not mean it was never on .org.
11331144
}
@@ -1152,18 +1163,9 @@ protected function get_wporg_data( $plugin_name ) {
11521163
if ( false !== $xml ) {
11531164
$xml_pub_date = $xml->xpath( '//pubDate' );
11541165
if ( $xml_pub_date ) {
1155-
$pub_date = strtotime( $xml_pub_date[0] ) ?: null;
1156-
1157-
if ( function_exists( 'wp_date' ) ) {
1158-
$data['last_updated'] = wp_date( 'Y-m-d', $pub_date );
1159-
} else {
1160-
// wp_date() is WordPress 5.3+. get_date_from_gmt() renders in the site
1161-
// timezone the same way, without date_i18n()'s pre-5.3 contract of
1162-
// expecting a timestamp that already has the offset added to it.
1163-
$data['last_updated'] = get_date_from_gmt(
1164-
gmdate( 'Y-m-d H:i:s', $pub_date ?? time() ),
1165-
'Y-m-d'
1166-
);
1166+
$pub_date = strtotime( $xml_pub_date[0] );
1167+
if ( false !== $pub_date ) {
1168+
$data['last_updated'] = $this->format_wporg_last_updated( $pub_date );
11671169
}
11681170
}
11691171
}
@@ -1172,6 +1174,27 @@ protected function get_wporg_data( $plugin_name ) {
11721174
return $data;
11731175
}
11741176

1177+
/**
1178+
* Formats a wp.org publish date as a `Y-m-d` string in the site's configured timezone.
1179+
*
1180+
* @param int $pub_date Unix timestamp.
1181+
*
1182+
* @return string|false
1183+
*/
1184+
private function format_wporg_last_updated( $pub_date ) {
1185+
if ( function_exists( 'wp_date' ) ) {
1186+
return wp_date( 'Y-m-d', $pub_date );
1187+
}
1188+
1189+
// wp_date() is WordPress 5.3+. get_date_from_gmt() renders in the site
1190+
// timezone the same way, without date_i18n()'s pre-5.3 contract of
1191+
// expecting a timestamp that already has the offset added to it.
1192+
return get_date_from_gmt(
1193+
gmdate( 'Y-m-d H:i:s', $pub_date ),
1194+
'Y-m-d'
1195+
);
1196+
}
1197+
11751198
protected function filter_item_list( $items, $args ) {
11761199
$basenames = wp_list_pluck( $this->fetcher->get_many( $args ), 'file' );
11771200
return Utils\pick_fields( $items, $basenames );

0 commit comments

Comments
 (0)