PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / trunk
WP STAGING – WordPress Backup, Restore, Migration & Clone vtrunk
4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Staging / Service / AbstractStagingSetup.php
wp-staging / Staging / Service Last commit date
Database 1 week ago AbstractStagingSetup.php 1 week ago DirectoryScanner.php 1 week ago FileCopier.php 1 week ago LegacyOptionsCache.php 1 week ago StagingEngine.php 1 week ago StagingSetup.php 1 week ago TableScanner.php 1 week ago
AbstractStagingSetup.php
274 lines
1 <?php
2
3 namespace WPStaging\Staging\Service;
4
5 use WPStaging\Backend\Modules\SystemInfo;
6 use WPStaging\Framework\Assets\Assets;
7 use WPStaging\Framework\TemplateEngine\TemplateEngine;
8 use WPStaging\Framework\Utils\WpDefaultDirectories;
9 use WPStaging\Staging\Dto\StagingSiteDto;
10
11 /**
12 * @package WPStaging\Staging\Service
13 */
14 abstract class AbstractStagingSetup
15 {
16 /** @var string */
17 const JOB_NEW_STAGING_SITE = 'new';
18
19 /** @var string */
20 const JOB_UPDATE = 'update';
21
22 /** @var string */
23 const JOB_RESET = 'reset';
24
25 /** @var string */
26 const JOB_PUSH = 'push';
27
28 /**
29 * @var StagingSiteDto
30 */
31 protected $stagingSiteDto;
32
33 /**
34 * @var TemplateEngine
35 */
36 protected $templateEngine;
37
38 /**
39 * @var bool
40 */
41 protected $openDisabledSettingsSectionByDefault = true;
42
43 /**
44 * @var string
45 */
46 protected $stagingJob;
47
48 /**
49 * @var string
50 */
51 private $infoIcon;
52
53 /**
54 * @var WpDefaultDirectories
55 */
56 private $wpDefaultDirectories;
57
58 public function __construct(TemplateEngine $templateEngine, Assets $assets, WpDefaultDirectories $wpDefaultDirectories)
59 {
60 $this->templateEngine = $templateEngine;
61 $this->infoIcon = $assets->getAssetsUrl('svg/info-outline.svg');
62 $this->wpDefaultDirectories = $wpDefaultDirectories;
63 }
64
65 /**
66 * @return void
67 */
68 public function initNewStagingSite()
69 {
70 $this->stagingJob = StagingSetup::JOB_NEW_STAGING_SITE;
71 $this->stagingSiteDto = new StagingSiteDto();
72 }
73
74 /**
75 * @param StagingSiteDto $stagingSiteDto
76 * @return void
77 */
78 public function initUpdateJob(StagingSiteDto $stagingSiteDto)
79 {
80 $this->stagingJob = StagingSetup::JOB_UPDATE;
81 $this->stagingSiteDto = $stagingSiteDto;
82 }
83
84 /**
85 * @param StagingSiteDto $stagingSiteDto
86 * @return void
87 */
88 public function initResetJob(StagingSiteDto $stagingSiteDto)
89 {
90 $this->stagingJob = StagingSetup::JOB_RESET;
91 $this->stagingSiteDto = $stagingSiteDto;
92 }
93
94 public function isNewStagingSite(): bool
95 {
96 return $this->stagingJob === StagingSetup::JOB_NEW_STAGING_SITE;
97 }
98
99 public function isUpdateJob(): bool
100 {
101 return $this->stagingJob === StagingSetup::JOB_UPDATE;
102 }
103
104 public function isResetJob(): bool
105 {
106 return $this->stagingJob === StagingSetup::JOB_RESET;
107 }
108
109 public function isPushJob(): bool
110 {
111 return $this->stagingJob === StagingSetup::JOB_PUSH;
112 }
113
114 public function isUpdateOrResetJob(): bool
115 {
116 return $this->isUpdateJob() || $this->isResetJob();
117 }
118
119 public function setStagingSiteDto(StagingSiteDto $stagingSiteDto)
120 {
121 $this->stagingSiteDto = $stagingSiteDto;
122 }
123
124 public function getStagingSiteDto(): StagingSiteDto
125 {
126 return $this->stagingSiteDto;
127 }
128
129 public function getRoot(): string
130 {
131 return wp_normalize_path(ABSPATH);
132 }
133
134 public function renderSettings(string $name, string $label, string $description, bool $checked = false, bool $disabled = false, string $additionalClasses = '', string $dataId = '', string $summary = '', string $content = '', string $tooltip = null)
135 {
136 $view = $this->templateEngine->render(
137 'staging/_partials/settings.php',
138 [
139 'name' => $name,
140 'label' => $label,
141 'description' => $description,
142 'summary' => $summary,
143 'checked' => $checked,
144 'disabled' => $disabled,
145 'classes' => $additionalClasses,
146 'dataId' => $dataId,
147 'infoIcon' => $this->infoIcon,
148 'content' => $content,
149 'tooltip' => $tooltip === null ? $description : $tooltip,
150 ]
151 );
152
153 echo $view; // phpcs:ignore
154 }
155
156 public function getSymlinkUploadDescription(): string
157 {
158 return sprintf(esc_html__('Activate to symlink the folder %s%s%s to the production site. %s All files including images on the production site\'s uploads folder will be linked to the staging site uploads folder. This will speed up the cloning and pushing process tremendously as no files from the uploads folder are copied between both sites. %s Warning: this can lead to mixed and shared content issues if both sites load (custom) stylesheet files from the same uploads folder. %s Using this option means changing images on the staging site will change images on the production site as well. Use this with care! %s', 'wp-staging'), '<code>', esc_html($this->wpDefaultDirectories->getRelativeUploadPath()), '</code>', '<br><br>', '<br><br><span class="wpstg--red">', '<br><br>', '</span>');
159 }
160
161 public function getCustomDirectoryDescription(): string
162 {
163 return $this->templateEngine->render(
164 'staging/setup/custom-directory-desc.php',
165 [
166 'systemInfo' => new SystemInfo(),
167 ]
168 );
169 }
170
171 public function getIsOpenDisabledSettingsSectionByDefault(): bool
172 {
173 return $this->openDisabledSettingsSectionByDefault;
174 }
175
176 /**
177 * Whether Pro advanced settings are unlocked at render time. True only on a
178 * Pro build with a valid/active (or local) license; the free build is always
179 * locked. Used to keep advanced settings disabled when a Pro install runs
180 * without a valid license.
181 *
182 * @return bool
183 */
184 public function isProLicenseActive(): bool
185 {
186 return false;
187 }
188
189 abstract public function renderNetworkCloneSettings();
190
191 abstract public function getAdvanceSettingsTitle(): string;
192
193 abstract public function renderAdvanceSettingsHeader();
194
195 abstract public function renderAdvanceSettings(string $name, string $label, string $description, bool $checked = false, string $additionalClasses = '', string $dataId = '', string $summary = '', string $content = '', string $tooltip = null);
196
197 abstract public function renderNewAdminSettings();
198
199 abstract public function renderExternalDatabaseSettings();
200
201 abstract public function renderCustomDirectorySettings();
202
203 abstract public function renderEnableWooSchedulerSettings();
204
205 protected function renderSettingsFields(array $fields)
206 {
207 foreach ($fields as $field) {
208 $type = $field['type'] ?? 'text';
209 if ($type === 'checkbox') {
210 $this->renderCheckbox(
211 $field['name'],
212 $field['label'],
213 $field['value'] ?? 'true',
214 $field['checked'] ?? false,
215 $field['disabled'] ?? false
216 );
217
218 continue;
219 }
220
221 $this->renderField(
222 $field['name'],
223 $field['label'],
224 $type,
225 $field['placeholder'] ?? '',
226 $field['description'] ?? '',
227 $field['disabled'] ?? false,
228 $field['autocapitalize'] ?? true,
229 $field['autocomplete'] ?? true
230 );
231 }
232 }
233
234 protected function renderField(string $name, string $label, string $type = 'text', string $placeholder = '', string $description = '', bool $disabled = false, bool $autocapitalize = true, bool $autocomplete = true)
235 {
236 $view = $this->templateEngine->render(
237 'staging/_partials/settings-field.php',
238 [
239 'name' => $name,
240 'label' => $label,
241 'type' => $type,
242 'placeholder' => $placeholder,
243 'description' => $description,
244 'disabled' => $disabled,
245 'autocapitalize' => $autocapitalize,
246 'autocomplete' => $autocomplete,
247 ]
248 );
249
250 if ($type === 'password') {
251 echo '<form>' . $view . '</form>'; // phpcs:ignore
252 return;
253 }
254
255 echo $view; // phpcs:ignore
256 }
257
258 protected function renderCheckbox(string $name, string $label, string $value, bool $checked = false, bool $disabled = false)
259 {
260 $view = $this->templateEngine->render(
261 'staging/_partials/settings-checkbox.php',
262 [
263 'name' => $name,
264 'label' => $label,
265 'value' => $value,
266 'checked' => $checked,
267 'disabled' => $disabled,
268 ]
269 );
270
271 echo $view; // phpcs:ignore
272 }
273 }
274