Skip to content

Commit

Permalink
Merge pull request #3249 from wp-cli/3216-fix-skip-plugins-network
Browse files Browse the repository at this point in the history
Fix `--skip-plugins` for network-activated plugins (v0.24.1)
  • Loading branch information
danielbachhuber committed Aug 4, 2016
2 parents 7086ecb + 7793be6 commit edadb0c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
47 changes: 24 additions & 23 deletions features/skip-plugins.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ Feature: Skipping plugins
Given a WP install
And I run `wp plugin activate hello akismet`

When I run `wp eval 'var_export( defined("AKISMET_VERSION") );'`
When I run `wp eval 'var_export( defined("AKISMET_VERSION") );var_export( function_exists( "hello_dolly" ) );'`
Then STDOUT should be:
"""
true
"""

When I run `wp eval 'var_export( function_exists( "hello_dolly" ) );'`
Then STDOUT should be:
"""
true
truetrue
"""

# The specified plugin should be skipped
Expand All @@ -31,10 +25,10 @@ Feature: Skipping plugins
"""

# The un-specified plugin should continue to be loaded
When I run `wp --skip-plugins=akismet eval 'var_export( function_exists( "hello_dolly" ) );'`
When I run `wp --skip-plugins=akismet eval 'var_export( defined("AKISMET_VERSION") );var_export( function_exists( "hello_dolly" ) );'`
Then STDOUT should be:
"""
true
falsetrue
"""

# Can specify multiple plugins to skip
Expand All @@ -45,15 +39,10 @@ Feature: Skipping plugins
"""

# No plugins should be loaded when --skip-plugins doesn't have a value
When I run `wp --skip-plugins eval 'var_export( defined("AKISMET_VERSION") );'`
Then STDOUT should be:
"""
false
"""
When I run `wp --skip-plugins eval 'var_export( function_exists( "hello_dolly" ) );'`
When I run `wp --skip-plugins eval 'var_export( defined("AKISMET_VERSION") );var_export( function_exists( "hello_dolly" ) );'`
Then STDOUT should be:
"""
false
falsefalse
"""

Scenario: Skipping multiple plugins via config file
Expand Down Expand Up @@ -88,17 +77,29 @@ Feature: Skipping plugins

Scenario: Skip network active plugins
Given a WP multisite install
And I run `wp plugin deactivate akismet`
And I run `wp plugin activate --network akismet`
And I run `wp plugin deactivate akismet hello`
And I run `wp plugin activate --network akismet hello`

When I run `wp eval 'var_export( defined("AKISMET_VERSION") );'`
When I run `wp eval 'var_export( defined("AKISMET_VERSION") );var_export( function_exists( "hello_dolly" ) );'`
Then STDOUT should be:
"""
true
truetrue
"""

When I run `wp --skip-plugins=akismet eval 'var_export( defined("AKISMET_VERSION") );'`
When I run `wp --skip-plugins eval 'var_export( defined("AKISMET_VERSION") );var_export( function_exists( "hello_dolly" ) );'`
Then STDOUT should be:
"""
false
falsefalse
"""

When I run `wp --skip-plugins=akismet eval 'var_export( defined("AKISMET_VERSION") );var_export( function_exists( "hello_dolly" ) );'`
Then STDOUT should be:
"""
falsetrue
"""

When I run `wp --skip-plugins=hello eval 'var_export( defined("AKISMET_VERSION") );var_export( function_exists( "hello_dolly" ) );'`
Then STDOUT should be:
"""
truefalse
"""
16 changes: 12 additions & 4 deletions php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1139,12 +1139,20 @@ private function setup_skip_plugins_filters() {
if ( ! is_array( $plugins ) ) {
return $plugins;
}
foreach( $plugins as $key => $plugin ) {
if ( Utils\is_plugin_skipped( $plugin ) ) {
unset( $plugins[ $key ] );
foreach( $plugins as $a => $b ) {
// active_sitewide_plugins stores plugin name as the key
if ( false !== strpos( current_filter(), 'active_sitewide_plugins' ) && Utils\is_plugin_skipped( $a ) ) {
unset( $plugins[ $a ] );
// active_plugins stores plugin name as the value
} else if ( false !== strpos( current_filter(), 'active_plugins' ) && Utils\is_plugin_skipped( $b ) ) {
unset( $plugins[ $a ] );
}
}
return array_values( $plugins );
// Reindex because active_plugins expects a numeric index
if ( false !== strpos( current_filter(), 'active_plugins' ) ) {
$plugins = array_values( $plugins );
}
return $plugins;
};

$hooks = array(
Expand Down

0 comments on commit edadb0c

Please sign in to comment.