OSDN Git Service

don't pick up php files inside plugin subdirs
authorscribu <mail@scribu.net>
Mon, 11 Nov 2013 22:55:43 +0000 (00:55 +0200)
committerscribu <mail@scribu.net>
Mon, 11 Nov 2013 22:58:29 +0000 (00:58 +0200)
features/plugin.feature
php/WP_CLI/Fetchers/Plugin.php

index 93c693a..be9c51c 100644 (file)
@@ -17,7 +17,9 @@ Feature: Manage WordPress plugins
     And the {PLUGIN_DIR}/zombieland/zombieland.php file should exist
     And the {PLUGIN_DIR}/zombieland/phpunit.xml file should exist
 
-    When I run `wp plugin status zombieland`
+    # Check that the inner-plugin is not picked up
+    When I run `mv {PLUGIN_DIR}/plugin1 {PLUGIN_DIR}/zombieland/`
+    And I run `wp plugin status zombieland`
     Then STDOUT should contain:
       """
       Plugin zombieland details:
index 247192b..f596725 100644 (file)
@@ -9,22 +9,30 @@ class Plugin extends Base {
        public function get( $name ) {
                $plugins = get_plugins( '/' . $name );
 
-               if ( !empty( $plugins ) ) {
-                       $file = $name . '/' . key( $plugins );
-               } else {
-                       $file = $name . '.php';
+               // some-plugin/the-plugin.php
+               while ( !empty( $plugins ) ) {
+                       $file = key( $plugins );
+                       array_shift( $plugins );
+
+                       // ignore files inside a plugin's subdirectory (like WP does)
+                       if ( dirname( $file ) == '.' ) {
+                               return (object) array(
+                                       'name' => $name,
+                                       'file' => $name . '/' . $file
+                               );
+                       }
+               }
 
-                       $plugins = get_plugins();
+               // some-plugin.php
+               $file = $name . '.php';
 
-                       if ( !isset( $plugins[$file] ) ) {
-                               return false;
-                       }
+               $plugins = get_plugins();
+
+               if ( isset( $plugins[ $file ] ) ) {
+                       return (object) compact( 'name', 'file' );
                }
 
-               return (object) array(
-                       'name' => $name,
-                       'file' => $file
-               );
+               return false;
        }
 }