| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hostinger; |
| 4 |
|
| 5 |
use Hostinger\Admin\Options\PluginOptions; |
| 6 |
use Hostinger\Helper; |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
class DefaultOptions { |
| 11 |
/** |
| 12 |
* @return void |
| 13 |
*/ |
| 14 |
public function add_options(): void { |
| 15 |
$this->configure_security_settings(); |
| 16 |
|
| 17 |
foreach ( $this->options() as $key => $option ) { |
| 18 |
update_option( $key, $option ); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
public function configure_security_settings(): void { |
| 23 |
$hostinger_plugin_settings = get_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, [] ); |
| 24 |
|
| 25 |
// Check and set bypass code |
| 26 |
if ( empty( $hostinger_plugin_settings['bypass_code'] ) ) { |
| 27 |
$hostinger_plugin_settings['bypass_code'] = Helper::generate_bypass_code( 16 ); |
| 28 |
} |
| 29 |
|
| 30 |
$hostinger_plugin_settings = $this->check_authentication_password( $hostinger_plugin_settings ); |
| 31 |
|
| 32 |
$plugin_options = new PluginOptions( $hostinger_plugin_settings ); |
| 33 |
update_option( HOSTINGER_PLUGIN_SETTINGS_OPTION, $plugin_options->to_array(), false ); |
| 34 |
} |
| 35 |
|
| 36 |
public function check_authentication_password( array $settings ): array { |
| 37 |
global $wpdb; |
| 38 |
|
| 39 |
$existing_passwords = (int)$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->usermeta} WHERE meta_key = %s", '_application_passwords' ) ); |
| 40 |
|
| 41 |
if ( $existing_passwords === 0 ) { |
| 42 |
$settings['disable_authentication_password'] = true; |
| 43 |
} |
| 44 |
|
| 45 |
return $settings; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @return string[] |
| 50 |
*/ |
| 51 |
private function options(): array { |
| 52 |
$options = array( |
| 53 |
'optin_monster_api_activation_redirect_disabled' => 'true', |
| 54 |
'wpforms_activation_redirect' => 'true', |
| 55 |
'aioseo_activation_redirect' => 'false', |
| 56 |
); |
| 57 |
|
| 58 |
if ( Helper::is_plugin_active( 'astra-sites' ) ) { |
| 59 |
$options = array_merge( $options, $this->get_astra_options() ); |
| 60 |
} |
| 61 |
|
| 62 |
return $options; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* @return string[] |
| 67 |
*/ |
| 68 |
private function get_astra_options(): array { |
| 69 |
return array( |
| 70 |
'astra_sites_settings' => 'gutenberg', |
| 71 |
); |
| 72 |
} |
| 73 |
} |
| 74 |
|