*/ class Ai_Shield_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $ai_shield The ID of this plugin. */ private $ai_shield; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * The option name * * @since 1.0.1 * @access private * @var string $option_name The key all options are stored under */ public const OPTION_NAME = 'ai_shield'; /** * The option group of this plugin. * * @since 1.0.1 * @access private * @var string $option_group The option group */ private $option_group = 'ai_shield_group'; /** * The option page of this plugin. * * @since 1.0.1 * @access private * @var string $option_page The option page */ private $option_page = 'ai_shield_page'; public const DEFAULT_SETTINGS = [ 'ai_shield_enabled' => true, 'ai_shield_use_cache' => true, 'ai_shield_cache_duration' => 5 ]; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $ai_shield The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $ai_shield, $version ) { $this->ai_shield = $ai_shield; $this->version = $version; } public function register_settings () { $settings_section = self::OPTION_NAME . '_section'; register_setting( $this->option_group, self::OPTION_NAME , [ 'sanitize_callback' => [$this, 'sanitize_fields'], 'default' => self::DEFAULT_SETTINGS ] ); add_settings_section( $settings_section, '', // __( 'AI Shield', 'ai-shield' ), '', // 'ai_shield_main_section_text_output', $this->option_page ); add_settings_field( 'ai_shield_enabled', __('Enabled', 'ai-shield' ), [$this, 'render_checkbox_input'], $this->option_page, $settings_section, ['label_for' => 'ai_shield_enabled'] ); add_settings_field( 'ai_shield_use_cache', __('Cache enabled', 'ai-shield' ), [$this, 'render_checkbox_input'], $this->option_page, $settings_section, ['label_for' => 'ai_shield_use_cache'] ); add_settings_field( 'ai_shield_cache_duration', __('Cache duration', 'ai-shield' ), [$this, 'render_cache_duration_input'], $this->option_page, $settings_section, ['label_for' => 'ai_shield_cache_duration'] ); } public function register_options_page() { // add_menu_page( // 'AI Shield Settings', // 'AI Shield', // 'manage_options', // 'ai_shield', // [$this, 'options_page_html'] // ); add_options_page( 'AI Shield', 'AI Shield', 'manage_options', 'ai_shield', [$this, 'options_page_html'] ); } public function options_page_html() { if ( ! current_user_can( 'manage_options' ) ) { return; } // WP displays its own notice if using a submenu // if ( isset( $_GET['settings-updated'] ) ) { // add_settings_error( // 'options_messages', // 'my_options_message', // esc_html__( 'Settings saved', 'ai-shield' ), // 'success' // ); // } settings_errors( 'options_messages' ); ?>