parent = $parent; $this->base = 'aweb_'; // Initialise settings. add_action( 'init', array( $this, 'init_settings' ), 11 ); // Register Accessible Web Badge. add_action( 'admin_init', array( $this, 'register_settings' ) ); // Add settings page to menu. add_action( 'admin_menu', array( $this, 'add_menu_item' ) ); // Add settings link to plugins page. add_filter( 'plugin_action_links_' . plugin_basename( $this->parent->file ), array( $this, 'add_settings_link', ) ); // Configure placement of Accessible Web Badge page. See readme for implementation. add_filter( $this->base . 'menu_settings', array( $this, 'configure_settings' ) ); } /** * Initialise settings * * @return void */ public function init_settings() { $this->settings = $this->settings_fields(); } /** * Add settings page to admin menu * * @return void */ public function add_menu_item() { $args = $this->menu_settings(); // Do nothing if wrong location key is set. if ( is_array( $args ) && isset( $args['location'] ) && function_exists( 'add_' . $args['location'] . '_page' ) ) { switch ( $args['location'] ) { case 'options': case 'submenu': $page = add_submenu_page( $args['parent_slug'], $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] ); break; case 'menu': $page = add_menu_page( $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'], $args['icon_url'], $args['position'] ); break; default: return; } } } /** * Prepare default settings page arguments * * @return mixed|void */ private function menu_settings() { return apply_filters( //phpcs:disable $this->base . 'menu_settings', //phpcs:enable array( 'location' => 'options', // Possible settings: options, menu, submenu. 'parent_slug' => 'options-general.php', 'page_title' => __( 'Accessible Web A11Y Center', 'aweb-badge-plugin' ), 'menu_title' => __( 'A11Y Center', 'aweb-badge-plugin' ), 'capability' => 'manage_options', 'menu_slug' => $this->parent->_token . '_settings', 'function' => array( $this, 'settings_page' ), 'icon_url' => '', 'position' => null, ) ); } /** * Container for settings page arguments * * @param array $settings Settings array. * * @return array */ public function configure_settings( $settings = array() ) { return $settings; } /** * Add settings link to plugin list table * * @param array $links Existing links. * @return array Modified links. */ public function add_settings_link( $links ) { $settings_link = '' . __( 'Settings', 'aweb-badge-plugin' ) . ''; array_push( $links, $settings_link ); return $links; } /** * Build settings fields * * @return array Fields to be displayed on settings page */ private function settings_fields() { ob_start(); ?>

To get started simply add your api key from your website in Accessible Web RAMP and save! Learn how to find your api key here.

The button will embed your accessibility center into your website. You can review your accessibility center if you'd like to verify its appearance.

__( 'Settings', 'aweb-badge-plugin' ), 'description' => $description, 'fields' => array( array( 'id' => 'api_key', 'label' => __( 'API Key', 'aweb-badge-plugin' ), 'description' => __( 'Your api key from Accessible Web RAMP.', 'aweb-badge-plugin' ), 'type' => 'text', 'default' => '', 'placeholder' => __( 'Enter your API key', 'aweb-badge-plugin' ), ), ), ); //phpcs:disable $settings = apply_filters( $this->parent->_token . '_settings_fields', $settings ); //phpcs:enable return $settings; } /** * Register Accessible Web Badge * * @return void */ public function register_settings() { if ( is_array( $this->settings ) ) { // Check posted/selected tab. //phpcs:disable $current_section = ''; if ( isset( $_POST['tab'] ) && $_POST['tab'] ) { $current_section = sanitize_text_field($_POST['tab']); } else { if ( isset( $_GET['tab'] ) && $_GET['tab'] ) { $current_section = sanitize_text_field($_GET['tab']); } } //phpcs:enable foreach ( $this->settings as $section => $data ) { if ( $current_section && $current_section !== $section ) { continue; } // Add section to page. add_settings_section( $section, $data['title'], array( $this, 'settings_section' ), $this->parent->_token . '_settings' ); foreach ( $data['fields'] as $field ) { // Validation callback for field. $validation = ''; if ( isset( $field['callback'] ) ) { $validation = $field['callback']; } // Register field. $option_name = $this->base . $field['id']; register_setting( $this->parent->_token . '_settings', $option_name, $validation ); // Add field to page. add_settings_field( $field['id'], $field['label'], array( $this->parent->admin, 'display_field' ), $this->parent->_token . '_settings', $section, array( 'field' => $field, 'prefix' => $this->base, ) ); } if ( ! $current_section ) { break; } } } } /** * Settings section. * * @param array $section Array of section ids. * @return void */ public function settings_section( $section ) { $html = '

' . $this->settings[ $section['id'] ]['description'] . '

' . "\n"; echo $html; //phpcs:ignore } /** * Load settings page content. * * @return void */ public function settings_page() { // Build page HTML. $html = '
' . "\n"; $html .= '

' . __( 'Accessible Web A11Y Center', 'aweb-badge-plugin' ) . '

' . "\n"; $tab = ''; //phpcs:disable if ( isset( $_GET['tab'] ) && $_GET['tab'] ) { $tab .= sanitize_text_field($_GET['tab']); } //phpcs:enable // Show page tabs. if ( is_array( $this->settings ) && 1 < count( $this->settings ) ) { $html .= '' . "\n"; } $html .= '
' . "\n"; // Get settings fields. ob_start(); settings_fields( $this->parent->_token . '_settings' ); do_settings_sections( $this->parent->_token . '_settings' ); $html .= ob_get_clean(); $html .= '

' . "\n"; $html .= '' . "\n"; $html .= '' . "\n"; $html .= '

' . "\n"; $html .= '
' . "\n"; $html .= '
' . "\n"; echo $html; //phpcs:ignore } /** * Main Aweb_Badge_Plugin_Settings Instance * * Ensures only one instance of Aweb_Badge_Plugin_Settings is loaded or can be loaded. * * @since 1.0.0 * @static * @see Aweb_Badge_Plugin() * @param object $parent Object instance. * @return object Aweb_Badge_Plugin_Settings instance */ public static function instance( $parent ) { if ( is_null( self::$_instance ) ) { self::$_instance = new self( $parent ); } return self::$_instance; } // End instance() }