PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.1.1
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.1.1
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 / runtimeRequirements.php
wp-staging Last commit date
Backend 2 years ago Backup 2 years ago Basic 2 years ago Core 2 years ago Framework 2 years ago Frontend 2 years ago assets 2 years ago languages 3 years ago vendor_wpstg 2 years ago Deactivate.php 2 years ago README.md 3 years ago autoloader.php 3 years ago bootstrap.php 2 years ago constantsFree.php 2 years ago freeBootstrap.php 2 years ago install.php 2 years ago opcacheBootstrap.php 2 years ago readme.txt 2 years ago runtimeRequirements.php 2 years ago uninstall.php 2 years ago wp-staging-error-handler.php 3 years ago wp-staging.php 2 years ago
runtimeRequirements.php
379 lines
1 <?php
2
3 /**
4 * @var string $pluginFilePath The absolute path to the main file of this plugin.
5 */
6 // TODO: refactor this and implement our own methods to get rid of hard loading wp core functions which is not recommended by WP.
7 require_once(trailingslashit(ABSPATH) . 'wp-admin/includes/plugin.php');
8
9 if (!defined('WPSTGPRO_MINIMUM_FREE_VERSION')) {
10 /** Expected version number of the free plugin in order to activate it at the same time with pro */
11 define('WPSTGPRO_MINIMUM_FREE_VERSION', '3.1.0');
12 }
13
14 if (!defined('WPSTG_FREE_VERSION_PLUGIN_FILE')) {
15 define('WPSTG_FREE_VERSION_PLUGIN_FILE', 'wp-staging.php');
16 }
17
18 if (!defined('WPSTG_PRO_VERSION_PLUGIN_FILE')) {
19 define('WPSTG_PRO_VERSION_PLUGIN_FILE', 'wp-staging-pro.php');
20 }
21
22 if (!function_exists('wpstgIsProPluginActive')) {
23 /**
24 * @return bool
25 */
26 function wpstgIsProPluginActive(): bool
27 {
28 return wpstgIsPluginActivated(WPSTG_PRO_VERSION_PLUGIN_FILE);
29 }
30 }
31
32 if (!function_exists('wpstgIsProPluginActiveInNetwork')) {
33 /**
34 * @return bool
35 */
36 function wpstgIsProPluginActiveInNetwork(): bool
37 {
38 return wpstgIsPluginActiveInNetwork(WPSTG_PRO_VERSION_PLUGIN_FILE);
39 }
40 }
41
42 if (!function_exists('wpstgIsProActiveInNetworkOrInCurrentSite')) {
43 /**
44 * @return bool
45 */
46 function wpstgIsProActiveInNetworkOrInCurrentSite(): bool
47 {
48 return wpstgIsProPluginActiveInNetwork() || wpstgIsProPluginActive();
49 }
50 }
51
52 if (!function_exists('wpstgIsFreeVersionActive')) {
53 /**
54 * @return bool
55 */
56 function wpstgIsFreeVersionActive(): bool
57 {
58 return wpstgIsPluginActivated(WPSTG_FREE_VERSION_PLUGIN_FILE);
59 }
60 }
61
62 if (!function_exists('wpstgIsFreeVersionActiveInNetwork')) {
63 /**
64 * @return bool
65 */
66 function wpstgIsFreeVersionActiveInNetwork(): bool
67 {
68 return wpstgIsPluginActiveInNetwork(WPSTG_FREE_VERSION_PLUGIN_FILE);
69 }
70 }
71
72 if (!function_exists('wpstgIsFreeActiveInNetworkOrCurrentSite')) {
73 /**
74 * @return bool
75 */
76 function wpstgIsFreeActiveInNetworkOrCurrentSite(): bool
77 {
78 return wpstgIsFreeVersionActiveInNetwork() || wpstgIsFreeVersionActive();
79 }
80 }
81
82 if (!function_exists('wpstgGetPluginSlug')) {
83 /**
84 * @param string $pluginFileName
85 *
86 * @return bool|string false if plugin is not installed otherwise return the plugin slug/basename.
87 */
88 function wpstgGetPluginSlug(string $pluginFileName)
89 {
90 $allPlugins = get_plugins();
91 foreach ($allPlugins as $key => $value) {
92 if (strpos($key, $pluginFileName) !== false) {
93 return $key;
94 }
95 }
96
97 return false;
98 }
99 }
100
101 if (!function_exists('wpstgGetPluginData')) {
102 /**
103 * @param string $pluginFileName
104 *
105 * @return array
106 */
107 function wpstgGetPluginData(string $pluginFileName): array
108 {
109 $allPlugins = get_plugins();
110 foreach ($allPlugins as $key => $value) {
111 if (strpos($key, $pluginFileName) !== false) {
112 return $value;
113 }
114 }
115
116 return [];
117 }
118 }
119
120 if (!function_exists('wpstgGetFreeVersionNumberIfInstalled')) {
121 /**
122 * @return string returns empty string if free is not installed.
123 */
124 function wpstgGetFreeVersionNumberIfInstalled(): string
125 {
126 $freeData = wpstgGetPluginData(WPSTG_FREE_VERSION_PLUGIN_FILE);
127 $installedFreeVersionNumber = isset($freeData['Version']) ? $freeData['Version'] : '';
128
129 return $installedFreeVersionNumber;
130 }
131 }
132
133 if (!function_exists('wpstgIsFreeVersionCompatible')) {
134 /**
135 * @return bool
136 */
137 function wpstgIsFreeVersionCompatible(): bool
138 {
139 return defined('WPSTGPRO_MINIMUM_FREE_VERSION') && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '>=');
140 }
141 }
142
143 if (!function_exists('wpstgIsFreeActiveButOutdated')) {
144 /**
145 * @return bool
146 */
147 function wpstgIsFreeActiveButOutdated(): bool
148 {
149 if (wpstgIsFreeActiveInNetworkOrCurrentSite() && !wpstgIsFreeVersionCompatible()) {
150 return true;
151 }
152
153 return false;
154 }
155 }
156
157 if (!function_exists('wpstgDeactivatePlugin')) {
158 /**
159 * @param mixed $pluginFilePath
160 * @return void
161 */
162 function wpstgDeactivatePlugin($pluginFilePath)
163 {
164 if (is_network_admin()) {
165 deactivate_plugins($pluginFilePath, false, true);
166 } else {
167 deactivate_plugins($pluginFilePath);
168 }
169 }
170 }
171
172 if (!function_exists('wpstgCanShowAnotherInstanceRunningNotice')) {
173 /**
174 * @param string $pluginFilePath
175 * @return bool
176 */
177 function wpstgCanShowAnotherInstanceRunningNotice(string $pluginFilePath): bool
178 {
179 if (!current_user_can('activate_plugins')) {
180 return false;
181 }
182
183 if (strpos($pluginFilePath, 'wp-staging-pro.php') !== false && wpstgIsProActiveInNetworkOrInCurrentSite() && !wpstgIsFreeActiveInNetworkOrCurrentSite()) {
184 return true;
185 }
186
187 if (strpos($pluginFilePath, 'wp-staging.php') !== false && !wpstgIsProActiveInNetworkOrInCurrentSite() && wpstgIsFreeActiveInNetworkOrCurrentSite()) {
188 return true;
189 }
190
191 return false;
192 }
193 }
194
195 if (!function_exists('wpstgCanThrowAnotherInstanceLoadedException')) {
196 /**
197 * @return bool
198 */
199 function wpstgCanThrowAnotherInstanceLoadedException(): bool
200 {
201 if (defined('WPSTG_VERSION') && version_compare(WPSTG_VERSION, WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
202 return true;
203 }
204
205 if (defined('WPSTGPRO_VERSION') && version_compare(WPSTGPRO_VERSION, '5.1.0', '<')) {
206 return true;
207 }
208
209 if (!wpstgIsProActiveInNetworkOrInCurrentSite()) {
210 return true;
211 }
212
213 return false;
214 }
215 }
216
217 if (!function_exists('wpstgIsPluginActivated')) {
218 /**
219 * This function checks if a plugin is activated on single site.
220 *
221 * @param string $pluginFileName
222 *
223 * @return bool
224 */
225 function wpstgIsPluginActivated(string $pluginFileName): bool
226 {
227 $activePlugins = wp_get_active_and_valid_plugins();
228 foreach ($activePlugins as $sitewidePlugin) {
229 if (strpos($sitewidePlugin, $pluginFileName) !== false) {
230 return true;
231 }
232 }
233
234 return false;
235 }
236 }
237
238 if (!function_exists('wpstgIsPluginActiveInNetwork')) {
239 /**
240 * @param string $pluginFileName
241 *
242 * @return bool
243 */
244 function wpstgIsPluginActiveInNetwork(string $pluginFileName): bool
245 {
246 if (!is_multisite()) {
247 return false;
248 }
249
250 $activePlugins = wp_get_active_network_plugins();
251 foreach ($activePlugins as $sitewidePlugin) {
252 if (strpos($sitewidePlugin, $pluginFileName) !== false) {
253 return true;
254 }
255 }
256
257 return false;
258 }
259 }
260
261 if (!function_exists('wpstgDoLoadPluginAutoLoad')) {
262 /**
263 * @param string $pluginFilePath
264 * @return void
265 */
266 function wpstgDoLoadPluginAutoLoad(string $pluginFilePath): bool
267 {
268 if (class_exists('\WPStaging\Core\WPStaging')) {
269 return false;
270 }
271
272 if (strpos($pluginFilePath, 'wp-staging.php') === false) {
273 return true;
274 }
275
276 if (strpos($pluginFilePath, 'wp-staging.php') !== false && (!is_network_admin() && !wpstgIsProPluginActive())) {
277 return true;
278 }
279
280 if (strpos($pluginFilePath, 'wp-staging.php') !== false && (is_network_admin() && !wpstgIsProPluginActiveInNetwork())) {
281 return true;
282 }
283
284 return false;
285 }
286 }
287
288 /**
289 * Early bail: Deactivate outdated free version.
290 */
291 if (strpos($pluginFilePath, 'wp-staging-pro.php') !== false && wpstgIsFreeActiveButOutdated()) {
292 // Deactivate free plugin.
293 $pluginSlug = wpstgGetPluginSlug(WPSTG_FREE_VERSION_PLUGIN_FILE);
294 wpstgDeactivatePlugin($pluginSlug);
295 }
296
297 /**
298 * Early bail: Activating another WPSTAGING Plugin.
299 * This is the only scenario where the plugin would be included after "plugins_loaded",
300 * therefore we need to detect earlier, from the context of the request, whether this is going to happen,
301 * to disable this plugin early and bail the bootstrap process to not conflict with the one being activated.
302 *
303 * Covers both clicking on the "Activate" button and selecting the "Activate" bulk-action.
304 */
305 if (isset($_REQUEST['action'])) {
306 switch ($_REQUEST['action']) :
307 case 'activate':
308 case 'error_scrape':
309 if (isset($_REQUEST['plugin'])) {
310 $plugin = (string)wp_unslash(sanitize_text_field($_REQUEST['plugin']));
311
312 $isActivatingWpStaging = strpos($plugin, 'wp-staging.php') || strpos($plugin, 'wp-staging-pro.php');
313 $isActivatingAnotherWpStaging = plugin_basename($plugin) !== plugin_basename($pluginFilePath);
314
315 if ($isActivatingWpStaging && $isActivatingAnotherWpStaging && current_user_can('deactivate_plugin', plugin_basename($pluginFilePath))) {
316 throw new Exception("Activating another WPSTAGING Plugin. Plugin that bailed bootstrapping: $pluginFilePath");
317 }
318 }
319 break;
320 case 'activate-selected':
321 case 'activate-multi':
322 if (isset($_REQUEST['checked'])) {
323 $plugins = array_map('sanitize_text_field', (array)wp_unslash($_REQUEST['checked']));
324
325 foreach ($plugins as $i => $plugin) {
326 $isActivatingWpStaging = strpos($plugin, 'wp-staging.php') || strpos($plugin, 'wp-staging-pro.php');
327 $isActivatingAnotherWpStaging = plugin_basename($plugin) !== plugin_basename($pluginFilePath);
328
329 if ($isActivatingWpStaging && $isActivatingAnotherWpStaging && current_user_can('deactivate_plugin', plugin_basename($pluginFilePath))) {
330 throw new Exception("Activating another WPSTAGING Plugin. Plugin that bailed bootstrapping: $pluginFilePath");
331 }
332 }
333 }
334 break;
335 endswitch;
336 }
337
338 /**
339 * Early bail: Another instance of WPSTAGING active.
340 */
341 if (
342 // WPSTAGING <= 2.7.5
343 class_exists('\WPStaging\WPStaging') ||
344 // WPSTAGING >= 2.7.6
345 class_exists('\WPStaging\Core\WPStaging')
346 ) {
347 if (wpstgCanShowAnotherInstanceRunningNotice($pluginFilePath)) {
348 add_action(is_network_admin() ? 'network_admin_notices' : 'admin_notices', function () { // phpcs:ignore WPStaging.Security.FirstArgNotAString, WPStaging.Security.AuthorizationChecked
349 echo '<div class="notice-warning notice is-dismissible another-wpstaging-active">';
350 echo '<p style="font-weight: bold;">' . esc_html__('WP STAGING Already Active', 'wp-staging') . '</p>';
351 echo '<p>' . esc_html__('Another WP STAGING is already activated, please leave only one instance of the WP STAGING plugin active at the same time.', 'wp-staging') . '</p>';
352 echo '</div>';
353 });
354 }
355
356 if (!wpstgCanThrowAnotherInstanceLoadedException()) {
357 return;
358 }
359
360 throw new Exception("Another instance of WPSTAGING active. Plugin that bailed bootstrapping: $pluginFilePath");
361 }
362
363 /**
364 * Early bail: Unsupported WordPress version.
365 * We check on runtime instead of activation so we can display the notice.
366 */
367 if (!version_compare($currentWordPressVersion = (string)get_bloginfo('version'), $minimumWordPressVersion = '4.4', '>=')) {
368 if (current_user_can('activate_plugins')) {
369 add_action(is_network_admin() ? 'network_admin_notices' : 'admin_notices', function () use ($currentWordPressVersion, $minimumWordPressVersion) { // phpcs:ignore WPStaging.Security.FirstArgNotAString, WPStaging.Security.AuthorizationChecked
370 echo '<div class="notice-warning notice is-dismissible">';
371 echo '<p style="font-weight: bold;">' . esc_html__('WP STAGING', 'wp-staging') . '</p>';
372 echo '<p>' . sprintf(esc_html__('WP STAGING requires at least WordPress %s to run. You have WordPress %s.', 'wp-staging'), esc_html($minimumWordPressVersion), esc_html($currentWordPressVersion)) . '</p>';
373 echo '</div>';
374 });
375 }
376
377 throw new Exception("Unsupported WordPress version. Plugin that bailed bootstrapping: $pluginFilePath");
378 }
379