-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblueprint.php
141 lines (122 loc) · 3.17 KB
/
blueprint.php
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace inseri_core;
if (!function_exists('\plugins_api')) {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
}
if (!function_exists('themes_api')) {
require_once ABSPATH . 'wp-admin/includes/theme.php';
}
class Builder {
public $blueprint = [
'$schema' => 'https://playground.wordpress.net/blueprint-schema.json',
'preferredVersions' => [
'php' => '',
'wp' => '',
],
'features' => [
'networking' => true,
],
'phpExtensionBundles' => ['kitchen-sink'],
'landingPage' => '/wp-admin/',
'login' => true,
'steps' => [
[
'step' => 'runPHP',
'code' => "<?php include 'wordpress/wp-load.php'; wp_delete_post(1,true); ?>",
],
[
'step' => 'installPlugin',
'pluginZipFile' => [
'resource' => 'wordpress.org/plugins',
'slug' => 'wordpress-importer',
],
'options' => [
'activate' => true,
],
],
],
];
public function generate($steps) {
$php_version = explode('.', phpversion());
$this->blueprint['preferredVersions']['php'] = $php_version[0] . '.' . $php_version[1];
$wp_version = explode('.', get_bloginfo('version'));
$this->blueprint['preferredVersions']['wp'] = $wp_version[0] . '.' . $wp_version[1];
if (!is_numeric($wp_version[1])) {
$this->blueprint['preferredVersions']['wp'] = 'nightly';
}
if ($steps['theme'] ?? true) {
$this->add_theme_installations_steps();
}
if ($steps['plugins'] ?? true) {
$this->add_plugins_installations_steps();
}
return $this->blueprint;
}
protected function add_theme_installations_steps() {
$theme_object = wp_get_theme();
$version = $theme_object->get('Version');
$slug = $theme_object->get_template();
$data = \themes_api('theme_information', [
'slug' => $slug,
'fields' => [
'rating' => false,
'tags' => false,
'sections' => false,
'versions' => true,
],
]);
if ($data instanceof \WP_Error || !isset($data->versions[$version])) {
return;
}
$this->blueprint['steps'][] = [
'step' => 'installTheme',
'themeZipFile' => [
'resource' => 'url',
'url' => $data->versions[$version],
],
'options' => [
'activate' => true,
],
];
}
protected function add_plugins_installations_steps() {
foreach ($this->get_active_plugins() as $plugin) {
$this->blueprint['steps'][] = [
'step' => 'installPlugin',
'pluginZipFile' => [
'resource' => 'url',
'url' => $plugin['link'],
],
'options' => [
'activate' => true,
],
];
}
}
protected function get_active_plugins() {
$plugins = get_option('active_plugins');
$return_plugins = [];
foreach ($plugins as $plugin) {
$plugin_version = get_file_data(WP_PLUGIN_DIR . '/' . $plugin, ['Version'], 'plugin')[0];
$slug = explode('/', $plugin)[0];
$data = \plugins_api('plugin_information', [
'slug' => $slug,
'fields' => [
'rating' => false,
'tags' => false,
'sections' => false,
'contributors' => false,
'versions' => true,
],
]);
if ($data instanceof \WP_Error || !isset($data->versions[$plugin_version])) {
continue;
}
$return_plugins[] = [
'slug' => $slug,
'link' => $data->versions[$plugin_version],
];
}
return $return_plugins;
}
}