PluginProbe
Hostinger Tools / 3.0.79
Hostinger Tools v3.0.79
3.0.79 3.0.78 3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 All 110 releases
← All changes | includes/DefaultOptions.php +27 -14 3.0.76 → 3.0.79 View file →
@@ -1,19 +1,23 @@
1 1 <?php
2 2
3 3 namespace Hostinger;
4 4
5 -use Hostinger\Admin\Options\PluginOptions;
5 +use Hostinger\Admin\PluginSettings;
6 6 use Hostinger\Helper;
7 7
8 8 defined( 'ABSPATH' ) || exit;
9 9
10 10 class DefaultOptions {
11 - /**
12 - * @return void
13 - */
11 +
12 + private PluginSettings $plugin_settings;
13 +
14 + public function __construct( PluginSettings $plugin_settings ) {
15 + $this->plugin_settings = $plugin_settings;
16 + }
17 +
14 18 public function add_options(): void {
15 - $this->configure_security_settings();
19 + $this->configure_plugin_settings();
16 20
17 21 foreach ( $this->options() as $key => $option ) {
18 22 update_option( $key, $option );
19 23 }
@@ -18,20 +22,29 @@
18 22 update_option( $key, $option );
19 23 }
20 24 }
21 25
22 - public function configure_security_settings(): void {
23 - $hostinger_plugin_settings = get_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, array() );
26 + /**
27 + * A later activation must never override a choice the site owner has already made.
28 + */
29 + private function configure_plugin_settings(): void {
30 + $is_first_setup = ! $this->plugin_settings->has_stored_settings();
31 + $plugin_options = $this->plugin_settings->get_plugin_settings();
32 + $needs_bypass_code = empty( $plugin_options->get_bypass_code() );
24 33
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 );
34 + if ( ! $is_first_setup && ! $needs_bypass_code ) {
35 + return;
28 36 }
29 - }
30 37
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 );
38 + if ( $is_first_setup ) {
39 + $plugin_options->set_enable_llms_txt( true );
40 + }
41 +
42 + if ( $needs_bypass_code ) {
43 + $plugin_options->set_bypass_code( Helper::generate_bypass_code( 16 ) );
44 + }
45 +
46 + $this->plugin_settings->save_plugin_settings( $plugin_options );
34 47 }
35 48
36 49 /**
37 50 * @return string[]