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

equalizedigital / accessibility-checker / 21996744422

13 Feb 2026 05:42PM UTC coverage: 57.265% (-0.5%) from 57.761%
21996744422

push

github

web-flow
Merge pull request #1393 from equalizedigital/william/no-issue/remove-ReadMoreAddTitleFix-as-it-went-unused

Remove the not-yet-used ReadMoreAddTitleFix

4146 of 7240 relevant lines covered (57.27%)

3.47 hits per line

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

43.7
/includes/classes/Fixes/FixesManager.php
1
<?php
2
/**
3
 * Manager class for fixes.
4
 *
5
 * @package Accessibility_Checker
6
 */
7

8
namespace EqualizeDigital\AccessibilityChecker\Fixes;
9

10
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\AddFileSizeAndTypeToLinkedFilesFix;
11
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\AddLabelToUnlabelledFormFieldsFix;
12
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\AddMissingOrEmptyPageTitleFix;
13
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\AddNewWindowWarningFix;
14
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\BlockPDFUploadsFix;
15
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\CommentSearchLabelFix;
16
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\HTMLLangAndDirFix;
17
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\RemoveTitleIfPrefferedAccessibleNameFix;
18
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\PreventLinksOpeningNewWindowFix;
19
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\SkipLinkFix;
20
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\TabindexFix;
21
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\LinkUnderline;
22
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\MetaViewportScalableFix;
23
use EqualizeDigital\AccessibilityChecker\Fixes\Fix\FocusOutlineFix;
24
use EqualizeDigital\AccessibilityChecker\Admin\AdminPage\FixesPage;
25

26
if ( ! defined( 'ABSPATH' ) ) {
27
        exit;
28
}
29

30
/**
31
 * Manager class for fixes.
32
 *
33
 * @since 1.16.0
34
 */
