esc_html__( 'Skip Link', 'accessibility-checker' ), 'callback' => [ $this, 'skip_link_section_callback' ], ]; return $sections; } ); add_filter( 'edac_filter_fixes_settings_fields', [ $this, 'get_fields_array' ] ); } /** * Returns the settings fields for the skip link fix. * * @param array $fields The array of fields that are already registered, if any. * * @return array */ public function get_fields_array( array $fields = [] ): array { $fields['edac_fix_add_skip_link'] = [ 'label' => esc_html__( 'Enable Skip Link', 'accessibility-checker' ), 'type' => 'checkbox', 'labelledby' => 'add_skip_link', 'description' => esc_html__( 'Add a skip link to all site pages, allowing users to skip directly to the main content.', 'accessibility-checker' ), 'section' => 'skip_link', 'fix_slug' => $this->get_slug(), 'group_name' => $this->get_nicename(), 'help_id' => 8638, ]; $fields['edac_fix_add_skip_link_target_id'] = [ 'label' => esc_html__( 'Main Content Target (required)', 'accessibility-checker' ), 'type' => 'text', 'labelledby' => 'skip_link_target_id', 'description' => esc_html__( 'Define the ID(s) of the main content area(s) to be targeted by skip links. Enter multiple IDs separated by commas; the system will cascade through the list to find the appropriate one for each page.', 'accessibility-checker' ), 'sanitize_callback' => 'sanitize_text_field', 'section' => 'skip_link', 'condition' => 'edac_fix_add_skip_link', 'required_when' => 'edac_fix_add_skip_link', 'fix_slug' => $this->get_slug(), ]; $fields['edac_fix_add_skip_link_nav_target_id'] = [ 'label' => esc_html__( 'Navigation Target', 'accessibility-checker' ), 'type' => 'text', 'labelledby' => 'skip_link_nav_target_id', 'description' => __( 'Set the ID attribute of the navigation element. This is useful if your main navigation contains actions that most site visitors would want to take such as login or search features.', 'accessibility-checker' ), 'sanitize_callback' => 'sanitize_text_field', 'section' => 'skip_link', 'condition' => 'edac_fix_add_skip_link', 'fix_slug' => $this->get_slug(), ]; return $fields; } /** * Run the fix for adding the skip link to the site. */ public function run() { if ( ! get_option( 'edac_fix_add_skip_link', false ) ) { return null; } add_action( 'wp_body_open', [ $this, 'add_skip_link' ] ); $targets_string = get_option( 'edac_fix_add_skip_link_target_id', '' ); if ( ! $targets_string ) { return; } $targets_list = explode( ',', $targets_string ); $targets = []; foreach ( $targets_list as $target ) { // trim whitespace and any leading '#'. $trimmed = ltrim( trim( $target ), '#' ); if ( empty( $trimmed ) ) { continue; } $targets[] = '#' . $trimmed; } if ( empty( $targets ) ) { return; } add_filter( 'edac_filter_frontend_fixes_data', function ( $data ) use ( $targets ) { $data['skip_link'] = [ 'enabled' => true, 'targets' => $targets, ]; return $data; } ); } /** * Injects the style rules for the skip link. * * @return void */ public function add_skip_link_styles() { ?>
', '' ) ); ?>
add_skip_link_styles(); ?>