403, 'back_link' => true) ); } // Verify user capabilities with error feedback (Bug #10 fix) if (!current_user_can('manage_options')) { wp_die( esc_html__('You do not have permission to access this page.', '404-solution'), esc_html__('Error', '404-solution'), array('response' => 403, 'back_link' => true) ); } $action = sanitize_text_field($_POST['abj404_setup_wizard_action']); // All actions mark setup as complete update_option(self::OPTION_NAME, gmdate('Y-m-d')); // If user clicked "Save & Get Started", apply their settings if ($action === 'save') { self::applySettings(); } // Determine redirect destination based on logging choice $q2_answer = isset($_POST['abj404_setup_q2']) ? sanitize_text_field($_POST['abj404_setup_q2']) : 'yes'; $redirect_url = 'options-general.php?page=abj404_solution&setup_complete=1'; // If logging 404s, take them to Captured 404s tab; otherwise Page Redirects if ($q2_answer === 'yes') { $redirect_url .= '&subpage=abj404_captured'; } wp_safe_redirect(admin_url($redirect_url)); exit; } /** Allowed values for Q1 (Bug #13 fix) */ private static $allowedQ1Values = ['redirect', 'default']; /** Allowed values for Q2 (Bug #13 fix) */ private static $allowedQ2Values = ['yes', 'no']; /** * Apply settings from wizard form */ private static function applySettings() { $abj404logic = ABJ_404_Solution_PluginLogic::getInstance(); $options = $abj404logic->getOptions(); // Question 1: What happens when page not found // Validate against whitelist (Bug #13 fix) $q1_answer = isset($_POST['abj404_setup_q1']) ? sanitize_text_field($_POST['abj404_setup_q1']) : 'redirect'; if (!in_array($q1_answer, self::$allowedQ1Values, true)) { $q1_answer = 'redirect'; // Default to safe value } if ($q1_answer === 'redirect') { // Automatically redirect to similar page when a match is found $options['auto_redirects'] = '1'; $options['auto_cats'] = '1'; $options['auto_tags'] = '1'; } else { // Just show the default 404 page - only use manual redirects $options['auto_redirects'] = '0'; $options['auto_cats'] = '0'; $options['auto_tags'] = '0'; } $options['dest404page'] = '0|' . ABJ404_TYPE_404_DISPLAYED; // Question 2: Log 404s // Validate against whitelist (Bug #13 fix) $q2_answer = isset($_POST['abj404_setup_q2']) ? sanitize_text_field($_POST['abj404_setup_q2']) : 'yes'; if (!in_array($q2_answer, self::$allowedQ2Values, true)) { $q2_answer = 'yes'; // Default to safe value } $options['capture_404'] = ($q2_answer === 'yes') ? '1' : '0'; // Save options $abj404logic->updateOptions($options); } /** * Enqueue assets on 404 Solution admin pages * * @param string $hook Current admin page hook */ public static function enqueueAssets($hook) { // Only load on 404 Solution pages if (!self::isPluginPage()) { return; } // Only load if wizard should be shown if (!self::shouldShowWizard()) { return; } // Only for users who can manage options if (!current_user_can('manage_options')) { return; } // Add inline styles for the modal add_action('admin_head', array(__CLASS__, 'outputStyles')); // Output modal HTML in footer add_action('admin_footer', array(__CLASS__, 'outputModalHTML')); // Output JavaScript for dismiss functionality add_action('admin_footer', array(__CLASS__, 'outputScript'), 20); } /** * Output modal CSS styles */ public static function outputStyles() { ?>