wp_create_nonce('abj404_uninstall_nonce'), 'pluginSlug' => self::getPluginSlug(), 'redirectCount' => $redirectCount )); // Custom CSS for modal styling wp_add_inline_style('wp-jquery-ui-dialog', ' .abj404-uninstall-dialog .ui-dialog-titlebar { background: #d63638; color: white; } .abj404-uninstall-dialog .ui-dialog-titlebar-close { color: white; } .abj404-uninstall-dialog .ui-dialog-titlebar-close:hover { background: #b32d2e; } .abj404-uninstall-dialog .button-danger { background: #d63638; border-color: #d63638; color: white; } .abj404-uninstall-dialog .button-danger:hover { background: #b32d2e; border-color: #b32d2e; } .abj404-uninstall-content label { display: block; margin: 15px 0; cursor: pointer; } .abj404-uninstall-content label input[type="checkbox"], .abj404-uninstall-content label input[type="radio"] { margin-right: 8px; } .abj404-uninstall-content .description { margin: 5px 0 0 25px; color: #646970; font-size: 13px; } .abj404-uninstall-content h3 { margin-top: 20px; margin-bottom: 10px; border-bottom: 1px solid #dcdcde; padding-bottom: 8px; } .abj404-uninstall-content h3:first-child { margin-top: 0; } .abj404-uninstall-reasons { margin-left: 25px; } .abj404-uninstall-reasons label { margin: 8px 0; } #abj404-feedback-fields { margin-top: 10px; padding: 15px; background: #f6f7f7; border-radius: 4px; } #abj404-feedback-fields input, #abj404-feedback-fields textarea { margin-top: 8px; } '); // Output modal HTML in footer add_action('admin_footer', array(__CLASS__, 'outputModalHTML')); } /** * Output the modal HTML structure */ public static function outputModalHTML() { $redirectCount = self::getRedirectCount(); ?> __('Insufficient permissions', '404-solution'))); return; } // Get preferences from AJAX request $preferences = array( 'delete_redirects' => isset($_POST['delete_redirects']) && $_POST['delete_redirects'] === 'true', 'delete_logs' => isset($_POST['delete_logs']) && $_POST['delete_logs'] === 'true', 'delete_cache' => true, // Always delete cache tables 'send_feedback' => isset($_POST['send_feedback']) && $_POST['send_feedback'] === 'true', 'uninstall_reason' => isset($_POST['uninstall_reason']) ? sanitize_text_field($_POST['uninstall_reason']) : '', 'feedback_email' => isset($_POST['feedback_email']) ? sanitize_email($_POST['feedback_email']) : '', 'feedback_details' => isset($_POST['feedback_details']) ? sanitize_textarea_field($_POST['feedback_details']) : '' ); // Save preferences using site options for multisite compatibility // In multisite, use site_option for network-activated plugins, regular option for single-site $option_name = 'abj404_uninstall_preferences'; if (is_multisite() && self::isNetworkActivated()) { // Network-activated: Use site option (accessible across all sites) $saved = update_site_option($option_name, $preferences); } else { // Single-site or site-specific activation: Use regular option $saved = update_option($option_name, $preferences, false); // autoload=false } if ($saved !== false) { wp_send_json_success(array('message' => __('Preferences saved successfully', '404-solution'))); } else { wp_send_json_error(array('message' => __('Failed to save preferences', '404-solution'))); } } /** * Check if plugin is network-activated * * @return bool True if network-activated, false otherwise */ private static function isNetworkActivated() { if (!is_multisite()) { return false; } if (!function_exists('is_plugin_active_for_network')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } return is_plugin_active_for_network(plugin_basename(ABJ404_FILE)); } /** * Get the plugin slug for JavaScript * * @return string Plugin directory slug */ private static function getPluginSlug() { // Get plugin directory name from plugin file path $pluginPath = plugin_basename(ABJ404_FILE); $parts = explode('/', $pluginPath); return $parts[0]; } /** * Get the count of redirects for display * * @return int Number of redirects */ private static function getRedirectCount() { global $wpdb; $table_name = $wpdb->prefix . 'abj404_redirects'; // Check if table exists $table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name; if (!$table_exists) { return 0; } $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name WHERE status != " . ABJ404_STATUS_TRASH); return $count ? intval($count) : 0; } }