| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hostinger; |
| 4 |
|
| 5 |
use Hostinger\Admin\PluginSettings; |
| 6 |
use Hostinger\Helper; |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
class DefaultOptions { |
| 11 |
|
| 12 |
private PluginSettings $plugin_settings; |
| 13 |
|
| 14 |
public function __construct( PluginSettings $plugin_settings ) { |
| 15 |
$this->plugin_settings = $plugin_settings; |
| 16 |
} |
| 17 |
|
| 18 |
public function add_options(): void { |
| 19 |
$this->configure_plugin_settings(); |
| 20 |
|
| 21 |
foreach ( $this->options() as $key => $option ) { |
| 22 |
update_option( $key, $option ); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 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() ); |
| 33 |
|
| 34 |
if ( ! $is_first_setup && ! $needs_bypass_code ) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 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 ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* @return string[] |
| 51 |
*/ |
| 52 |
private function options(): array { |
| 53 |
$options = array( |
| 54 |
'optin_monster_api_activation_redirect_disabled' => 'true', |
| 55 |
'wpforms_activation_redirect' => 'true', |
| 56 |
'aioseo_activation_redirect' => 'false', |
| 57 |
); |
| 58 |
|
| 59 |
if ( Helper::is_plugin_active( 'astra-sites' ) ) { |
| 60 |
$options = array_merge( $options, $this->get_astra_options() ); |
| 61 |
} |
| 62 |
|
| 63 |
return $options; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* @return string[] |
| 68 |
*/ |
| 69 |
private function get_astra_options(): array { |
| 70 |
return array( |
| 71 |
'astra_sites_settings' => 'gutenberg', |
| 72 |
); |
| 73 |
} |
| 74 |
} |
| 75 |
|