示例#1
0
 private function handle_post()
 {
     if (!empty($_POST['itsec_clear_logs']) && 'clear_logs' === $_POST['itsec_clear_logs']) {
         if (!wp_verify_nonce($_POST['wp_nonce'], 'itsec_clear_logs')) {
             die(__('Security error!', 'better-wp-security'));
         }
         global $itsec_logger;
         $itsec_logger->purge_logs(true);
     } else {
         $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();
     }
 }