PluginProbe
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.12.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.12.0
4.12.0 4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 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 All 67 releases
wp-staging / Deactivate.php
Deactivate.php
123 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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