get_file()), [$this, 'plugin_action_links'], 10, 1); } private function get_menu_slug():string { return Plugin::instance()->get_id(); } private function get_menu_title():string { return Plugin::instance()->get_title(); } private function get_page_title():string { return sprintf( Plugin::__('%s Settings'), Plugin::instance()->get_title() ); } // Register settings page public function admin_menu():void { add_submenu_page( self::PARENT_SLUG, $this->get_page_title(), $this->get_menu_title(), self::CAPABILITY, $this->get_menu_slug(), [$this, 'render'] ); } // Register settings fields private function get_option_group():string { return Plugin::instance()->get_id(); } private function get_option_name():string { return Plugin::instance()->get_id(); } public function register_settings():void { register_setting($this->get_option_group(), $this->get_option_name(), [ 'type' => 'array', 'label' => $this->get_page_title(), 'sanitize_callback' => [$this, 'sanitize'], 'default' => [ 'client_id' => '', 'client_secret' => '', 'token' => '', ], ]); add_settings_section( 'api', Plugin::__('API Settings'), function () { printf( '
%s
', Plugin::__('See Issuu API documentation to learn how to generate an API client with your Issuu account.') ); }, $this->get_menu_slug() ); add_settings_field( 'client_id', Plugin::__('Client ID'), [$this, 'the_field'], $this->get_menu_slug(), 'api', ['name' => 'client_id'] ); add_settings_field( 'client_secret', Plugin::__('Client Secret'), [$this, 'the_field'], $this->get_menu_slug(), 'api', ['name' => 'client_secret'] ); add_settings_field( 'token', Plugin::__('Token'), [$this, 'the_field'], $this->get_menu_slug(), 'api', ['name' => 'token'] ); } public function the_field(array $args):void { printf( '', esc_attr($args['name']), esc_attr($this->get_option_group()), esc_attr($args['name']), esc_attr($this->get_field($args['name'])) ); if (isset($args['description']) && !empty($args['description'])) { printf('%s
', esc_html($args['description'])); } } public function sanitize(array $input):array { return array_map('sanitize_text_field', $input); } // Output settings page private function load_options():bool { if (isset($this->options) && is_array($this->options)) return false; $this->options = get_option($this->get_option_group()); return true; } public function render():void { $this->load_options(); echo '