| @@ -7,55 +7,59 @@ | ||
| 7 | 7 | |
| 8 | 8 | defined( 'ABSPATH' ) || exit; |
| 9 | 9 | |
| 10 | 10 | class DefaultOptions { |
| 11 | - /** | |
| 12 | - * @return void | |
| 13 | - */ | |
| 14 | - public function add_options(): void { | |
| 15 | - $this->configure_security_settings(); | |
| 11 | + /** | |
| 12 | + * @return void | |
| 13 | + */ | |
| 14 | + public function add_options(): void { | |
| 15 | + $this->install_bypass_code(); | |
| 16 | 16 | |
| 17 | - foreach ( $this->options() as $key => $option ) { | |
| 18 | - update_option( $key, $option ); | |
| 19 | - } | |
| 20 | - } | |
| 17 | + foreach ( $this->options() as $key => $option ) { | |
| 18 | + update_option( $key, $option ); | |
| 19 | + } | |
| 20 | + } | |
| 21 | 21 | |
| 22 | - public function configure_security_settings(): void { | |
| 23 | - $hostinger_plugin_settings = get_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, array() ); | |
| 22 | + /** | |
| 23 | + * @return void | |
| 24 | + */ | |
| 25 | + public function install_bypass_code(): void { | |
| 26 | + // Generate initial bypass code when plugin is first installed. | |
| 27 | + $hostinger_plugin_settings = get_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, false ); | |
| 24 | 28 | |
| 25 | - if ( empty( $hostinger_plugin_settings['bypass_code'] ) ) { | |
| 26 | - $hostinger_plugin_settings['bypass_code'] = Helper::generate_bypass_code( 16 ); | |
| 27 | - $this->update_plugin_settings( $hostinger_plugin_settings ); | |
| 28 | - } | |
| 29 | - } | |
| 29 | + if ( $hostinger_plugin_settings === false ) { | |
| 30 | + $options = array( | |
| 31 | + 'bypass_code' => Helper::generate_bypass_code( 16 ), | |
| 32 | + ); | |
| 30 | 33 | |
| 31 | - private function update_plugin_settings( array $settings ): void { | |
| 32 | - $plugin_options = new PluginOptions( $settings ); | |
| 33 | - update_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, $plugin_options->to_array(), false ); | |
| 34 | - } | |
| 34 | + $plugin_options = new PluginOptions( $options ); | |
| 35 | 35 | |
| 36 | - /** | |
| 37 | - * @return string[] | |
| 38 | - */ | |
| 39 | - private function options(): array { | |
| 40 | - $options = array( | |
| 41 | - 'optin_monster_api_activation_redirect_disabled' => 'true', | |
| 42 | - 'wpforms_activation_redirect' => 'true', | |
| 43 | - 'aioseo_activation_redirect' => 'false', | |
| 44 | - ); | |
| 36 | + update_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, $plugin_options->to_array(), false ); | |
| 37 | + } | |
| 38 | + } | |
| 45 | 39 | |
| 46 | - if ( Helper::is_plugin_active( 'astra-sites' ) ) { | |
| 47 | - $options = array_merge( $options, $this->get_astra_options() ); | |
| 48 | - } | |
| 40 | + /** | |
| 41 | + * @return string[] | |
| 42 | + */ | |
| 43 | + private function options(): array { | |
| 44 | + $options = array( | |
| 45 | + 'optin_monster_api_activation_redirect_disabled' => 'true', | |
| 46 | + 'wpforms_activation_redirect' => 'true', | |
| 47 | + 'aioseo_activation_redirect' => 'false', | |
| 48 | + ); | |
| 49 | 49 | |
| 50 | - return $options; | |
| 51 | - } | |
| 50 | + if ( Helper::is_plugin_active( 'astra-sites' ) ) { | |
| 51 | + $options = array_merge( $options, $this->get_astra_options() ); | |
| 52 | + } | |
| 52 | 53 | |
| 53 | - /** | |
| 54 | - * @return string[] | |
| 55 | - */ | |
| 56 | - private function get_astra_options(): array { | |
| 57 | - return array( | |
| 58 | - 'astra_sites_settings' => 'gutenberg', | |
| 59 | - ); | |
| 60 | - } | |
| 54 | + return $options; | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * @return string[] | |
| 59 | + */ | |
| 60 | + private function get_astra_options(): array { | |
| 61 | + return array( | |
| 62 | + 'astra_sites_settings' => 'gutenberg', | |
| 63 | + ); | |
| 64 | + } | |
| 61 | 65 | } |