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
3 years ago
install.php
3 years ago
opcacheBootstrap.php
2 years ago
php56-compatibility.php
3 years ago
readme.txt
2 years ago
runtimeRequirements.php
2 years ago
uninstall.php
3 years ago
wp-staging-error-handler.php
3 years ago
wp-staging.php
2 years ago
runtimeRequirements.php
86 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @var string $pluginFilePath The absolute path to the main file of this plugin. |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * Early bail: Activating another WPSTAGING Plugin. |
| 9 | * This is the only scenario where the plugin would be included after "plugins_loaded", |
| 10 | * therefore we need to detect earlier, from the context of the request, whether this is going to happen, |
| 11 | * to disable this plugin early and bail the bootstrap process to not conflict with the one being activated. |
| 12 | * |
| 13 | * Covers both clicking on the "Activate" button and selecting the "Activate" bulk-action. |
| 14 | */ |
| 15 | |
| 16 | if (isset($_REQUEST['action'])) { |
| 17 | switch ($_REQUEST['action']) : |
| 18 | case 'activate': |
| 19 | case 'error_scrape': |
| 20 | if (isset($_REQUEST['plugin'])) { |
| 21 | $plugin = (string)wp_unslash(sanitize_text_field($_REQUEST['plugin'])); |
| 22 | |
| 23 | $isActivatingWpStaging = strpos($plugin, 'wp-staging.php') || strpos($plugin, 'wp-staging-pro.php'); |
| 24 | $isActivatingAnotherWpStaging = plugin_basename($plugin) !== plugin_basename($pluginFilePath); |
| 25 | |
| 26 | if ($isActivatingWpStaging && $isActivatingAnotherWpStaging && current_user_can('deactivate_plugin', plugin_basename($pluginFilePath))) { |
| 27 | throw new Exception("Activating another WPSTAGING Plugin. Plugin that bailed bootstrapping: $pluginFilePath"); |
| 28 | } |
| 29 | } |
| 30 | break; |
| 31 | case 'activate-selected': |
| 32 | case 'activate-multi': |
| 33 | if (isset($_REQUEST['checked'])) { |
| 34 | $plugins = array_map('sanitize_text_field', (array)wp_unslash($_REQUEST['checked'])); |
| 35 | |
| 36 | foreach ($plugins as $i => $plugin) { |
| 37 | $isActivatingWpStaging = strpos($plugin, 'wp-staging.php') || strpos($plugin, 'wp-staging-pro.php'); |
| 38 | $isActivatingAnotherWpStaging = plugin_basename($plugin) !== plugin_basename($pluginFilePath); |
| 39 | |
| 40 | if ($isActivatingWpStaging && $isActivatingAnotherWpStaging && current_user_can('deactivate_plugin', plugin_basename($pluginFilePath))) { |
| 41 | throw new Exception("Activating another WPSTAGING Plugin. Plugin that bailed bootstrapping: $pluginFilePath"); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | break; |
| 46 | endswitch; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Early bail: Another instance of WPSTAGING active. |
| 51 | */ |
| 52 | if ( |
| 53 | // WPSTAGING <= 2.7.5 |
| 54 | class_exists('\WPStaging\WPStaging') || |
| 55 | // WPSTAGING >= 2.7.6 |
| 56 | class_exists('\WPStaging\Core\WPStaging') |
| 57 | ) { |
| 58 | if (current_user_can('activate_plugins')) { |
| 59 | add_action(is_network_admin() ? 'network_admin_notices' : 'admin_notices', function () { // phpcs:ignore WPStaging.Security.FirstArgNotAString, WPStaging.Security.AuthorizationChecked |
| 60 | echo '<div class="notice-warning notice is-dismissible another-wpstaging-active">'; |
| 61 | echo '<p style="font-weight: bold;">' . esc_html__('WP STAGING Already Active', 'wp-staging') . '</p>'; |
| 62 | 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>'; |
| 63 | echo '</div>'; |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | throw new Exception("Another instance of WPSTAGING active. Plugin that bailed bootstrapping: $pluginFilePath"); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Early bail: Unsupported WordPress version. |
| 72 | * We check on runtime instead of activation so we can display the notice. |
| 73 | */ |
| 74 | if (!version_compare($currentWordPressVersion = get_bloginfo('version'), $minimumWordPressVersion = '4.4', '>=')) { |
| 75 | if (current_user_can('activate_plugins')) { |
| 76 | add_action(is_network_admin() ? 'network_admin_notices' : 'admin_notices', function () use ($currentWordPressVersion, $minimumWordPressVersion) { // phpcs:ignore WPStaging.Security.FirstArgNotAString, WPStaging.Security.AuthorizationChecked |
| 77 | echo '<div class="notice-warning notice is-dismissible">'; |
| 78 | echo '<p style="font-weight: bold;">' . esc_html__('WP STAGING', 'wp-staging') . '</p>'; |
| 79 | 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>'; |
| 80 | echo '</div>'; |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | throw new Exception("Unsupported WordPress version. Plugin that bailed bootstrapping: $pluginFilePath"); |
| 85 | } |
| 86 |