options = get_option( 'accessdefender_options', array() );
require_once ACCESS_DEFENDER_PATH . 'src/Views/admin/settings-page.php';
}
/**
* Initializes the settings for the Access Defender plugin.
*
* Registers the settings and adds the main settings section and fields
* for configuring the plugin options. The settings are sanitized using
* the specified callback method.
*
* @since 1.0.1
*/
public function init_settings(): void {
register_setting(
'accessdefender_options',
'accessdefender_options',
array( $this, 'sanitize_options' )
);
add_settings_section(
'main_section',
'General Settings',
null,
'access-defender'
);
$this->add_settings_fields();
}
/**
* Adds settings fields to the Access Defender settings page.
*
* This method defines and adds the necessary settings fields for
* configuring the Access Defender plugin options, including enabling
* VPN blocking, setting a custom warning title, and setting a custom
* warning message.
*
* The settings fields are registered under the 'main_section' of the
* 'access-defender' settings page.
*
* @since 1.0.1
*/
private function add_settings_fields(): void {
add_settings_field(
'enable_vpn_blocking',
'Enable VPN Blocking',
array( $this, 'render_switch_field' ),
'access-defender',
'main_section',
array( 'enable_vpn_blocking' )
);
add_settings_field(
'warning_title',
'Warning Title',
array( $this, 'render_text_field' ),
'access-defender',
'main_section',
array( 'warning_title' )
);
add_settings_field(
'warning_message',
'Warning Message',
array( $this, 'render_textarea_field' ),
'access-defender',
'main_section',
array( 'warning_message' )
);
}
/**
* Render a switch field for the settings page
*
* @param array $args Field arguments.
* @return void
*/
public function render_switch_field( $args ): void {
$field = $args[0];
$checked = ( isset( $this->options[ $field ] ) && '1' === $this->options[ $field ] ) ? 'checked' : '';
?>
options[ $field ] ?? '';
?>
options[ $field ] ?? '';
?>