Skip to content

Commit b7d6b58

Browse files
committed
Mark tested_up_to as optional
1 parent b207e08 commit b7d6b58

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

features/plugin.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,23 @@ Feature: Manage WordPress plugins
746746
License URI: https://www.gnu.org/licenses/gpl-2.0.html
747747
"""
748748
And I run `wp plugin activate foo`
749+
750+
When I run `wp plugin list`
751+
Then STDOUT should be a table containing rows:
752+
| name | status | update | version | update_version | auto_update |
753+
| foo | active | none | | | off |
754+
749755
When I run `wp plugin list --fields=name,tested_up_to`
750756
Then STDOUT should be a table containing rows:
751757
| name | tested_up_to |
752758
| foo | 3.4 |
753759

760+
And I run `wp plugin list --name=foo --field=tested_up_to`
761+
Then STDOUT should be:
762+
"""
763+
3.4
764+
"""
765+
754766
Scenario: Listing plugins should include tested_up_to from the 'tested' header
755767
Given a WP install
756768
And a wp-content/plugins/foo/foo.php file:
@@ -776,7 +788,19 @@ Feature: Manage WordPress plugins
776788
License URI: https://www.gnu.org/licenses/gpl-2.0.html
777789
"""
778790
And I run `wp plugin activate foo`
791+
792+
When I run `wp plugin list`
793+
Then STDOUT should be a table containing rows:
794+
| name | status | update | version | update_version | auto_update |
795+
| foo | active | none | | | off |
796+
779797
When I run `wp plugin list --fields=name,tested_up_to`
780798
Then STDOUT should be a table containing rows:
781799
| name | tested_up_to |
782800
| foo | 5.5 |
801+
802+
And I run `wp plugin list --name=foo --field=tested_up_to`
803+
Then STDOUT should be:
804+
"""
805+
5.5
806+
"""

src/Plugin_Command.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
5252
'status' => false,
5353
'last_updated' => false,
5454
];
55+
protected $check_headers = [
56+
'tested_up_to' => false,
57+
];
5558

5659
protected $obj_fields = array(
5760
'name',
@@ -743,12 +746,14 @@ protected function get_item_list() {
743746
'wporg_last_updated' => $wporg_info['last_updated'],
744747
];
745748

746-
// Include information from the plugin readme.txt headers.
747-
$plugin_readme = WP_PLUGIN_DIR . '/' . $name . '/readme.txt';
749+
if ( $this->check_headers['tested_up_to'] ) {
750+
// Include information from the plugin readme.txt headers.
751+
$plugin_readme = WP_PLUGIN_DIR . '/' . $name . '/readme.txt';
748752

749-
if ( file_exists( $plugin_readme ) ) {
750-
$readme_parser = new Parser( $plugin_readme );
751-
$items[ $file ]['tested_up_to'] = $readme_parser->tested ? $readme_parser->tested : '';
753+
if ( file_exists( $plugin_readme ) ) {
754+
$readme_parser = new Parser( $plugin_readme );
755+
$items[ $file ]['tested_up_to'] = $readme_parser->tested ? $readme_parser->tested : '';
756+
}
752757
}
753758

754759
if ( null === $update_info ) {
@@ -1263,7 +1268,6 @@ public function delete( $args, $assoc_args = array() ) {
12631268
* * version
12641269
* * update_version
12651270
* * auto_update
1266-
* * tested_up_to
12671271
*
12681272
* These fields are optionally available:
12691273
*
@@ -1273,6 +1277,7 @@ public function delete( $args, $assoc_args = array() ) {
12731277
* * description
12741278
* * file
12751279
* * author
1280+
* * tested_up_to
12761281
* * wporg_status
12771282
* * wporg_last_updated
12781283
*
@@ -1316,6 +1321,8 @@ public function list_( $_, $assoc_args ) {
13161321
$fields = explode( ',', $fields );
13171322
$this->check_wporg['status'] = in_array( 'wporg_status', $fields, true );
13181323
$this->check_wporg['last_updated'] = in_array( 'wporg_last_updated', $fields, true );
1324+
1325+
$this->check_headers['tested_up_to'] = in_array( 'tested_up_to', $fields, true );
13191326
}
13201327

13211328
$field = Utils\get_flag_value( $assoc_args, 'field' );
@@ -1325,6 +1332,8 @@ public function list_( $_, $assoc_args ) {
13251332
$this->check_wporg['last_updated'] = true;
13261333
}
13271334

1335+
$this->check_headers['tested_up_to'] = 'tested_up_to' === $field || $this->check_headers['tested_up_to'];
1336+
13281337
parent::_list( $_, $assoc_args );
13291338
}
13301339

0 commit comments

Comments
 (0)