wp-staging
Last commit date
Backend
1 year ago
Backup
1 year ago
Basic
1 year ago
Core
1 year ago
Duplicator
2 years ago
Framework
1 year ago
Frontend
2 years ago
Notifications
1 year ago
assets
1 year ago
languages
3 years ago
vendor_wpstg
1 year ago
CONTRIBUTING.md
1 year ago
Deactivate.php
2 years ago
README.md
1 year ago
SECURITY.md
2 years ago
autoloader.php
3 years ago
bootstrap.php
2 years ago
constantsFree.php
1 year ago
freeBootstrap.php
2 years ago
install.php
2 years ago
opcacheBootstrap.php
1 year ago
readme.txt
1 year ago
runtimeRequirements.php
2 years ago
uninstall.php
2 years ago
wp-staging-error-handler.php
2 years ago
wp-staging.php
1 year ago
Deactivate.php
105 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging; |
| 4 | |
| 5 | /** |
| 6 | * Actions to perform when we deactivate WP Staging Plugin |
| 7 | */ |
| 8 | class Deactivate |
| 9 | { |
| 10 | /** |
| 11 | * @var string |
| 12 | */ |
| 13 | private $currentPluginFile; |
| 14 | |
| 15 | /** |
| 16 | * @param string $currentPluginFile |
| 17 | */ |
| 18 | public function __construct($currentPluginFile) |
| 19 | { |
| 20 | $this->currentPluginFile = $currentPluginFile; |
| 21 | |
| 22 | // Early bail |
| 23 | // This filter hook is for internal use only |
| 24 | if (apply_filters('wpstg.deactivation_hook.skip_mu_delete', false)) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | // Only delete MU plugin when no other wp staging plugin is activated |
| 29 | if (!$this->isOtherWPStagingPluginActivated()) { |
| 30 | $this->deleteMuPlugin(); |
| 31 | } |
| 32 | |
| 33 | $this->deleteBackupSchedulesFromCron(); |
| 34 | $this->deleteOtherCron(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Check if any other WP Staging Plugin is activated other than current one |
| 39 | * |
| 40 | * @return boolean |
| 41 | */ |
| 42 | private function isOtherWPStagingPluginActivated() |
| 43 | { |
| 44 | foreach (wp_get_active_and_valid_plugins() as $activePlugin) { |
| 45 | if ($activePlugin === $this->currentPluginFile) { |
| 46 | continue; |
| 47 | } |
| 48 | |
| 49 | if (strpos($activePlugin, 'wp-staging.php') !== false || strpos($activePlugin, 'wp-staging-pro.php') !== false) { |
| 50 | return true; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * delete MuPlugin |
| 59 | */ |
| 60 | private function deleteMuPlugin() |
| 61 | { |
| 62 | $muDir = (defined('WPMU_PLUGIN_DIR')) ? WPMU_PLUGIN_DIR : trailingslashit(WP_CONTENT_DIR) . 'mu-plugins'; |
| 63 | $dest = trailingslashit($muDir) . 'wp-staging-optimizer.php'; |
| 64 | |
| 65 | if (file_exists($dest) && !unlink($dest)) { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | protected function deleteBackupSchedulesFromCron() |
| 73 | { |
| 74 | if (!file_exists(__DIR__ . '/Backup/BackupScheduler.php')) { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | if (!class_exists('\WPStaging\Backup\BackupScheduler')) { |
| 79 | require_once __DIR__ . '/Backup/BackupScheduler.php'; |
| 80 | } |
| 81 | |
| 82 | \WPStaging\Backup\BackupScheduler::removeBackupSchedulesFromCron(); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * delete Other Cron |
| 87 | */ |
| 88 | private function deleteOtherCron() |
| 89 | { |
| 90 | $hooks = [ |
| 91 | 'wpstg_q_ajax_support_feature_detection', |
| 92 | 'wpstg_queue_maintain', |
| 93 | 'wpstg_queue_process', |
| 94 | 'wpstg_weekly_event', |
| 95 | 'wpstg_daily_event' |
| 96 | ]; |
| 97 | |
| 98 | foreach ($hooks as $hook) { |
| 99 | if (wp_get_schedule($hook)) { |
| 100 | wp_clear_scheduled_hook($hook); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 |