35
class FixesManager {
36

37
        /**
38
         * The single instance of the class.
39
         *
40
         * @var FixesManager|null
41
         */
42
        private static $instance = null;
43

44
        /**
45
         * Whether the theme has the accessibility-ready tag.
46
         *
47
         * @var bool|null
48
         */
49
        private static $theme_is_accessibility_ready = null;
50

51
        /**
52
         * The fixes.
53
         *
54
         * @var array
55
         */
56
        private $fixes = [];
57

58
        /**
59
         * Private constructor to prevent direct instantiation.
60
         */
61
        private function __construct() {
62
                $this->maybe_enqueue_frontend_scripts();
6✔
63
                $this->maybe_enqueue_thickbox();
6✔
64

65
                self::$theme_is_accessibility_ready = self::is_theme_accessibility_ready();
6✔
66
        }
67

68
        /**
69
         * Maybe enqueue the thickbox script.
70
         *
71
         * This powers the modal that is used to display fix settings in the editor.
72
         */
73
        public function maybe_enqueue_thickbox() {
74
                add_action(
6✔
75
                        'admin_enqueue_scripts',
6✔
76
                        function () {
6✔
77
                                add_thickbox();
×
78
                        }
6✔
79
                );
6✔
80
        }
81

82
        /**
83
         * Get the single instance of the class.
84
         *
85
         * @return FixesManager
86
         */
87
        public static function get_instance() {
88
                if ( null === self::$instance ) {
6✔
89
                        self::$instance = new self();
6✔
90
                }
91
                return self::$instance;
6✔
92
        }
93

94
        /**
95
         * Maybe enqueue the frontend scripts.
96
         */
97
        private function maybe_enqueue_frontend_scripts() {
98

99
                if (
100
                        ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
6✔
101
                        ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ||
6✔
102
                        ( defined( 'DOING_CRON' ) && DOING_CRON ) ||
6✔
103
                        ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
6✔
104
                ) {
105
                        return;
×
106
                }
107

108
                // Consider adding this only if we can determine at least 1 of the fixes are enabled.
109
                add_action(
6✔
110
                        'wp_enqueue_scripts',
6✔
111
                        function () {
6✔
112
                                wp_enqueue_script( 'edac-frontend-fixes', EDAC_PLUGIN_URL . 'build/frontendFixes.bundle.js', [], EDAC_VERSION, true );
×
113
                                wp_set_script_translations( 'edac-frontend-fixes', 'accessibility-checker', plugin_dir_path( EDAC_PLUGIN_FILE ) . 'languages' );
×
114
                                wp_localize_script(
×
115
                                        'edac-frontend-fixes',
×
116
                                        'edac_frontend_fixes',
×
117
                                        apply_filters( 'edac_filter_frontend_fixes_data', [] )
×
118
                                );
×
119
                                do_action( 'edac_action_enqueue_frontend_fixes' );
×
120
                        }
6✔
121
                );
6✔
122
        }
123

124
        /**
125
         * Load the fixes.
126
         */
127
        private function load_fixes() {
128
                $fixes = apply_filters(
×
129
                        'edac_filter_fixes',
×
130
                        [
×
131
                                SkipLinkFix::class,
×
132
                                CommentSearchLabelFix::class,
×
133
                                HTMLLangAndDirFix::class,
×
134
                                TabindexFix::class,
×
135
                                RemoveTitleIfPrefferedAccessibleNameFix::class,
×
136
                                LinkUnderline::class,
×
137
                                MetaViewportScalableFix::class,
×
138
                                PreventLinksOpeningNewWindowFix::class,
×
139
                                FocusOutlineFix::class,
×
140
                                BlockPDFUploadsFix::class,
×
141
                                AddFileSizeAndTypeToLinkedFilesFix::class,
×
142
                                AddMissingOrEmptyPageTitleFix::class,
×
143
                                AddLabelToUnlabelledFormFieldsFix::class,
×
144
                                AddNewWindowWarningFix::class,
×
145
                        ]
×
146
                );
×
147
                foreach ( $fixes as $fix ) {
×
148
                        if ( is_subclass_of( $fix, '\EqualizeDigital\AccessibilityChecker\Fixes\FixInterface' ) ) {
×
149
                                if ( ! isset( $this->fixes[ $fix::get_slug() ] ) ) {
×
150
                                        $this->fixes[ $fix::get_slug() ] = ( new $fix() );
×
151
                                }
152
                        }
153
                }
154
        }
155

156
        /**
157
         * Get a fix by its slug.
158
         *
159
         * @param string $slug The fix slug.
160
         *
161
         * @return FixInterface|null
162
         */
163
        public function get_fix( $slug ) {
164
                return isset( $this->fixes[ $slug ] ) ? $this->fixes[ $slug ] : null;
×
165
        }
166

167
        /**
168
         * Get the fixes settings.
169
         *
170
         * Returns an array of all the fix settings and their values along with a pro or not flag.
171
         *
172
         * @return array
173
         */
174
        public function get_fixes_settings() {
175
                $fixes_array = [];
6✔
176
                foreach ( $this->fixes as $fix ) {
6✔
177

178
                        $fields = [];
4✔
179
                        foreach ( $fix->get_fields_array() as $field_slug => $field ) {
4✔
180
                                $fields[ $field_slug ] = get_option( $field_slug, $field['default'] ?? 0 );
4✔
181
                        }
182

183
                        $fixes_array[ $fix::get_slug() ] = [
4✔
184
                                'fields' => $fields,
4✔
185
                                'is_pro' => isset( $fix->is_pro ) ? $fix->is_pro : false,
4✔
186
                        ];
4✔
187
                }
188
                return $fixes_array;
6✔
189
        }
190

191
        /**
192
         * Register the fixes.
193
         */
194
        public function register_fixes() {
195
                $this->load_fixes();
×
196

197
                foreach ( $this->fixes as $fix ) {
×
198
                        $fix->register();
×
199
                        $this->maybe_run_fix( $fix );
×
200
                }
201
        }
202

203
        /**
204
         * Maybe run a fix depending on current context.
205
         *
206
         * @param FixInterface $fix The fix to maybe run.
207
         */
208
        public function maybe_run_fix( $fix ) {
209
                if ( 'backend' === $fix::get_type() && is_admin() ) {
×
210
                        $fix->run();
×
211
                } elseif ( 'frontend' === $fix::get_type() && ! is_admin() ) {
×
212
                        $fix->run();
×
213
                } elseif ( 'everywhere' === $fix::get_type() ) {
×
214
                        $fix->run();
×
215
                }
216
        }
217

218
        /**
219
         * Check if the theme is accessibility ready.
220
         *
221
         * True if the theme has the tag, false otherwise.
222
         *
223
         * @return bool
224
         */
225
        public static function is_theme_accessibility_ready() {
226
                if ( null !== self::$theme_is_accessibility_ready ) {
6✔
227
                        return self::$theme_is_accessibility_ready;
6✔
228
                }
229

230
                $theme = wp_get_theme();
×
231
                $tags  = $theme->get( 'Tags' );
×
232

233
                self::$theme_is_accessibility_ready = is_array( $tags ) && in_array( 'accessibility-ready', $tags, true );
×
234
                return self::$theme_is_accessibility_ready;
×
235
        }
236

237
        /**
238
         * Maybe show a notice if the theme is accessibility-ready.
239
         */
240
        public static function maybe_show_accessibility_ready_conflict_notice() {
241
                if ( self::is_theme_accessibility_ready() ) {
×
242
                        ?>
243
                        <span class="edac-notice--accessibility-ready-conflict">
×
244
                                <?php esc_html_e( 'Note: This setting is not recommended for themes that are already accessibility-ready.', 'accessibility-checker' ); ?>
×
245
                        </span>
×
246
                        <?php
×
247
                }
248
        }
249

250
        /**
251
         * Register the rest routes.
252
         *
253
         * @return void
254
         */
255
        public function register_rest_routes() {
256
                register_rest_route(
6✔
257
                        'edac/v1',
6✔
258
                        '/fixes',
6✔
259
                        [
6✔
260
                                'methods'             => 'GET',
6✔
261
                                'callback'            => [ $this, 'get_fixes' ],
6✔
262
                                'permission_callback' => function () {
6✔
263
                                        return current_user_can( apply_filters( 'edac_filter_settings_capability', 'manage_options' ) );
×
264
                                },
6✔
265
                        ]
6✔
266
                );
6✔
267

268
                register_rest_route(
6✔
269
                        'edac/v1',
6✔
270
                        '/fixes/update',
6✔
271
                        [
6✔
272
                                'methods'             => 'POST',
6✔
273
                                'callback'            => [ $this, 'update_fix_settings' ],
6✔
274
                                'permission_callback' => function () {
6✔
275
                                        return current_user_can( apply_filters( 'edac_filter_settings_capability', 'manage_options' ) );
×
276
                                },
6✔
277
                        ]
6✔
278
                );
6✔
279
        }
280

281
        /**
282
         * Handle the request to set a fix.
283
         *
284
         * @param \WP_REST_Request $request The request recieved through a rest call.
285
         *
286
         * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response
287
         */
288
        public function update_fix_settings( $request ) {
289
                // get body of the request.
290
                $body = $request->get_json_params();
×
291

292
                // loop through body and find fixes for those items.
293
                foreach ( $body as $rule_slug => $settings ) {
×
294
                        $fix        = $this->get_fix( $rule_slug );
×
295
                        $fix_fields = $fix->get_fields_array();
×
296
                        if ( ! $fix ) {
×
297
                                return new \WP_Error( 'edac_fix_not_found', esc_html__( 'Fix not found', 'accessibility-checker' ), [ 'status' => 404 ] );
×
298
                        }
299

300
                        foreach ( $settings as $setting => $value ) {
×
301
                                $sanitizer = isset( $fix_fields[ $setting ]['sanitize_callback'] ) ? $fix_fields[ $setting ]['sanitize_callback'] : [ FixesPage::class, 'sanitize_' . $fix_fields[ $setting ]['type'] ];
×
302
                                if ( ! $sanitizer || ! is_callable( $sanitizer ) ) {
×
303
                                        // no sanitizer, do not save.
304
                                        continue;
×
305
                                }
306
                                update_option( $setting, $sanitizer( $value ) );
×
307
                        }
308
                }
309

310
                return rest_ensure_response( [ 'enabled' => $enabled ] );
×
311
        }
312
}
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