t_server(), $config['server-type'], true ) ) { return false; } if ( isset( $config['install-type'] ) && $config['install-type'] !== ITSEC_Core::get_install_type() ) { return false; } if ( isset( $config['active-modules'] ) ) { $active = array_filter( $config['active-modules'], 'ITSEC_Modules::is_active' ); if ( count( $active ) !== count( $config['active-modules'] ) ) { return false; } } if ( isset( $config['user-groups'] ) ) { foreach ( $config['user-groups'] as $group_setting ) { if ( ! ITSEC_Lib::array_get( $settings, $group_setting ) ) { return false; } } } if ( isset( $config['feature-flags'] ) ) { foreach ( $config['feature-flags'] as $flag ) { if ( ! ITSEC_Lib_Feature_Flags::is_enabled( $flag ) ) { return false; } } } return true; } protected function after_save() { } protected function handle_settings_changes( $old_settings ) {} public function export() { _deprecated_function( __METHOD__, '7.1' ); return $this->settings; } public function import( $settings ) { _deprecated_function( __METHOD__, '7.1' ); $this->set_all( $settings ); } public function get( $name, $default = null ) { if ( isset( $this->settings[ $name ] ) ) { return $this->settings[ $name ]; } return $default; } public function get_all() { return $this->settings; } /** * Prepares the settings for output in the REST API. * * @return array */ public function prepare_for_rest() { return $this->settings; } /** * Prepares the settings from a REST API request to be saved. * * @param array $settings * * @return array */ public function prepare_from_rest( $settings ) { return $settings; } public function set( $name, $value ) { $settings = $this->settings; $settings[ $name ] = $value; return $this->set_all( $settings ); } public function set_all( $settings ) { $retval = array( 'old_settings' => $this->settings, 'new_settings' => $this->settings, 'errors' => array(), 'messages' => array(), 'saved' => false, ); $validator = ITSEC_Modules::get_validator( $this->get_id() ); if ( is_null( $validator ) ) { $retval['errors'][] = new WP_Error( 'itsec-settings-missing-validator-for-' . $this->get_id(), sprintf( __( 'The data validator for %1$s is missing. Data for the module cannot be saved without the validator. This error could indicate a bad install of Solid Security. Please remove the plugin and reinstall it. If this message persists, please contact support and send them this error message.', 'better-wp-security' ), $this->get_id() ) ); } else { $validator->validate( $settings ); $retval['errors'] = $validator->get_errors(); $retval['messages'] = $validator->get_messages(); if ( $validator->can_save() ) { $this->settings = $validator->get_settings(); ITSEC_Storage::set( $this->get_id(), $this->settings ); $this->after_save(); $this->handle_settings_changes( $retval['old_settings'] ); $retval['new_settings'] = $this->settings; $retval['saved'] = true; do_action( 'itsec-settings-updated', $this->get_id() ); } else { ITSEC_Response::set_success( false ); } } ITSEC_Response::add_errors( $retval['errors'] ); ITSEC_Response::add_messages( $retval['messages'] ); return $retval; } public function load() { $this->settings = ITSEC_Storage::get( $this->get_id() ); if ( ! is_array( $this->settings ) ) { $this->settings = array(); } foreach ( $this->get_known_settings() as $setting ) { if ( ! array_key_exists( $setting, $this->settings ) ) { $this->settings[ $setting ] = $this->get_default( $setting ); } } } } t_server(), $config['server-type'], true ) ) { return false; } if ( isset( $config['install-type'] ) && $config['install-type'] !== ITSEC_Core::get_install_type() ) { return false; } if ( isset( $config['active-modules'] ) ) { $active = array_filter( $config['active-modules'], 'ITSEC_Modules::is_active' ); if ( count( $active ) !== count( $config['active-modules'] ) ) { return false; } } if ( isset( $config['user-groups'] ) ) { foreach ( $config['user-groups'] as $group_setting ) { if ( ! ITSEC_Lib::array_get( $settings, $group_setting ) ) { return false; } } } if ( isset( $config['feature-flags'] ) ) { foreach ( $config['feature-flags'] as $flag ) { if ( ! ITSEC_Lib_Feature_Flags::is_enabled( $flag ) ) { return false; } } } return true; } protected function after_save() { } protected function handle_settings_changes( $old_settings ) {} public function export() { _deprecated_function( __METHOD__, '7.1' ); return $this->settings; } public function import( $settings ) { _deprecated_function( __METHOD__, '7.1' ); $this->set_all( $settings ); } public function get( $name, $default = null ) { if ( isset( $this->settings[ $name ] ) ) { return $this->settings[ $name ]; } return $default; } public function get_all() { return $this->settings; } /** * Prepares the settings for output in the REST API. * * @return array */ public function prepare_for_rest() { return $this->settings; } /** * Prepares the settings from a REST API request to be saved. * * @param array $settings * * @return array */ public function prepare_from_rest( $settings ) { return $settings; } public function set( $name, $value ) { $settings = $this->settings; $settings[ $name ] = $value; return $this->set_all( $settings ); } public function set_all( $settings ) { $retval = array( 'old_settings' => $this->settings, 'new_settings' => $this->settings, 'errors' => array(), 'messages' => array(), 'saved' => false, ); $validator = ITSEC_Modules::get_validator( $this->get_id() ); if ( is_null( $validator ) ) { $retval['errors'][] = new WP_Error( 'itsec-settings-missing-validator-for-' . $this->get_id(), sprintf( __( 'The data validator for %1$s is missing. Data for the module cannot be saved without the validator. This error could indicate a bad install of Solid Security. Please remove the plugin and reinstall it. If this message persists, please contact support and send them this error message.', 'better-wp-security' ), $this->get_id() ) ); } else { $validator->validate( $settings ); $retval['errors'] = $validator->get_errors(); $retval['messages'] = $validator->get_messages(); if ( $validator->can_save() ) { $this->settings = $validator->get_settings(); ITSEC_Storage::set( $this->get_id(), $this->settings ); $this->after_save(); $this->handle_settings_changes( $retval['old_settings'] ); $retval['new_settings'] = $this->settings; $retval['saved'] = true; do_action( 'itsec-settings-updated', $this->get_id() ); } else { ITSEC_Response::set_success( false ); } } ITSEC_Response::add_errors( $retval['errors'] ); ITSEC_Response::add_messages( $retval['messages'] ); return $retval; } public function load() { $this->settings = ITSEC_Storage::get( $this->get_id() ); if ( ! is_array( $this->settings ) ) { $this->settings = array(); } foreach ( $this->get_known_settings() as $setting ) { if ( ! array_key_exists( $setting, $this->settings ) ) { $this->settings[ $setting ] = $this->get_default( $setting ); } } } }