1
|
|
|
<?php |
2
|
|
|
namespace PressCLI\WPCLI; |
3
|
|
|
|
4
|
|
|
use PressCLI\WPCLI\CLI; |
5
|
|
|
use PressCLI\ThemeInstall\Zip; |
6
|
|
|
use PressCLI\Option\Configuration; |
7
|
|
|
use PressCLI\ThemeInstall\StyleCSS; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
trait Theme |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Deletes all unused default themes. |
14
|
|
|
*/ |
15
|
|
|
public static function themeDeleteDefaults() |
16
|
|
|
{ |
17
|
|
|
$themes = [ |
18
|
|
|
'twentyfifteen', |
19
|
|
|
'twentyfourteen', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
foreach ($themes as $theme) { |
23
|
|
|
self::themeDelete($theme); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Deletes a theme. |
29
|
|
|
* |
30
|
|
|
* @param string $theme Theme name to delete. |
31
|
|
|
*/ |
32
|
|
|
public static function themeDelete($theme) |
33
|
|
|
{ |
34
|
|
|
CLI::execCommand('theme', ['delete', $theme]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Activates a theme. |
39
|
|
|
* |
40
|
|
|
* @param string $theme Theme name to activate. |
41
|
|
|
*/ |
42
|
|
|
protected static function themeActivate($theme) |
43
|
|
|
{ |
44
|
|
|
CLI::execCommand('theme', ['activate', $theme]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Installs a theme. |
49
|
|
|
* |
50
|
|
|
* @param OutputInterface $output |
51
|
|
|
*/ |
52
|
|
|
public static function themeInstall(OutputInterface $output) |
53
|
|
|
{ |
54
|
|
|
$config = Configuration::get(); |
55
|
|
|
$url = isset($config['theme']['url']) ? $config['theme']['url'] : ''; |
56
|
|
|
$name = isset($config['theme']['name']) ? $config['theme']['name'] : ''; |
57
|
|
|
$directory = getcwd() . '/wp-content/themes'; |
58
|
|
|
|
59
|
|
|
// Make sure we have the required configuration. |
60
|
|
|
if (!$url || !$name) { |
61
|
|
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Make sure the theme does not already exist. |
65
|
|
|
if (file_exists("{$directory}/{$name}")) { |
66
|
|
|
$output->writeln("Warning: Theme already exists in {$directory}/{$name}."); |
67
|
|
|
|
68
|
|
|
// Activate theme. |
69
|
|
|
self::themeActivate($name); |
70
|
|
|
|
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// Download the theme to the themes directory. |
75
|
|
|
$theme = Zip::execute($url, $directory, $name); |
76
|
|
|
if (!$theme) { |
77
|
|
|
$output->writeln("<error>Error: Theme could not be downloaded from {$url}!</error>"); |
78
|
|
|
return; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$output->writeln("Success: Theme successfully installed!"); |
82
|
|
|
|
83
|
|
|
// Set style.css |
84
|
|
|
StyleCSS::set(); |
85
|
|
|
|
86
|
|
|
// Activate theme. |
87
|
|
|
self::themeActivate($name); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|