private function handle_post() { if (!defined('DOING_AJAX') || !DOING_AJAX) { // Only process the nonce when the request is not an AJAX request as the AJAX handler has its own nonce check. ITSEC_Form::check_nonce('itsec-settings-page'); } $post_data = ITSEC_Form::get_post_data(); $saved = true; $js_function_calls = array(); if (!empty($_POST['widget-id'])) { $id = $_POST['widget-id']; if (isset($post_data[$id]) && isset($this->widgets[$id])) { $widget = $this->widgets[$id]; $widget->handle_form_post($post_data[$id]); } } else { if (!empty($_POST['module'])) { if (isset($this->modules[$_POST['module']])) { $modules = array($_POST['module'] => $this->modules[$_POST['module']]); } else { ITSEC_Response::add_error(new WP_Error('itsec-settings-save-unrecognized-module', sprintf(__('The supplied module (%s) is not recognized. The module settings could not be saved.', 'better-wp-security'), $_POST['module']))); $modules = array(); } } else { $modules = $this->modules; } foreach ($modules as $id => $module) { if (isset($post_data[$id])) { $results = $module->handle_form_post($post_data[$id]); } } if (ITSEC_Response::is_success()) { if (ITSEC_Response::get_show_default_success_message()) { ITSEC_Response::add_message(__('The settings saved successfully.', 'better-wp-security')); } } else { if (ITSEC_Response::get_show_default_error_message()) { $error_count = ITSEC_Response::get_error_count(); if ($error_count > 0) { ITSEC_Response::add_error(new WP_Error('itsec-settings-data-not-saved', _n('The settings could not be saved. Please correct the error above and try again.', 'The settings could not be saved. Please correct the errors above and try again.', $error_count, 'better-wp-security'))); } else { ITSEC_Response::add_error(new WP_Error('itsec-settings-data-not-saved-missing-error', __('The settings could not be saved. Due to an unknown error. Please try refreshing the page and trying again.', 'better-wp-security'))); } } } } if (defined('DOING_AJAX') && DOING_AJAX) { return; } ITSEC_Response::maybe_regenerate_wp_config(); ITSEC_Response::maybe_regenerate_server_config(); ITSEC_Response::maybe_do_force_logout(); ITSEC_Response::maybe_do_redirect(); }