PluginProbe
404 Solution / 4.3.3
404 Solution v4.3.3
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / uninstall.php

uninstall.php in 404 Solution 4.3.3, at uninstall.php

109 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uninstall handler for 404 Solution plugin
4 *
5 * This file is triggered when the plugin is deleted via WordPress admin.
6 * It handles cleanup of database tables, options, and cron jobs based on
7 * user preferences saved from the uninstall modal.
8 *
9 * @package 404Solution
10 * @since 2.36.11
11 */
12
13 // Security: Ensure this file is called by WordPress during uninstall
14 // WordPress core enforces the 'delete_plugins' capability in wp-admin/plugins.php
15 // before this file is ever reached, so no additional permission checks are needed.
16 // The WP_UNINSTALL_PLUGIN constant check prevents direct file access and is the
17 // WordPress-recommended security pattern per the Plugin Handbook.
18 if (!defined('WP_UNINSTALL_PLUGIN')) {
19 exit;
20 }
21
22 // Additional security: Verify user has permission to delete plugins
23 // Allow WP-CLI and other automated contexts where current_user_can() returns false
24 if (!defined('WP_CLI') && !current_user_can('activate_plugins')) {
25 exit;
26 }
27
28 // Read version from main plugin file header (single source of truth)
29 $plugin_data = get_file_data(__DIR__ . '/404-solution.php', array('Version' => 'Version'));
30 define('ABJ404_VERSION', $plugin_data['Version']);
31
32 // Load the Uninstaller class
33 require_once __DIR__ . '/includes/uninstall/Uninstaller.php';
34 require_once __DIR__ . '/includes/settings/StorageOptionContracts.php';
35
36 // Get saved preferences from the uninstall modal
37 // Use site option for network-activated plugins, regular option for single-site
38 $option_name = 'abj404_uninstall_preferences';
39 $preferences = false;
40
41 if (is_multisite()) {
42 // Check if the plugin is network-activated
43 if (!function_exists('is_plugin_active_for_network')) {
44 require_once ABSPATH . 'wp-admin/includes/plugin.php';
45 }
46
47 $plugin_file = '404-solution/404-solution.php';
48 $is_network_active = is_plugin_active_for_network($plugin_file);
49
50 if ($is_network_active) {
51 // Network-activated: Get from site options
52 $preferences = get_site_option($option_name);
53 } else {
54 // Site-specific activation: Get from regular options
55 $preferences = get_option($option_name);
56 }
57 } else {
58 // Single-site: Get from regular options
59 $preferences = get_option($option_name);
60 }
61
62 // If no preferences were saved, use safe defaults
63 // This happens if user deleted plugin without using the modal
64 if (false === $preferences || !is_array($preferences)) {
65 $preferences = array(
66 'delete_redirects' => false, // Default: KEEP redirects (user might reinstall)
67 'delete_logs' => false, // Default: KEEP logs (historical data)
68 'delete_cache' => true, // Default: DELETE cache (can be rebuilt)
69 'send_feedback' => false, // Default: Don't send feedback
70 'uninstall_reason' => '',
71 'feedback_email' => '',
72 'feedback_details' => ''
73 );
74 }
75 $preferences = ABJ_404_Solution_StorageOptionContracts::normalizeForRead($option_name, $preferences);
76
77 // Delete the preferences (cleanup)
78 if (is_multisite() && $is_network_active) {
79 delete_site_option($option_name);
80 } else {
81 delete_option($option_name);
82 }
83
84 // Handle both single-site and multisite installations
85 if (is_multisite()) {
86 // Check if the plugin is network-activated
87 // Only run network-wide uninstall if it was activated network-wide
88 if (!function_exists('is_plugin_active_for_network')) {
89 require_once ABSPATH . 'wp-admin/includes/plugin.php';
90 }
91
92 // Determine the plugin file path relative to plugins directory
93 $plugin_file = '404-solution/404-solution.php';
94 $is_network_active = is_plugin_active_for_network($plugin_file);
95
96 if ($is_network_active) {
97 // Network-activated: Uninstall from all sites in the network
98 ABJ_404_Solution_Uninstaller::multisite_uninstall($preferences);
99 } else {
100 // Single-site activation: Only uninstall from current site
101 ABJ_404_Solution_Uninstaller::uninstall($preferences);
102 }
103 } else {
104 // Single site installation: Standard uninstall
105 ABJ_404_Solution_Uninstaller::uninstall($preferences);
106 }
107
108 // All done! WordPress will now delete the plugin files.
109