• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

equalizedigital / accessibility-checker / 16057813270

03 Jul 2025 06:21PM UTC coverage: 28.915% (-0.1%) from 29.05%
16057813270

push

github

web-flow
Merge pull request #1029 from equalizedigital/william/pro-165-urls-missing-utm-parameters-in-plugin

Update some links through the plugin to properly attribute them

32 of 160 new or added lines in 15 files covered. (20.0%)

18 existing lines in 5 files now uncovered.

1527 of 5281 relevant lines covered (28.91%)

1.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/includes/classes/Fixes/Fix/SkipLinkFix.php
1
<?php
2
/**
3
 * Skip Link Fix Class
4
 *
5
 * @package accessibility-checker
6
 */
7

8
namespace EqualizeDigital\AccessibilityChecker\Fixes\Fix;
9

10
use EqualizeDigital\AccessibilityChecker\Fixes\FixInterface;
11

12
/**
13
 * Allows the user to add a skip link to the site if their theme does not already include them.
14
 *
15
 * @since 1.16.0
16
 */
17
class SkipLinkFix implements FixInterface {
18

19
        /**
20
         * The slug of the fix.
21
         *
22
         * @return string
23
         */
24
        public static function get_slug(): string {
25
                return 'skip_link';
×
26
        }
27

28
        /**
29
         * The nicename for the fix.
30
         *
31
         * @return string
32
         */
33
        public static function get_nicename(): string {
34
                return __( 'Add Skip Links', 'accessibility-checker' );
×
35
        }
36

37
        /**
38
         * The type of the fix.
39
         *
40
         * @return string
41
         */
42
        public static function get_type(): string {
43
                return 'frontend';
×
44
        }
45

46
        /**
47
         * Registers everything needed for the skip link fix.
48
         *
49
         * @return void
50
         */
51
        public function register(): void {
52

53
                add_filter(
×
54
                        'edac_filter_fixes_settings_sections',
×
55
                        function ( $sections ) {
×
56
                                $sections['skip_link'] = [
×
57
                                        'title'    => esc_html__( 'Skip Link', 'accessibility-checker' ),
×
58
                                        'callback' => [ $this, 'skip_link_section_callback' ],
×
59
                                ];
×
60

61
                                return $sections;
×
62
                        }
×
63
                );
×
64

65
                add_filter(
×
66
                        'edac_filter_fixes_settings_fields',
×
67
                        [ $this, 'get_fields_array' ]
×
68
                );
×
69
        }
70

71
        /**
72
         * Returns the settings fields for the skip link fix.
73
         *
74
         * @param array $fields The array of fields that are already registered, if any.
75
         *
76
         * @return array
77
         */
78
        public function get_fields_array( array $fields = [] ): array {
79

80
                $fields['edac_fix_add_skip_link'] = [
×
81
                        'label'       => esc_html__( 'Enable Skip Link', 'accessibility-checker' ),
×
82
                        'type'        => 'checkbox',
×
83
                        'labelledby'  => 'add_skip_link',
×
84
                        'description' => esc_html__( 'Add a skip link to all site pages, allowing users to skip directly to the main content.', 'accessibility-checker' ),
×
85
                        'section'     => 'skip_link',
×
86
                        'fix_slug'    => $this->get_slug(),
×
87
                        'group_name'  => $this->get_nicename(),
×
88
                        'help_id'     => 8638,
×
89
                ];
×
90

91
                $fields['edac_fix_add_skip_link_target_id'] = [
×
92
                        'label'             => esc_html__( 'Main Content Target (required)', 'accessibility-checker' ),
×
93
                        'type'              => 'text',
×
94
                        'labelledby'        => 'skip_link_target_id',
×
95
                        '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' ),
×
96
                        'sanitize_callback' => 'sanitize_text_field',
×
97
                        'section'           => 'skip_link',
×
98
                        'condition'         => 'edac_fix_add_skip_link',
×
99
                        'required_when'     => 'edac_fix_add_skip_link',
×
100
                        'fix_slug'          => $this->get_slug(),
×
101
                ];
×
102

103
                $fields['edac_fix_add_skip_link_nav_target_id'] = [
×
104
                        'label'             => esc_html__( 'Navigation Target', 'accessibility-checker' ),
×
105
                        'type'              => 'text',
×
106
                        'labelledby'        => 'skip_link_nav_target_id',
×
107
                        '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' ),
×
108
                        'sanitize_callback' => 'sanitize_text_field',
×
109
                        'section'           => 'skip_link',
×
110
                        'condition'         => 'edac_fix_add_skip_link',
×
111
                        'fix_slug'          => $this->get_slug(),
×
112
                ];
×
113

114
                return $fields;
×
115
        }
116

117
        /**
118
         * Run the fix for adding the skip link to the site.
119
         */
120
        public function run() {
121
                if ( ! get_option( 'edac_fix_add_skip_link', false ) ) {
×
122
                        return null;
×
123
                }
124

125
                add_action( 'wp_body_open', [ $this, 'add_skip_link' ] );
×
126

127
                $targets_string = get_option( 'edac_fix_add_skip_link_target_id', '' );
×
128
                if ( ! $targets_string ) {
×
129
                        return;
×
130
                }
131

132
                $targets_list = explode( ',', $targets_string );
×
133

134
                foreach ( $targets_list as $target ) {
×
135
                        // trim whitespace and any leading '#'.
136
                        $trimmed = ltrim( trim( $target ), '#' );
×
137
                        if ( empty( $trimmed ) ) {
×
138
                                continue;
×
139
                        }
140
                        $targets[] = '#' . $trimmed;
×
141
                }
142
                add_filter(
×
143
                        'edac_filter_frontend_fixes_data',
×
144
                        function ( $data ) use ( $targets ) {
×
145
                                $data['skip_link'] = [
×
146
                                        'enabled' => true,
×
147
                                        'targets' => $targets,
×
148
                                ];
×
149
                                return $data;
×
150
                        }
×
151
                );
×
152
        }
