PluginProbe
404 Solution / 4.1.13
404 Solution v4.1.13
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.1.13, at uninstall.php

107 lines 3.9 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/Uninstaller.php';
34
35 // Get saved preferences from the uninstall modal
36 // Use site option for network-activated plugins, regular option for single-site
37 $option_name = 'abj404_uninstall_preferences';
38 $preferences = false;
39
40 if (is_multisite()) {
41 // Check if the plugin is network-activated
42 if (!function_exists('is_plugin_active_for_network')) {
43 require_once ABSPATH . 'wp-admin/includes/plugin.php';
44 }
45
46 $plugin_file = '404-solution/404-solution.php';
47 $is_network_active = is_plugin_active_for_network($plugin_file);
48
49 if ($is_network_active) {
50 // Network-activated: Get from site options
51 $preferences = get_site_option($option_name);
52 } else {
53 // Site-specific activation: Get from regular options
54 $preferences = get_option($option_name);
55 }
56 } else {
57 // Single-site: Get from regular options
58 $preferences = get_option($option_name);
59 }
60
61 // If no preferences were saved, use safe defaults
62 // This happens if user deleted plugin without using the modal
63 if (false === $preferences || !is_array($preferences)) {
64 $preferences = array(
65 'delete_redirects' => false, // Default: KEEP redirects (user might reinstall)
66 'delete_logs' => false, // Default: KEEP logs (historical data)
67 'delete_cache' => true, // Default: DELETE cache (can be rebuilt)
68 'send_feedback' => false, // Default: Don't send feedback
69 'uninstall_reason' => '',
70 'feedback_email' => '',
71 'feedback_details' => ''
72 );
73 }
74
75 // Delete the preferences (cleanup)
76 if (is_multisite() && $is_network_active) {
77 delete_site_option($option_name);
78 } else {
79 delete_option($option_name);
80 }
81
82 // Handle both single-site and multisite installations
83 if (is_multisite()) {
84 // Check if the plugin is network-activated
85 // Only run network-wide uninstall if it was activated network-wide
86 if (!function_exists('is_plugin_active_for_network')) {
87 require_once ABSPATH . 'wp-admin/includes/plugin.php';
88 }
89
90 // Determine the plugin file path relative to plugins directory
91 $plugin_file = '404-solution/404-solution.php';
92 $is_network_active = is_plugin_active_for_network($plugin_file);
93
94 if ($is_network_active) {
95 // Network-activated: Uninstall from all sites in the network
96 ABJ_404_Solution_Uninstaller::multisite_uninstall($preferences);
97 } else {
98 // Single-site activation: Only uninstall from current site
99 ABJ_404_Solution_Uninstaller::uninstall($preferences);
100 }
101 } else {
102 // Single site installation: Standard uninstall
103 ABJ_404_Solution_Uninstaller::uninstall($preferences);
104 }
105
106 // All done! WordPress will now delete the plugin files.
107