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' => __( 'Accessible Web: 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(); $target_snippet = '
'; $text_snippet = ' View Accessibility Policy '; $shortcode_snippet_default = '[accessible_web_target_snippet]'; $shortcode_snippet_text = '[accessible_web_target_snippet]View our Accessibility Center[/accessible_web_target_snippet]'; ?>To get started simply add your api key from your website in Accessible Web Console and save!
For additional options add the following additional snippets to your site manually.
This snippet is optional, and used alongside the previous snippet. It allows you to place the badge in a specific location on the page.
To embed this as a simple shortcode use:
This snippet is also optional, and can be used in place of the previous snippet. It allows you to embed a text-only link on your website instead of the standard badge. This will allow you to show a link to your accessibility center that matches your websites styles.
To embed this as a simple shortcode use:
You may feel free to edit the content inside of the link however you like, but be sure to follow accessibility best practices!
The badge will embed your accessibility center into your website.
You can review your accessibility center if you'd like to verify its appearance.
__( 'A11Y Center 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 Console.', 'aweb-badge-plugin' ), 'type' => 'text', 'default' => '', 'placeholder' => __( '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 = '