153

154
        /**
155
         * Injects the style rules for the skip link.
156
         *
157
         * @return void
158
         */
159
        public function add_skip_link_styles() {
160
                ?>
161
                <style id="edac-fix-skip-link-styles">
×
162
                        .edac-bypass-block {
×
163
                                border: 0;
×
164
                                clip: rect(1px, 1px, 1px, 1px);
×
165
                                clip-path: inset(50%);
×
166
                                height: 1px;
×
167
                                margin: -1px;
×
168
                                overflow: hidden;
×
169
                                padding: 0;
×
170
                                position: absolute !important;
×
171
                                width: 1px;
×
172
                                word-wrap: normal !important;
×
173
                        }
×
174

175
                        .edac-bypass-block:focus-within {
×
176
                                background-color: #ececec;
×
177
                                clip: auto !important;
×
178
                                -webkit-clip-path: none;
×
179
                                clip-path: none;
×
180
                                display: block;
×
181
                                font-size: 1rem;
×
182
                                height: auto;
×
183
                                left: 5px;
×
184
                                line-height: normal;
×
185
                                padding: 8px 22px 10px;
×
186
                                top: 5px;
×
187
                                width: auto;
×
188
                                z-index: 100000;
×
189
                        }
×
190

191
                        .admin-bar .edac-bypass-block,
×
192
                        .admin-bar .edac-bypass-block:focus-within {
×
193
                                top: 37px;
×
194
                        }
×
195

196
                        @media screen and (max-width: 782px) {
×
197
                                .admin-bar .edac-bypass-block,
×
198
                                .admin-bar .edac-bypass-block:focus-within {
×
199
                                        top: 51px;
×
200
                                }
×
201
                        }
×
202

203
                        a.edac-bypass-block {
×
204
                                display: block;
×
205
                                margin: 0.5rem 0;
×
206
                                color: #444;
×
207
                                text-decoration: underline;
×
208
                        }
×
209

210
                        a.edac-bypass-block:hover,
×
211
                        a.edac-bypass-block:focus {
×
212
                                text-decoration: none;
×
213
                                color: #006595;
×
214
                        }
×
215

216
                        a.edac-bypass-block:focus {
×
217
                                outline: 2px solid #000;
×
218
                                outline-offset: 2px;
×
219
                        }
×
220
                </style>
×
221
                <?php
×
222
        }
223

224
        /**
225
         * Callback for the skip link section.
226
         *
227
         * @return void
228
         */
229
        public function skip_link_section_callback() {
230
                ?>
231
                <p>
×
232
                        <?php
×
233
                        echo wp_kses_post(
×
234
                                sprintf(
×
235
                                        // translators: %1$s: opening anchor tag, %2$s: closing anchor tag.
236
                                        __( 'If your theme is not already adding a skip link that allows keyboard users to bypass the navigation and quickly jump to the main content, enable skip links here. %1$sLearn more about skip links.%2$s', 'accessibility-checker' ),
×
NEW
237
                                        '<a href="' . esc_url( edac_link_wrapper( 'https://equalizedigital.com/how-to-make-your-wordpress-site-more-accessible-with-skip-links/', 'fix-description', 'skip-link', false ) ) . '">',
×
238
                                        '</a>'
×
239
                                )
×
240
                        );
×
241
                        ?>
242
                </p>
×
243
                <?php
×
244
        }
245

246
        /**
247
         * Adds the skip link code to the page.
248
         *
249
         * @return void
250
         */
251
        public function add_skip_link() {
252

253
                $targets_string = get_option( 'edac_fix_add_skip_link_target_id', '' );
×
254

255
                $nav_targets_string = get_option( 'edac_fix_add_skip_link_nav_target_id', '' );
×
256

257
                if ( ! $targets_string && ! $nav_targets_string ) {
×
258
                        return;
×
259
                }
260
                ?>
261
                <template id="skip-link-template">
×
262
                                <?php if ( $targets_string ) : ?>
×
263
                                        <a class="edac-skip-link--content edac-bypass-block" href=""><?php esc_html_e( 'Skip to content', 'accessibility-checker' ); ?></a>
×
264
                                <?php endif; ?>
265
                        <?php
×
266
                        if ( $nav_targets_string ) :
×
267
                                ?>
268
                                        <?php
×
269
                                        if ( $nav_targets_string ) :
×
270
                                                $nav_target = ltrim( trim( $nav_targets_string ), '#' );
×
271
                                                ?>
272
                                                <a class="edac-skip-link--navigation edac-bypass-block" href="#<?php echo esc_attr( $nav_target ); ?>"><?php esc_html_e( 'Skip to navigation', 'accessibility-checker' ); ?></a>
×
273
                                        <?php endif; ?>
274
                        <?php endif; ?>
×
275
                        <?php $this->add_skip_link_styles(); ?>
×
276
                </template>
×
277
                <?php
×
278
        }
279
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc