OSDN Git Service

first pass at --skip-plugins flag
authorscribu <mail@scribu.net>
Tue, 21 Jan 2014 00:02:40 +0000 (02:02 +0200)
committerscribu <mail@scribu.net>
Tue, 21 Jan 2014 00:22:31 +0000 (02:22 +0200)
features/flags.feature
php/commands/plugin.php
php/config-spec.php
php/utils-wp.php
php/wp-settings-cli.php

index b81fdbb..c666235 100644 (file)
@@ -92,6 +92,55 @@ Feature: Global flags
       log: called 'error' method
       """
 
+  Scenario: Skipping plugins
+    Given a WP install
+    And I run `wp plugin activate hello akismet`
+
+    When I run `wp eval 'var_export( defined("AKISMET_VERSION") );'`
+    Then STDOUT should be:
+      """
+      true
+      """
+
+    When I run `wp eval 'var_export( function_exists( "hello_dolly" ) );'`
+    Then STDOUT should be:
+      """
+      true
+      """
+
+    # The specified plugin should be skipped
+    When I run `wp --skip-plugins=akismet eval 'var_export( defined("AKISMET_VERSION") );'`
+    Then STDOUT should be:
+      """
+      false
+      """
+
+    # The specified plugin should still show up as an active plugin
+    When I run `wp --skip-plugins=akismet plugin status`
+    Then STDOUT should contain:
+      """
+      akismet
+      """
+
+    # The un-specified plugin should continue to be loaded
+    When I run `wp --skip-plugins=akismet eval 'var_export( function_exists( "hello_dolly" ) );'`
+    Then STDOUT should be:
+      """
+      true
+      """
+
+    # 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" ) );'`
+    Then STDOUT should be:
+      """
+      false
+      """
+
   Scenario: Using --require
     Given an empty directory
     And a custom-cmd.php file:
index 2b6ebef..1d90b75 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use \WP_CLI\Utils;
+
 /**
  * Manage plugins.
  *
@@ -102,7 +104,7 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
                        $version .= ' (%gUpdate available%n)';
 
                echo WP_CLI::colorize( \WP_CLI\Utils\mustache_render( 'plugin-status.mustache', array(
-                       'slug' => $this->get_name( $file ),
+                       'slug' => Utils\get_plugin_name( $file ),
                        'status' => $status,
                        'version' => $version,
                        'name' => $details['Name'],
@@ -116,7 +118,7 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
 
                foreach ( get_mu_plugins() as $file => $mu_plugin ) {
                        $items[ $file ] = array(
-                               'name' => $this->get_name( $file ),
+                               'name' => Utils\get_plugin_name( $file ),
                                'status' => 'must-use',
                                'update' => false
                        );
@@ -169,7 +171,7 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
                                if ( $this->get_status( $file ) == "inactive" )
                                        continue;
 
-                               $name = $this->get_name( $file );
+                               $name = Utils\get_plugin_name( $file );
 
                                deactivate_plugins( $file, false, $network_wide );
 
@@ -307,7 +309,7 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
                        $update_info = $this->get_update_info( $file );
 
                        $items[ $file ] = array(
-                               'name' => $this->get_name( $file ),
+                               'name' => Utils\get_plugin_name( $file ),
                                'status' => $this->get_status( $file ),
                                'update' => (bool) $update_info,
                                'update_version' => $update_info['new_version'],
@@ -387,7 +389,7 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
                $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $file, false, false );
 
                $plugin_obj = (object)array(
-                       'name'        => $this->get_name( $file ),
+                       'name'        => Utils\get_plugin_name( $file ),
                        'title'       => $plugin_data['Name'],
                        'author'      => $plugin_data['Author'],
                        'version'     => $plugin_data['Version'],
@@ -545,18 +547,6 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
                return $plugin_folder[$plugin_file];
        }
 
-       /**
-        * Converts a plugin basename back into a friendly slug.
-        */
-       private function get_name( $file ) {
-               if ( false === strpos( $file, '/' ) )
-                       $name = basename( $file, '.php' );
-               else
-                       $name = dirname( $file );
-
-               return $name;
-       }
-
        private function _delete( $plugin ) {
                $plugin_dir = dirname( $plugin->file );
                if ( '.' == $plugin_dir )
index d4e206e..dd76121 100644 (file)
@@ -28,6 +28,14 @@ return array(
                'desc' => 'Set the WordPress user',
        ),
 
+       'skip-plugins' => array(
+               'runtime' => '[=<plugin>]',
+               'file' => false,
+               'desc' => 'Skip loading all or some plugins',
+               'multiple' => false,
+               'default' => '',
+       ),
+
        'require' => array(
                'runtime' => '=<path>',
                'file' => '<path>',
index 1d925c6..a8a64fb 100644 (file)
@@ -69,3 +69,25 @@ function get_upgrader( $class ) {
        return new $class( new \WP_CLI\UpgraderSkin );
 }
 
+/**
+ * Converts a plugin basename back into a friendly slug.
+ */
+function get_plugin_name( $basename ) {
+       if ( false === strpos( $basename, '/' ) )
+               $name = basename( $basename, '.php' );
+       else
+               $name = dirname( $basename );
+
+       return $name;
+}
+
+function is_plugin_skipped( $file ) {
+       $name = get_plugin_name( str_replace( WP_PLUGIN_DIR . '/', '', $file ) );
+
+       $skipped_plugins = \WP_CLI::get_runner()->config['skip-plugins'];
+       if ( true === $skipped_plugins )
+               return true;
+
+       return in_array( $name, array_filter( explode( ',', $skipped_plugins ) ) );
+}
+
index d43118d..735e54f 100644 (file)
@@ -181,7 +181,8 @@ unset( $mu_plugin );
 // Load network activated plugins.
 if ( is_multisite() ) {
        foreach( wp_get_active_network_plugins() as $network_plugin ) {
-               include_once( $network_plugin );
+               if ( !Utils\is_plugin_skipped( $network_plugin ) )
+                       include_once( $network_plugin );
        }
        unset( $network_plugin );
 }
@@ -210,7 +211,8 @@ register_theme_directory( get_theme_root() );
 
 // Load active plugins.
 foreach ( wp_get_active_and_valid_plugins() as $plugin )
-       include_once( $plugin );
+       if ( !Utils\is_plugin_skipped( $plugin ) )
+               include_once( $plugin );
 unset( $plugin );
 
 // Load pluggable functions.