Skip to content

Commit e81579d

Browse files
authored
Merge pull request #414 from ernilambar/update/plugin-get-deps
2 parents 96a2d33 + 033353d commit e81579d

File tree

3 files changed

+131
-10
lines changed

3 files changed

+131
-10
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,28 @@ wp plugin get <plugin> [--field=<field>] [--fields=<fields>] [--format=<format>]
197197
- yaml
198198
---
199199

200+
**AVAILABLE FIELDS**
201+
202+
These fields will be displayed by default for the plugin:
203+
204+
* name
205+
* title
206+
* author
207+
* version
208+
* description
209+
* status
210+
211+
These fields are optionally available:
212+
213+
* requires_wp
214+
* requires_php
215+
* requires_plugins
216+
200217
**EXAMPLES**
201218

219+
# Get plugin details.
202220
$ wp plugin get bbpress --format=json
203-
{"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"}
221+
{"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"}
204222

205223

206224

features/plugin-get.feature

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Feature: Get WordPress plugin
2+
3+
Scenario: Get plugin info
4+
Given a WP install
5+
And a wp-content/plugins/foo.php file:
6+
"""
7+
/**
8+
* Plugin Name: Sample Plugin
9+
* Description: Description for sample plugin.
10+
* Requires at least: 6.0
11+
* Requires PHP: 5.6
12+
* Version: 1.0.0
13+
* Author: John Doe
14+
* Author URI: https://example.com/
15+
* License: GPLv2 or later
16+
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
17+
* Text Domain: sample-plugin
18+
*/
19+
"""
20+
21+
When I run `wp plugin get foo --fields=name,author,version,status`
22+
Then STDOUT should be a table containing rows:
23+
| Field | Value |
24+
| name | foo |
25+
| author | John Doe |
26+
| version | 1.0.0 |
27+
| status | inactive |
28+
29+
When I run `wp plugin get foo --format=json`
30+
Then STDOUT should be:
31+
"""
32+
{"name":"foo","title":"Sample Plugin","author":"John Doe","version":"1.0.0","description":"Description for sample plugin.","status":"inactive"}
33+
"""
34+
35+
@require-wp-6.5
36+
Scenario: Get Requires Plugins header of plugin
37+
Given a WP install
38+
And a wp-content/plugins/foo.php file:
39+
"""
40+
<?php
41+
/**
42+
* Plugin Name: Foo
43+
* Description: Foo plugin
44+
* Author: John Doe
45+
* Requires Plugins: jetpack, woocommerce
46+
*/
47+
"""
48+
49+
When I run `wp plugin get foo --field=requires_plugins`
50+
Then STDOUT should be:
51+
"""
52+
jetpack, woocommerce
53+
"""
54+
55+
@require-wp-5.3
56+
Scenario: Get Requires PHP and Requires WP header of plugin
57+
Given a WP install
58+
And a wp-content/plugins/foo.php file:
59+
"""
60+
<?php
61+
/**
62+
* Plugin Name: Foo
63+
* Description: Foo plugin
64+
* Author: John Doe
65+
* Requires at least: 6.2
66+
* Requires PHP: 7.4
67+
*/
68+
"""
69+
70+
When I run `wp plugin get foo --fields=requires_wp,requires_php`
71+
Then STDOUT should be a table containing rows:
72+
| Field | Value |
73+
| requires_wp | 6.2 |
74+
| requires_php | 7.4 |

src/Plugin_Command.php

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -941,29 +941,58 @@ public function install( $args, $assoc_args ) {
941941
* - yaml
942942
* ---
943943
*
944+
* ## AVAILABLE FIELDS
945+
*
946+
* These fields will be displayed by default for the plugin:
947+
*
948+
* * name
949+
* * title
950+
* * author
951+
* * version
952+
* * description
953+
* * status
954+
*
955+
* These fields are optionally available:
956+
*
957+
* * requires_wp
958+
* * requires_php
959+
* * requires_plugins
960+
*
944961
* ## EXAMPLES
945962
*
963+
* # Get plugin details.
946964
* $ wp plugin get bbpress --format=json
947-
* {"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"}
965+
* {"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"}
948966
*/
949967
public function get( $args, $assoc_args ) {
968+
$default_fields = array(
969+
'name',
970+
'title',
971+
'author',
972+
'version',
973+
'description',
974+
'status',
975+
);
976+
950977
$plugin = $this->fetcher->get_check( $args[0] );
951978
$file = $plugin->file;
952979

953980
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $file, false, false );
954981

955982
$plugin_obj = (object) [
956-
'name' => Utils\get_plugin_name( $file ),
957-
'title' => $plugin_data['Name'],
958-
'author' => $plugin_data['Author'],
959-
'version' => $plugin_data['Version'],
960-
'description' => wordwrap( $plugin_data['Description'] ),
961-
'status' => $this->get_status( $file ),
983+
'name' => Utils\get_plugin_name( $file ),
984+
'title' => $plugin_data['Name'],
985+
'author' => $plugin_data['Author'],
986+
'version' => $plugin_data['Version'],
987+
'description' => wordwrap( $plugin_data['Description'] ),
988+
'status' => $this->get_status( $file ),
989+
'requires_wp' => ! empty( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : '',
990+
'requires_php' => ! empty( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : '',
991+
'requires_plugins' => ! empty( $plugin_data['RequiresPlugins'] ) ? $plugin_data['RequiresPlugins'] : '',
962992
];
963993

964994
if ( empty( $assoc_args['fields'] ) ) {
965-
$plugin_array = get_object_vars( $plugin_obj );
966-
$assoc_args['fields'] = array_keys( $plugin_array );
995+
$assoc_args['fields'] = $default_fields;
967996
}
968997

969998
$formatter = $this->get_formatter( $assoc_args );

0 commit comments

Comments
 (0)