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