forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordPressSetup.php
More file actions
110 lines (99 loc) · 3.74 KB
/
WordPressSetup.php
File metadata and controls
110 lines (99 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
namespace Hestia\WebApp\Installers\WordPress;
use Hestia\System\Util;
use Hestia\WebApp\BaseSetup;
use Hestia\WebApp\InstallationTarget\InstallationTarget;
use function file_get_contents;
class WordPressSetup extends BaseSetup
{
protected array $info = [
'name' => 'WordPress',
'group' => 'cms',
'version' => 'latest',
'thumbnail' => 'wp-thumb.png',
];
protected array $config = [
'form' => [
'site_name' => ['type' => 'text', 'value' => 'WordPress Blog'],
'username' => ['value' => 'wpadmin'],
'email' => 'text',
'password' => 'password',
'language' => [
'type' => 'select',
'value' => 'en_US',
'options' => [
'cs_CZ' => 'Czech',
'de_DE' => 'German',
'es_ES' => 'Spanish',
'en_US' => 'English',
'fr_FR' => 'French',
'hu_HU' => 'Hungarian',
'it_IT' => 'Italian',
'ja' => 'Japanese',
'nl_NL' => 'Dutch',
'pt_PT' => 'Portuguese',
'pt_BR' => 'Portuguese (Brazil)',
'sk_SK' => 'Slovak',
'sr_RS' => 'Serbian',
'sv_SE' => 'Swedish',
'tr_TR' => 'Turkish',
'ru_RU' => 'Russian',
'uk' => 'Ukrainian',
'zh-CN' => 'Simplified Chinese (China)',
'zh_TW' => 'Traditional Chinese',
],
],
],
'database' => true,
'resources' => [
'wp' => ['src' => 'https://wordpress.org/latest.tar.gz'],
],
'server' => [
'nginx' => [
'template' => 'wordpress',
],
'php' => [
'supported' => ['7.4', '8.0', '8.1', '8.2', '8.3'],
],
],
];
protected function setupApplication(InstallationTarget $target, array $options = null): void
{
$this->appcontext->runWp($options['php_version'], [
'config',
'create',
'--dbname=' . $target->database->name,
'--dbuser=' . $target->database->user,
'--dbpass=' . $target->database->password,
'--dbhost=' . $target->database->host,
'--dbprefix=' . 'wp_' . Util::generateString(5, false) . '_',
'--dbcharset=utf8mb4',
'--locale=' . $options['language'],
'--path=' . $target->getDocRoot(),
]);
$wpPasswordBcryptContents = file_get_contents(
'https://raw.githubusercontent.com/roots/wp-password-bcrypt/master/wp-password-bcrypt.php',
);
$this->appcontext->addDirectory($target->getDocRoot('wp-content/mu-plugins/'));
$this->appcontext->createFile(
$target->getDocRoot('wp-content/mu-plugins/wp-password-bcrypt.php'),
$wpPasswordBcryptContents,
);
// WordPress CLI seems to have a bug that when site name has a space it will be seen as an
// extra argument. Even when properly escaped. For now just install with install.php
$this->appcontext->sendPostRequest(
$target->getUrl() .
'/' .
$options['install_directory'] .
'/wp-admin/install.php?step=2',
[
'weblog_title' => $options['site_name'],
'user_name' => $options['username'],
'admin_password' => $options['password'],
'admin_password2' => $options['password'],
'admin_email' => $options['email'],
],
);
}
}