Skip to content

Commit 8c0cc7b

Browse files
committed
Merge branch 'master' into svenkaptein-feature-plugin-delete-all
2 parents a931978 + faa452b commit 8c0cc7b

File tree

8 files changed

+183
-30
lines changed

8 files changed

+183
-30
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ search query.
451451
**icons**: Plugin's Icon Image Link
452452
**active_installs**: Plugin's Number of Active Installs
453453
**contributors**: Plugin's List of Contributors
454+
**url**: Plugin's URL on wordpress.org
454455

455456
[--format=<format>]
456457
Render output in a particular format.
@@ -1206,6 +1207,7 @@ search query.
12061207
**num_ratings**: Number of Theme Ratings
12071208
**homepage**: Theme Author's Homepage
12081209
**description**: Theme Description
1210+
**url**: Theme's URL on wordpress.org
12091211

12101212
[--format=<format>]
12111213
Render output in a particular format.
@@ -1341,6 +1343,44 @@ wp theme update [<theme>...] [--all] [--exclude=<theme-names>] [--format=<format
13411343
# Update all themes
13421344
$ wp theme update --all
13431345

1346+
1347+
1348+
### wp theme mod list
1349+
1350+
Gets a list of theme mods.
1351+
1352+
~~~
1353+
wp theme mod list [--field=<field>] [--format=<format>]
1354+
~~~
1355+
1356+
**OPTIONS**
1357+
1358+
[--field=<field>]
1359+
Returns the value of a single field.
1360+
1361+
[--format=<format>]
1362+
Render output in a particular format.
1363+
---
1364+
default: table
1365+
options:
1366+
- table
1367+
- json
1368+
- csv
1369+
- yaml
1370+
---
1371+
1372+
**EXAMPLES**
1373+
1374+
# Gets a list of theme mods.
1375+
$ wp theme mod list
1376+
+------------------+---------+
1377+
| key | value |
1378+
+------------------+---------+
1379+
| background_color | dd3333 |
1380+
| link_color | #dd9933 |
1381+
| main_text_color | #8224e3 |
1382+
+------------------+---------+
1383+
13441384
## Installing
13451385

13461386
This package is included with WP-CLI itself, no additional installation necessary.

features/theme.feature

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -231,73 +231,73 @@ Feature: Manage WordPress themes
231231
232232
Scenario: Enabling and disabling a theme
233233
Given a WP multisite install
234-
And I run `wp theme install jolene`
235-
And I run `wp theme install biker`
234+
And I run `wp theme install stargazer`
235+
And I run `wp theme install buntu`
236236
237237
When I try `wp option get allowedthemes`
238238
Then the return code should be 1
239239
# STDERR may or may not be empty, depending on WP-CLI version.
240240
And STDOUT should be empty
241241
242-
When I run `wp theme enable biker`
242+
When I run `wp theme enable buntu`
243243
Then STDOUT should contain:
244244
"""
245-
Success: Enabled the 'Biker' theme.
245+
Success: Enabled the 'Buntu' theme.
246246
"""
247247
248248
When I run `wp option get allowedthemes`
249249
Then STDOUT should contain:
250250
"""
251-
'biker' => true
251+
'buntu' => true
252252
"""
253253
254-
When I run `wp theme disable biker`
254+
When I run `wp theme disable buntu`
255255
Then STDOUT should contain:
256256
"""
257-
Success: Disabled the 'Biker' theme.
257+
Success: Disabled the 'Buntu' theme.
258258
"""
259259
260260
When I run `wp option get allowedthemes`
261261
Then STDOUT should not contain:
262262
"""
263-
'biker' => true
263+
'buntu' => true
264264
"""
265265
266-
When I run `wp theme enable biker --activate`
266+
When I run `wp theme enable buntu --activate`
267267
Then STDOUT should contain:
268268
"""
269-
Success: Enabled the 'Biker' theme.
270-
Success: Switched to 'Biker' theme.
269+
Success: Enabled the 'Buntu' theme.
270+
Success: Switched to 'Buntu' theme.
271271
"""
272272
273273
When I run `wp network-meta get 1 allowedthemes`
274274
Then STDOUT should not contain:
275275
"""
276-
'biker' => true
276+
'buntu' => true
277277
"""
278278
279-
When I run `wp theme enable biker --network`
279+
When I run `wp theme enable buntu --network`
280280
Then STDOUT should contain:
281281
"""
282-
Success: Network enabled the 'Biker' theme.
282+
Success: Network enabled the 'Buntu' theme.
283283
"""
284284
285285
When I run `wp network-meta get 1 allowedthemes`
286286
Then STDOUT should contain:
287287
"""
288-
'biker' => true
288+
'buntu' => true
289289
"""
290290
291-
When I run `wp theme disable biker --network`
291+
When I run `wp theme disable buntu --network`
292292
Then STDOUT should contain:
293293
"""
294-
Success: Network disabled the 'Biker' theme.
294+
Success: Network disabled the 'Buntu' theme.
295295
"""
296296
297297
When I run `wp network-meta get 1 allowedthemes`
298298
Then STDOUT should not contain:
299299
"""
300-
'biker' => true
300+
'buntu' => true
301301
"""
302302
303303
Scenario: Enabling and disabling a theme without multisite
@@ -335,27 +335,27 @@ Feature: Manage WordPress themes
335335
336336
Scenario: Install and attempt to activate a child theme without its parent
337337
Given a WP install
338-
And I run `wp theme install biker`
339-
And I run `rm -rf wp-content/themes/jolene`
338+
And I run `wp theme install buntu`
339+
And I run `rm -rf wp-content/themes/stargazer`
340340
341-
When I try `wp theme activate biker`
341+
When I try `wp theme activate buntu`
342342
Then STDERR should contain:
343343
"""
344-
Error: The parent theme is missing. Please install the "jolene" parent theme.
344+
Error: The parent theme is missing. Please install the "stargazer" parent theme.
345345
"""
346346
And STDOUT should be empty
347347
And the return code should be 1
348348
349349
Scenario: List an active theme with its parent
350350
Given a WP install
351-
And I run `wp theme install jolene`
352-
And I run `wp theme install --activate biker`
351+
And I run `wp theme install stargazer`
352+
And I run `wp theme install --activate buntu`
353353
354354
When I run `wp theme list --fields=name,status`
355355
Then STDOUT should be a table containing rows:
356356
| name | status |
357-
| biker | active |
358-
| jolene | parent |
357+
| buntu | active |
358+
| stargazer | parent |
359359
360360
Scenario: When updating a theme --format should be the same when using --dry-run
361361
Given a WP install

features/upgradables.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Feature: Manage WordPress themes and plugins
1313
And STDERR should be empty
1414
And STDOUT should be empty
1515

16+
When I try `wp <type> is-active <item>`
17+
Then the return code should be 1
18+
And STDERR should be empty
19+
And STDOUT should be empty
20+
1621
When I try `wp <type> get <item>`
1722
Then the return code should be 1
1823
And STDERR should not be empty

src/Plugin_Command.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public function status( $args ) {
152152
* **icons**: Plugin's Icon Image Link
153153
* **active_installs**: Plugin's Number of Active Installs
154154
* **contributors**: Plugin's List of Contributors
155+
* **url**: Plugin's URL on wordpress.org
155156
*
156157
* [--format=<format>]
157158
* : Render output in a particular format.
@@ -198,7 +199,7 @@ protected function status_single( $args ) {
198199
if ( $this->has_update( $file ) )
199200
$version .= ' (%gUpdate available%n)';
200201

201-
echo WP_CLI::colorize( \WP_CLI\Utils\mustache_render( 'plugin-status.mustache', array(
202+
echo WP_CLI::colorize( \WP_CLI\Utils\mustache_render( self::get_template_path( 'plugin-status.mustache' ), array(
202203
'slug' => Utils\get_plugin_name( $file ),
203204
'status' => $status,
204205
'version' => $version,
@@ -899,6 +900,37 @@ public function is_installed( $args, $assoc_args = array() ) {
899900
}
900901
}
901902

903+
/**
904+
* Checks if a given plugin is active.
905+
*
906+
* Returns exit code 0 when active, 1 when not active.
907+
*
908+
* ## OPTIONS
909+
*
910+
* <plugin>
911+
* : The plugin to check.
912+
*
913+
* ## EXAMPLES
914+
*
915+
* # Check whether plugin is Active; exit status 0 if active, otherwise 1
916+
* $ wp plugin is-active hello
917+
* $ echo $?
918+
* 1
919+
*
920+
* @subcommand is-active
921+
*/
922+
public function is_active( $args, $assoc_args = array() ) {
923+
$network_wide = \WP_CLI\Utils\get_flag_value( $assoc_args, 'network' );
924+
925+
$plugin = $this->fetcher->get( $args[0] );
926+
927+
if ( ! $plugin ) {
928+
WP_CLI::halt( 1 );
929+
}
930+
931+
$this->check_active( $plugin->file, $network_wide ) ? WP_CLI::halt( 0 ) : WP_CLI::halt( 1 );
932+
}
933+
902934
/**
903935
* Deletes plugin files without deactivating or uninstalling.
904936
*
@@ -1058,6 +1090,20 @@ protected function get_status( $file ) {
10581090
return 'inactive';
10591091
}
10601092

1093+
/**
1094+
* Gets the template path based on installation type.
1095+
*/
1096+
private static function get_template_path( $template ) {
1097+
$command_root = Utils\phar_safe_path( dirname( __DIR__ ) );
1098+
$template_path = "{$command_root}/templates/{$template}";
1099+
1100+
if ( ! file_exists( $template_path ) ) {
1101+
WP_CLI::error( "Couldn't find {$template}" );
1102+
}
1103+
1104+
return $template_path;
1105+
}
1106+
10611107
/**
10621108
* Gets the details of a plugin.
10631109
*

src/Theme_Command.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function status( $args ) {
125125
* **num_ratings**: Number of Theme Ratings
126126
* **homepage**: Theme Author's Homepage
127127
* **description**: Theme Description
128+
* **url**: Theme's URL on wordpress.org
128129
*
129130
* [--format=<format>]
130131
* : Render output in a particular format.
@@ -166,7 +167,7 @@ protected function status_single( $args ) {
166167
if ( $this->has_update( $theme->get_stylesheet() ) )
167168
$version .= ' (%gUpdate available%n)';
168169

169-
echo WP_CLI::colorize( \WP_CLI\Utils\mustache_render( 'theme-status.mustache', array(
170+
echo WP_CLI::colorize( \WP_CLI\Utils\mustache_render( self::get_template_path( 'theme-status.mustache' ), array(
170171
'slug' => $theme->get_stylesheet(),
171172
'status' => $status,
172173
'version' => $version,
@@ -597,7 +598,7 @@ public function get( $args, $assoc_args ) {
597598
*
598599
* [--all]
599600
* : If set, all themes that have updates will be updated.
600-
*
601+
*
601602
* [--exclude=<theme-names>]
602603
* : Comma separated list of theme names that should be excluded from updating.
603604
*
@@ -639,7 +640,7 @@ public function get( $args, $assoc_args ) {
639640
* | twentysixteen | 1.1 | 1.2 | Updated |
640641
* +---------------+-------------+-------------+---------+
641642
* Success: Updated 2 of 2 themes.
642-
*
643+
*
643644
* # Exclude themes updates when bulk updating the themes
644645
* $ wp theme update --all --exclude=twentyfifteen
645646
* Downloading update from https://downloads.wordpress.org/theme/astra.1.0.5.1.zip...
@@ -716,6 +717,35 @@ public function is_installed( $args, $assoc_args = array() ) {
716717
}
717718
}
718719

720+
/**
721+
* Checks if a given theme is active.
722+
*
723+
* Returns exit code 0 when active, 1 when not active.
724+
*
725+
* ## OPTIONS
726+
*
727+
* <theme>
728+
* : The plugin to check.
729+
*
730+
* ## EXAMPLES
731+
*
732+
* # Check whether theme is Active; exit status 0 if active, otherwise 1
733+
* $ wp theme is-active twentyfifteen
734+
* $ echo $?
735+
* 1
736+
*
737+
* @subcommand is-active
738+
*/
739+
public function is_active( $args, $assoc_args = array() ) {
740+
$theme = wp_get_theme( $args[0] );
741+
742+
if ( ! $theme->exists() ) {
743+
WP_CLI::halt( 1 );
744+
}
745+
746+
$this->is_active_theme( $theme ) ? WP_CLI::halt( 0 ) : WP_CLI::halt( 1 );
747+
}
748+
719749
/**
720750
* Deletes one or more themes.
721751
*
@@ -840,4 +870,18 @@ private function check_optional_args_and_all( $args, $all ) {
840870

841871
return $args;
842872
}
873+
874+
/**
875+
* Gets the template path based on installation type.
876+
*/
877+
private static function get_template_path( $template ) {
878+
$command_root = Utils\phar_safe_path( dirname( __DIR__ ) );
879+
$template_path = "{$command_root}/templates/{$template}";
880+
881+
if ( ! file_exists( $template_path ) ) {
882+
WP_CLI::error( "Couldn't find {$template}" );
883+
}
884+
885+
return $template_path;
886+
}
843887
}

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ protected function _search( $args, $assoc_args ) {
613613

614614
$items = $api->$plural;
615615

616+
// Add `url` for plugin or theme on wordpress.org.
617+
foreach ( $items as $index => $item_object ) {
618+
if ( $item_object instanceof \stdClass ) {
619+
$item_object->url = "https://wordpress.org/{$plural}/{$item_object->slug}/";
620+
}
621+
}
622+
616623
if ( 'table' === $format ) {
617624
$count = \WP_CLI\Utils\get_flag_value( $api->info, 'results', 'unknown' );
618625
\WP_CLI::success( sprintf( 'Showing %s of %s %s.', count( $items ), $count, $plural ) );

templates/plugin-status.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Plugin %9{{slug}}%n details:
2+
Name: {{name}}
3+
Status: {{status}}%n
4+
Version: {{version}}
5+
Author: {{author}}
6+
Description: {{description}}

templates/theme-status.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Theme %9{{slug}}%n details:
2+
Name: {{name}}
3+
Status: {{status}}%n
4+
Version: {{version}}
5+
Author: {{author}}

0 commit comments

Comments
 (0)