repository = new FLOATCONNECT_Repository(); $this->sanitizer = new FLOATCONNECT_Sanitizer(); } /** * Get all settings. * * @return array */ public function get_settings(): array { return $this->repository->get_all(); } /** * Get one setting. * * @param string $key Setting key. * @param mixed $default_value Default value. * * @return mixed */ public function get( string $key, mixed $default_value = null ): mixed { $settings = $this->get_settings(); return $settings[ $key ] ?? $default_value; } /** * Save settings. * * @param array $settings Settings to save. * * @return bool */ public function save( array $settings ): bool { $sanitized = $this->sanitizer->sanitize( $settings ); $errors = get_settings_errors( 'floatconnect' ); if ( ! empty( $errors ) ) { return false; } return $this->repository->save( $sanitized ); } /** * Reset settings to defaults. * * @return bool */ public function reset(): bool { $defaults = FLOATCONNECT_Defaults::all(); /* * Keep the default contact structurally valid. * The value is intentionally empty and therefore the frontend * will simply not display the contact until a value is entered. */ return $this->repository->save( $defaults ); } }