From 0a7602b799192977afc3eba36753ff123122282b Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 11 Apr 2024 12:02:57 +0545 Subject: [PATCH 1/5] Show RequiresPlugins if available in plugin get command --- src/Plugin_Command.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 169acbce..586f05b2 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -961,6 +961,10 @@ public function get( $args, $assoc_args ) { 'status' => $this->get_status( $file ), ]; + if ( isset( $plugin_data['RequiresPlugins'] ) && ! empty( $plugin_data['RequiresPlugins'] ) ) { + $plugin_obj->requires_plugins = $plugin_data['RequiresPlugins']; + } + if ( empty( $assoc_args['fields'] ) ) { $plugin_array = get_object_vars( $plugin_obj ); $assoc_args['fields'] = array_keys( $plugin_array ); From e491918bd834fcc3c996a4ca9842adffff6c1234 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 11 Apr 2024 12:49:50 +0545 Subject: [PATCH 2/5] Add feature test for plugin get command --- features/plugin-get.feature | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 features/plugin-get.feature diff --git a/features/plugin-get.feature b/features/plugin-get.feature new file mode 100644 index 00000000..403bbb64 --- /dev/null +++ b/features/plugin-get.feature @@ -0,0 +1,47 @@ +Feature: Get WordPress plugin + + Scenario: Get plugin info + Given a WP install + And a wp-content/plugins/foo.php file: + """ + /** + * Plugin Name: Sample Plugin + * Description: Description for sample plugin. + * Requires at least: 6.0 + * Requires PHP: 5.6 + * Version: 1.0.0 + * Author: John Doe + * Author URI: https://example.com/ + * License: GPLv2 or later + * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * Text Domain: sample-plugin + */ + """ + + When I run `wp plugin get foo --fields=name,author,version,status` + Then STDOUT should be a table containing rows: + | Field | Value | + | name | foo | + | author | John Doe | + | version | 1.0.0 | + | status | inactive | + + @require-wp-6.5 + Scenario: Get Requires Plugins header of plugin + Given a WP install + And a wp-content/plugins/foo.php file: + """ + Date: Thu, 25 Apr 2024 14:53:49 +0545 Subject: [PATCH 3/5] Show requires fields optionally --- features/plugin-get.feature | 27 +++++++++++++++++++++++++ src/Plugin_Command.php | 39 +++++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/features/plugin-get.feature b/features/plugin-get.feature index 403bbb64..cdb3a75a 100644 --- a/features/plugin-get.feature +++ b/features/plugin-get.feature @@ -26,6 +26,12 @@ Feature: Get WordPress plugin | version | 1.0.0 | | status | inactive | + When I run `wp plugin get foo --format=json` + Then STDOUT should be: + """ + {"name":"foo","title":"Sample Plugin","author":"John Doe","version":"1.0.0","description":"Description for sample plugin.","status":"inactive"} + """ + @require-wp-6.5 Scenario: Get Requires Plugins header of plugin Given a WP install @@ -45,3 +51,24 @@ Feature: Get WordPress plugin """ jetpack, woocommerce """ + + @require-wp-5.3 + Scenario: Get Requires PHP and Requires WP header of plugin + Given a WP install + And a wp-content/plugins/foo.php file: + """ + fetcher->get_check( $args[0] ); $file = $plugin->file; $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $file, false, false ); $plugin_obj = (object) [ - 'name' => Utils\get_plugin_name( $file ), - 'title' => $plugin_data['Name'], - 'author' => $plugin_data['Author'], - 'version' => $plugin_data['Version'], - 'description' => wordwrap( $plugin_data['Description'] ), - 'status' => $this->get_status( $file ), + 'name' => Utils\get_plugin_name( $file ), + 'title' => $plugin_data['Name'], + 'author' => $plugin_data['Author'], + 'version' => $plugin_data['Version'], + 'description' => wordwrap( $plugin_data['Description'] ), + 'status' => $this->get_status( $file ), + 'requires_wp' => '', + 'requires_php' => '', + 'requires_plugins' => '', ]; - if ( isset( $plugin_data['RequiresPlugins'] ) && ! empty( $plugin_data['RequiresPlugins'] ) ) { - $plugin_obj->requires_plugins = $plugin_data['RequiresPlugins']; + $require_fields = [ + 'requires_wp' => 'RequiresWP', + 'requires_php' => 'RequiresPHP', + 'requires_plugins' => 'RequiresPlugins', + ]; + + foreach ( $require_fields as $field_key => $data_key ) { + if ( isset( $plugin_data[ $data_key ] ) && ! empty( $plugin_data[ $data_key ] ) ) { + $plugin_obj->{$field_key} = $plugin_data[ $data_key ]; + } } if ( empty( $assoc_args['fields'] ) ) { - $plugin_array = get_object_vars( $plugin_obj ); - $assoc_args['fields'] = array_keys( $plugin_array ); + $assoc_args['fields'] = $default_fields; } $formatter = $this->get_formatter( $assoc_args ); From b9d1d77ba086da8d2ac5479fe981ec384b597ed2 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 25 Apr 2024 15:01:55 +0545 Subject: [PATCH 4/5] Update docs for plugin get command --- README.md | 20 +++++++++++++++++++- src/Plugin_Command.php | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d3e971ad..d2f4eccf 100644 --- a/README.md +++ b/README.md @@ -197,10 +197,28 @@ wp plugin get [--field=] [--fields=] [--format=] - yaml --- +**AVAILABLE FIELDS** + +These fields will be displayed by default for the plugin: + +* name +* title +* author +* version +* description +* status + +These fields are optionally available: + +* requires_wp +* requires_php +* requires_plugins + **EXAMPLES** + # Get plugin details. $ wp plugin get bbpress --format=json - {"name":"bbpress","title":"bbPress","author":"The bbPress Contributors","version":"2.6-alpha","description":"bbPress is forum software with a twist from the creators of WordPress.","status":"active"} + {"name":"bbpress","title":"bbPress","author":"The bbPress Contributors","version":"2.6.9","description":"bbPress is forum software with a twist from the creators of WordPress.","status":"active"} diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index c98190f4..46ddaeaf 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -941,10 +941,28 @@ public function install( $args, $assoc_args ) { * - yaml * --- * + * ## AVAILABLE FIELDS + * + * These fields will be displayed by default for the plugin: + * + * * name + * * title + * * author + * * version + * * description + * * status + * + * These fields are optionally available: + * + * * requires_wp + * * requires_php + * * requires_plugins + * * ## EXAMPLES * + * # Get plugin details. * $ wp plugin get bbpress --format=json - * {"name":"bbpress","title":"bbPress","author":"The bbPress Contributors","version":"2.6-alpha","description":"bbPress is forum software with a twist from the creators of WordPress.","status":"active"} + * {"name":"bbpress","title":"bbPress","author":"The bbPress Contributors","version":"2.6.9","description":"bbPress is forum software with a twist from the creators of WordPress.","status":"active"} */ public function get( $args, $assoc_args ) { $default_fields = array( From ea5566b96ab09917ee63c87abf054ab1c7ae335b Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 25 Apr 2024 15:30:27 +0545 Subject: [PATCH 5/5] Simplify fetching requires header values --- src/Plugin_Command.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 46ddaeaf..9e237c0d 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -986,23 +986,11 @@ public function get( $args, $assoc_args ) { 'version' => $plugin_data['Version'], 'description' => wordwrap( $plugin_data['Description'] ), 'status' => $this->get_status( $file ), - 'requires_wp' => '', - 'requires_php' => '', - 'requires_plugins' => '', + 'requires_wp' => ! empty( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : '', + 'requires_php' => ! empty( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : '', + 'requires_plugins' => ! empty( $plugin_data['RequiresPlugins'] ) ? $plugin_data['RequiresPlugins'] : '', ]; - $require_fields = [ - 'requires_wp' => 'RequiresWP', - 'requires_php' => 'RequiresPHP', - 'requires_plugins' => 'RequiresPlugins', - ]; - - foreach ( $require_fields as $field_key => $data_key ) { - if ( isset( $plugin_data[ $data_key ] ) && ! empty( $plugin_data[ $data_key ] ) ) { - $plugin_obj->{$field_key} = $plugin_data[ $data_key ]; - } - } - if ( empty( $assoc_args['fields'] ) ) { $assoc_args['fields'] = $default_fields; }