wp-staging
Last commit date
Backend
1 day ago
Backup
1 day ago
Basic
1 day ago
Component
1 day ago
Core
1 day ago
Framework
1 day ago
Frontend
1 day ago
Notifications
1 day ago
Staging
1 day ago
assets
1 day ago
languages
1 day ago
resources
1 day ago
vendor_wpstg
1 day ago
views
1 day ago
CONTRIBUTING.md
2 years ago
Deactivate.php
1 day ago
README.md
5 months ago
SECURITY.md
3 weeks ago
autoloader.php
1 day ago
bootstrap.php
1 day ago
commonBootstrap.php
1 day ago
constantsFree.php
1 day ago
freeBootstrap.php
1 day ago
install.php
1 day ago
opcacheBootstrap.php
1 day ago
readme.txt
1 day ago
runtimeRequirements.php
1 day ago
uninstall.php
1 day ago
wp-staging-error-handler.php
1 day ago
wp-staging.php
1 day ago
Deactivate.php
123 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging; |
| 4 | |
| 5 | use WPStaging\Core\Cron\Cron; |
| 6 | use WPStaging\Framework\Analytics\Actions\PluginLifecycle; |
| 7 | use WPStaging\Framework\BackgroundProcessing\BackgroundProcessingServiceProvider; |
| 8 | use WPStaging\Framework\BackgroundProcessing\FeatureDetection; |
| 9 | use WPStaging\Framework\BackgroundProcessing\QueueProcessor; |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | class Deactivate |
| 15 | { |
| 16 | |
| 17 | |
| 18 | |
| 19 | private $currentPluginFile; |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | public function __construct($currentPluginFile) |
| 25 | { |
| 26 | $this->currentPluginFile = $currentPluginFile; |
| 27 | |
| 28 | |
| 29 | |
| 30 | if (apply_filters('wpstg.deactivation_hook.skip_mu_delete', false)) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | PluginLifecycle::recordDeactivation(); |
| 40 | |
| 41 | |
| 42 | if (!$this->isOtherWPStagingPluginActivated()) { |
| 43 | $this->deleteMuPlugin(); |
| 44 | } |
| 45 | |
| 46 | $this->deleteBackupSchedulesFromCron(); |
| 47 | $this->deleteOtherCron(); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | private function isOtherWPStagingPluginActivated() |
| 56 | { |
| 57 | foreach (wp_get_active_and_valid_plugins() as $activePlugin) { |
| 58 | if ($activePlugin === $this->currentPluginFile) { |
| 59 | continue; |
| 60 | } |
| 61 | |
| 62 | if (strpos($activePlugin, 'wp-staging.php') !== false || strpos($activePlugin, 'wp-staging-pro.php') !== false) { |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | private function deleteMuPlugin() |
| 74 | { |
| 75 | $muDir = (defined('WPMU_PLUGIN_DIR')) ? WPMU_PLUGIN_DIR : trailingslashit(WP_CONTENT_DIR) . 'mu-plugins'; |
| 76 | $dest = trailingslashit($muDir) . 'wp-staging-optimizer.php'; |
| 77 | |
| 78 | if (file_exists($dest) && !unlink($dest)) { |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | protected function deleteBackupSchedulesFromCron() |
| 86 | { |
| 87 | if (!file_exists(__DIR__ . '/Backup/BackupScheduler.php')) { |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | if (!class_exists('\WPStaging\Backup\BackupScheduler')) { |
| 92 | require_once __DIR__ . '/Backup/BackupScheduler.php'; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | if (!class_exists('\WPStaging\Core\Cron\Cron')) { |
| 97 | require_once __DIR__ . '/Core/Cron/Cron.php'; |
| 98 | } |
| 99 | |
| 100 | \WPStaging\Backup\BackupScheduler::removeBackupSchedulesFromCron(); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | private function deleteOtherCron() |
| 107 | { |
| 108 | $hooks = [ |
| 109 | FeatureDetection::ACTION_AJAX_SUPPORT_FEATURE_DETECTION, |
| 110 | BackgroundProcessingServiceProvider::ACTION_QUEUE_MAINTAIN, |
| 111 | QueueProcessor::ACTION_QUEUE_PROCESS, |
| 112 | Cron::ACTION_WEEKLY_EVENT, |
| 113 | Cron::ACTION_DAILY_EVENT, |
| 114 | ]; |
| 115 | |
| 116 | foreach ($hooks as $hook) { |
| 117 | if (wp_get_schedule($hook)) { |
| 118 | wp_clear_scheduled_hook($hook); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 |