Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show additional plugin headers values in wp plugin get <plugin> output #414

Merged
merged 6 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions features/plugin-get.feature
Original file line number Diff line number Diff line change
@@ -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:
"""
<?php
/**
* Plugin Name: Foo
* Description: Foo plugin
* Author: John Doe
* Requires Plugins: jetpack, woocommerce
*/
"""

When I run `wp plugin get foo --field=requires_plugins`
Then STDOUT should be:
"""
jetpack, woocommerce
"""
4 changes: 4 additions & 0 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,10 @@ public function get( $args, $assoc_args ) {
'status' => $this->get_status( $file ),
];

if ( isset( $plugin_data['RequiresPlugins'] ) && ! empty( $plugin_data['RequiresPlugins'] ) ) {
ernilambar marked this conversation as resolved.
Show resolved Hide resolved
$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 );
Expand Down