Skip to content

Commit 2077d49

Browse files
authored
Fix update_unavailable_reason leaking across rows in plugin and theme list (#552)
1 parent 8b288e9 commit 2077d49

4 files changed

Lines changed: 124 additions & 2 deletions

File tree

‎features/plugin.feature‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,61 @@ Feature: Manage WordPress plugins
11311131
"""
11321132
Warning: example: This update requires PHP version 100
11331133
"""
1134+
1135+
@require-wp-4.0
1136+
Scenario: The unavailable reason of one plugin does not leak into other plugins
1137+
Given a WP install
1138+
And a wp-content/plugins/aaa-example/aaa-example.php file:
1139+
"""
1140+
<?php
1141+
/**
1142+
* Plugin Name: AAA Example Plugin
1143+
* Version: 1.0.0
1144+
* Requires at least: 3.7
1145+
* Tested up to: 6.7
1146+
"""
1147+
And a wp-content/plugins/zzz-example/zzz-example.php file:
1148+
"""
1149+
<?php
1150+
/**
1151+
* Plugin Name: ZZZ Example Plugin
1152+
* Version: 1.0.0
1153+
* Requires at least: 3.7
1154+
* Tested up to: 6.7
1155+
"""
1156+
And that HTTP requests to https://api.wordpress.org/plugins/update-check/1.1/ will respond with:
1157+
"""
1158+
HTTP/1.1 200 OK
1159+
1160+
{
1161+
"plugins": {
1162+
"aaa-example/aaa-example.php": {
1163+
"id": "w.org/plugins/aaa-example",
1164+
"slug": "aaa-example",
1165+
"plugin": "aaa-example/aaa-example.php",
1166+
"new_version": "2.0.0",
1167+
"requires": "3.7",
1168+
"tested": "6.6",
1169+
"requires_php": "100",
1170+
"requires_plugins": [],
1171+
"compatibility": []
1172+
}
1173+
},
1174+
"translations": [],
1175+
"no_update": []
1176+
}
1177+
"""
1178+
1179+
When I run `wp plugin list --fields=name,update,update_unavailable_reason --format=csv`
1180+
Then STDOUT should contain:
1181+
"""
1182+
aaa-example,unavailable,"This update requires PHP version 100
1183+
"""
1184+
And STDOUT should contain:
1185+
"""
1186+
zzz-example,none,
1187+
"""
1188+
And STDOUT should not contain:
1189+
"""
1190+
zzz-example,none,"
1191+
"""

‎features/theme.feature‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,64 @@ Feature: Manage WordPress themes
792792
Warning: example: This update requires PHP version 100
793793
"""
794794

795+
Scenario: The unavailable reason of one theme does not leak into other themes
796+
Given a WP install
797+
And a wp-content/themes/aaa-example/style.css file:
798+
"""
799+
/*
800+
Theme Name: aaa-example
801+
Version: 1.0.0
802+
*/
803+
"""
804+
And a wp-content/themes/aaa-example/index.php file:
805+
"""
806+
<?php
807+
// Silence is golden.
808+
"""
809+
And a wp-content/themes/zzz-example/style.css file:
810+
"""
811+
/*
812+
Theme Name: zzz-example
813+
Version: 1.0.0
814+
*/
815+
"""
816+
And a wp-content/themes/zzz-example/index.php file:
817+
"""
818+
<?php
819+
// Silence is golden.
820+
"""
821+
And that HTTP requests to https://api.wordpress.org/themes/update-check/1.1/ will respond with:
822+
"""
823+
HTTP/1.1 200 OK
824+
825+
{
826+
"themes": {
827+
"aaa-example": {
828+
"theme": "aaa-example",
829+
"new_version": "2.0.0",
830+
"requires": "3.7",
831+
"requires_php": "100"
832+
}
833+
},
834+
"translations": [],
835+
"no_update": []
836+
}
837+
"""
838+
839+
When I run `wp theme list --fields=name,update,update_unavailable_reason --format=csv`
840+
Then STDOUT should contain:
841+
"""
842+
aaa-example,unavailable,"This update requires PHP version 100
843+
"""
844+
And STDOUT should contain:
845+
"""
846+
zzz-example,none,
847+
"""
848+
And STDOUT should not contain:
849+
"""
850+
zzz-example,none,"
851+
"""
852+
795853
@require-wp-5.9
796854
Scenario: Check theme type field for block themes
797855
Given a WP install

‎src/Plugin_Command.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,9 @@ protected function get_item_list() {
987987
// filter out plugins based on PHP requirements -- so we must do that here
988988
$compatible_php = empty( $requires_php ) || version_compare( PHP_VERSION, $requires_php, '>=' );
989989

990+
// Reset for each plugin so a previous plugin's reason does not leak into this row.
991+
$update_unavailable_reason = '';
992+
990993
if ( ! $compatible_php ) {
991994
$update = 'unavailable';
992995

@@ -1030,7 +1033,7 @@ protected function get_item_list() {
10301033
'wporg_status' => $wporg_info['status'],
10311034
'wporg_last_updated' => $wporg_info['last_updated'],
10321035
'recently_active' => in_array( $file, array_keys( $recently_active ), true ),
1033-
'update_unavailable_reason' => isset( $update_unavailable_reason ) ? $update_unavailable_reason : '',
1036+
'update_unavailable_reason' => $update_unavailable_reason,
10341037
];
10351038

10361039
if ( $this->check_headers['tested_up_to'] ) {

‎src/WP_CLI/ParseThemeNameInput.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ private function get_all_themes() {
103103
$compatible_php = empty( $requires_php ) || version_compare( PHP_VERSION, $requires_php, '>=' );
104104
$compatible_wp = empty( $requires ) || version_compare( $wp_version, $requires, '>=' );
105105

106+
// Reset for each theme so a previous theme's reason does not leak into this row.
107+
$update_unavailable_reason = '';
108+
106109
if ( ! $compatible_php ) {
107110
$update = 'unavailable';
108111

@@ -155,7 +158,7 @@ private function get_all_themes() {
155158
'auto_update_indicated' => $auto_update_indicated,
156159
'requires' => $requires,
157160
'requires_php' => $requires_php,
158-
'update_unavailable_reason' => isset( $update_unavailable_reason ) ? $update_unavailable_reason : '',
161+
'update_unavailable_reason' => $update_unavailable_reason,
159162
'type' => $theme_type,
160163
];
161164

0 commit comments

Comments
 (0)