OSDN Git Service

Merge pull request #817 from x-team:mysqldump-extra-args
[wvm/wvm.git] / php / WP_CLI / Fetchers / Plugin.php
1 <?php
2
3 namespace WP_CLI\Fetchers;
4
5 class Plugin extends Base {
6
7         protected $msg = "The '%s' plugin could not be found.";
8
9         public function get( $name ) {
10                 $plugins = get_plugins( '/' . $name );
11
12                 // some-plugin/the-plugin.php
13                 while ( !empty( $plugins ) ) {
14                         $file = key( $plugins );
15                         array_shift( $plugins );
16
17                         // ignore files inside a plugin's subdirectory (like WP does)
18                         if ( dirname( $file ) == '.' ) {
19                                 return (object) array(
20                                         'name' => $name,
21                                         'file' => $name . '/' . $file
22                                 );
23                         }
24                 }
25
26                 // some-plugin.php
27                 $file = $name . '.php';
28
29                 $plugins = get_plugins();
30
31                 if ( isset( $plugins[ $file ] ) ) {
32                         return (object) compact( 'name', 'file' );
33                 }
34
35                 return false;
36         }
37 }
38