Skip to content

Commit 0da98cc

Browse files
authored
Merge pull request #102 from marksabbath/master
New command: `wp <plugin|theme> is-active <theme|plugin>` addressing #102
2 parents 941e7e3 + cdf3e5b commit 0da98cc

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,37 @@ public function is_installed( $args, $assoc_args = array() ) {
899899
}
900900
}
901901

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

src/Theme_Command.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ public function get( $args, $assoc_args ) {
597597
*
598598
* [--all]
599599
* : If set, all themes that have updates will be updated.
600-
*
600+
*
601601
* [--exclude=<theme-names>]
602602
* : Comma separated list of theme names that should be excluded from updating.
603603
*
@@ -639,7 +639,7 @@ public function get( $args, $assoc_args ) {
639639
* | twentysixteen | 1.1 | 1.2 | Updated |
640640
* +---------------+-------------+-------------+---------+
641641
* Success: Updated 2 of 2 themes.
642-
*
642+
*
643643
* # Exclude themes updates when bulk updating the themes
644644
* $ wp theme update --all --exclude=twentyfifteen
645645
* Downloading update from https://downloads.wordpress.org/theme/astra.1.0.5.1.zip...
@@ -716,6 +716,35 @@ public function is_installed( $args, $assoc_args = array() ) {
716716
}
717717
}
718718

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

0 commit comments

Comments
 (0)