|
1
|
|
|
<?php |
|
2
|
|
|
namespace PressCLI\WPCLI; |
|
3
|
|
|
|
|
4
|
|
|
use PressCLI\WPCLI\CLI; |
|
5
|
|
|
use PressCLI\Option\Configuration; |
|
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
7
|
|
|
|
|
8
|
|
|
trait Plugin |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Deletes all unused default plugins. |
|
12
|
|
|
*/ |
|
13
|
|
|
public static function pluginDeleteDefaults() |
|
14
|
|
|
{ |
|
15
|
|
|
$plugins = [ |
|
16
|
|
|
'akismet', |
|
17
|
|
|
'hello', |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
foreach ($plugins as $plugin) { |
|
21
|
|
|
self::pluginDelete($plugin); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Deletes a plugin. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $plugin Theme name to delete. |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function pluginDelete($plugin) |
|
31
|
|
|
{ |
|
32
|
|
|
CLI::execCommand('plugin', ['delete', $plugin]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Installs all of the plugins from the configuration. |
|
37
|
|
|
* |
|
38
|
|
|
* @param OutputInterface $output |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function pluginInstallAll(OutputInterface $output) |
|
41
|
|
|
{ |
|
42
|
|
|
$config = Configuration::get(); |
|
43
|
|
|
$plugins = isset($config['plugins']) ? $config['plugins'] : []; |
|
44
|
|
|
foreach ($plugins as $plugin) { |
|
45
|
|
|
$version = isset($plugin['version']) ? $plugin['version'] : ''; |
|
46
|
|
|
$activate = isset($plugin['activate']) ? (bool) $plugin['activate'] : false; |
|
47
|
|
|
$location = isset($plugin['location']) ? $plugin['location'] : ''; |
|
48
|
|
|
|
|
49
|
|
|
// Let the user know which custom plugin is being installed. |
|
50
|
|
|
if ($location) { |
|
51
|
|
|
$locVersion = $version ? "($version)" : ''; |
|
52
|
|
|
$output->writeln(trim("Installing {$plugin['plugin']} {$locVersion}")); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
// Install the plugin. |
|
56
|
|
|
$install = $location ? $location : $plugin['plugin']; |
|
57
|
|
|
self::pluginInstall($install, $activate, $version); |
|
58
|
|
|
|
|
59
|
|
|
$output->writeln(''); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Installs and optionally activates plugin. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $plugin A plugin slug, the path to a local zip file, or URL to a remote zip file. |
|
67
|
|
|
* @param boolean $activate Optional, if true the plugin will be activated immediately after install. |
|
68
|
|
|
* @param string $version Optional, version of plugin to install. Default stable. |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function pluginInstall($plugin, $activate = true, $version = null) |
|
71
|
|
|
{ |
|
72
|
|
|
$options = [ 'force' => '' ]; |
|
73
|
|
|
|
|
74
|
|
|
if ($activate) { |
|
75
|
|
|
$options['activate'] = ''; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (! is_null($version) && $version) { |
|
79
|
|
|
$options['version'] = $version; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
CLI::execCommand('plugin', ['install', $plugin], $options); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|