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

equalizedigital / accessibility-checker / 15452164054

04 Jun 2025 08:32PM UTC coverage: 28.973%. First build
15452164054

Pull #1004

github

web-flow
Merge 28c013970 into 147ba9c27
Pull Request #1004: Release v1.24.0

7 of 92 new or added lines in 13 files covered. (7.61%)

1495 of 5160 relevant lines covered (28.97%)

1.5 hits per line

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

0.0
/admin/class-ajax.php
1
<?php
2
/**
3
 * Class file for admin notices
4
 *
5
 * @package Accessibility_Checker
6
 */
7

8
namespace EDAC\Admin;
9

10
use EDAC\Admin\OptIn\Email_Opt_In;
11
use EDAC\Inc\Summary_Generator;
12
use EqualizeDigital\AccessibilityChecker\Admin\AdminPage\FixesPage;
13
use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager;
14

15
/**
16
 * Class that handles ajax requests.
17
 */
18
class Ajax {
19

20
        /**
21
         * Constructor function for the class.
22
         */
23
        public function __construct() {
24
        }
×
25

26
        /**
27
         * Initialize hooks.
28
         *
29
         * @return void
30
         */
31
        public function init_hooks() {
32
                add_action( 'wp_ajax_edac_summary_ajax', [ $this, 'summary' ] );
×
33
                add_action( 'wp_ajax_edac_details_ajax', [ $this, 'details' ] );
×
34
                add_action( 'wp_ajax_edac_readability_ajax', [ $this, 'readability' ] );
×
35
                add_action( 'wp_ajax_edac_insert_ignore_data', [ $this, 'add_ignore' ] );
×
36
                add_action( 'wp_ajax_edac_update_simplified_summary', [ $this, 'simplified_summary' ] );
×
37
                add_action( 'wp_ajax_edac_dismiss_welcome_cta_ajax', [ $this, 'dismiss_welcome_cta' ] );
×
38
                add_action( 'wp_ajax_edac_dismiss_dashboard_cta_ajax', [ $this, 'dismiss_dashboard_cta' ] );
×
39
                ( new Email_Opt_In() )->register_ajax_handlers();
×
40
        }
41

42
        /**
43
         * Summary Ajax
44
         *
45
         * @return void
46
         *
47
         *  - '-1' means that nonce could not be varified
48
         *  - '-2' means that the post ID was not specified
49
         *  - '-3' means that there isn't any summary data to return
50
         */
51
        public function summary() {
52

53
                // nonce security.
54
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
55

NEW
56
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
57
                        wp_send_json_error( $error );
×
58

59
                }
60

61
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
62

NEW
63
                        $error = new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) );
×
64
                        wp_send_json_error( $error );
×
65

66
                }
67

68
                $html            = [];
×
69
                $html['content'] = '';
×
70

71
                // password check.
72
                if ( (bool) get_option( 'edac_password_protected' ) === true ) {
×
73
                        $admin_notices              = new \EDAC\Admin\Admin_Notices();
×
74
                        $notice_text                = $admin_notices->edac_password_protected_notice_text();
×
75
                        $html['password_protected'] = $notice_text;
×
76
                        $html['content']           .= '<div class="edac-summary-notice">' . $notice_text . '</div>';
×
77
                }
78

79
                $post_id                   = (int) $_REQUEST['post_id'];
×
80
                $summary                   = ( new Summary_Generator( $post_id ) )->generate_summary();
×
81
                $simplified_summary_text   = '';
×
82
                $simplified_summary_prompt = get_option( 'edac_simplified_summary_prompt' );
×
83
                $simplified_summary        = get_post_meta( $post_id, '_edac_simplified_summary', true ) ? get_post_meta( $post_id, '_edac_simplified_summary', true ) : '';
×
84

85
                $simplified_summary_grade = 0;
×
86
                if ( class_exists( 'DaveChild\TextStatistics\TextStatistics' ) ) {
×
87
                        $text_statistics          = new \DaveChild\TextStatistics\TextStatistics();
×
88
                        $simplified_summary_grade = (int) floor( $text_statistics->fleschKincaidGradeLevel( $simplified_summary ) );
×
89
                }
90
                $simplified_summary_grade_failed = ( $simplified_summary_grade > 9 ) ? true : false;
×
91

92
                $simplified_summary_text = esc_html__( 'A Simplified summary has not been included for this content.', 'accessibility-checker' );
×
93
                if ( 'none' !== $simplified_summary_prompt ) {
×
94
                        if ( $summary['content_grade'] <= 9 ) {
×
95
                                $simplified_summary_text = esc_html__( 'Your content has a reading level at or below 9th grade and does not require a simplified summary.', 'accessibility-checker' );
×
96
                        } elseif ( $summary['simplified_summary'] ) {
×
97
                                if ( $simplified_summary_grade_failed ) {
×
98
                                        $simplified_summary_text = esc_html__( 'The reading level of the simplified summary is too high.', 'accessibility-checker' );
×
99
                                } else {
100
                                        $simplified_summary_text = esc_html__( 'A simplified summary has been included for this content.', 'accessibility-checker' );
×
101
                                }
102
                        }
103
                }
104

105
                $html['content'] .= '<ul class="edac-summary-grid">';
×
106

107
                        $html['content'] .= '<li class="edac-summary-total" aria-label="' . $summary['passed_tests'] . '% Passed Tests">';
×
108

109
                                $html['content'] .= '<div class="edac-summary-total-progress-circle ' . ( ( $summary['passed_tests'] > 50 ) ? ' over50' : '' ) . '">
×
110
                                        <div class="edac-summary-total-progress-circle-label">
111
                                                <div class="edac-panel-number">' . $summary['passed_tests'] . '%</div>
×
112
                                                <div class="edac-panel-number-label">Passed Tests<sup><a href="#edac-summary-disclaimer" aria-label="About passed tests.">*</a></sup></div>
113
                                        </div>
114
                                        <div class="left-half-clipper">
115
                                                <div class="first50-bar"></div>
116
                                                <div class="value-bar" style="transform: rotate(' . $summary['passed_tests'] * 3.6 . 'deg);"></div>
×
117
                                        </div>
118
                                </div>';
×
119

120
                                $html['content'] .= '<div class="edac-summary-total-mobile">
×
121
                                        <div class="edac-panel-number">' . $summary['passed_tests'] . '%</div>
×
122
                                        <div class="edac-panel-number-label">Passed Tests<sup><a href="#edac-summary-disclaimer" aria-label="About passed tests.">*</a></sup></div>
123
                                        <div class="edac-summary-total-mobile-bar"><span style="width:' . ( $summary['passed_tests'] ) . '%;"></span></div>
×
124
                                </div>';
×
125

126
                        $html['content'] .= '</li>';
×
127

128
                        $html['content'] .= '
×
129
                                ' . edac_generate_summary_stat(
×
130
                                'edac-summary-errors',
×
131
                                $summary['errors'],
×
132
                                /* translators: %s: Number of errors */
133
                                        sprintf( _n( '%s Error', '%s Errors', $summary['errors'], 'accessibility-checker' ), $summary['errors'] )
×
134
                        ) . '
×
135
                                ' . edac_generate_summary_stat(
×
136
                                'edac-summary-contrast',
×
137
                                $summary['contrast_errors'],
×
138
                                /* translators: %s: Number of contrast errors */
139
                                        sprintf( _n( '%s Contrast Error', '%s Contrast Errors', $summary['contrast_errors'], 'accessibility-checker' ), $summary['contrast_errors'] )
×
140
                        ) . '
×
141
                                ' . edac_generate_summary_stat(
×
142
                                'edac-summary-warnings',
×
143
                                $summary['warnings'],
×
144
                                /* translators: %s: Number of warnings */
145
                                        sprintf( _n( '%s Warning', '%s Warnings', $summary['warnings'], 'accessibility-checker' ), $summary['warnings'] )
×
146
                        ) . '
×
147
                                ' . edac_generate_summary_stat(
×
148
                                'edac-summary-ignored',
×
149
                                $summary['ignored'],
×
150
                                /* translators: %s: Number of ignored items */
151
                                        sprintf( _n( '%s Ignored Item', '%s Ignored Items', $summary['ignored'], 'accessibility-checker' ), $summary['ignored'] )
×
152
                        ) . '
×
153

154
                </ul>
155
                <div class="edac-summary-readability">
156
                        <div class="edac-summary-readability-level">
157
                                <div><img src="' . EDAC_PLUGIN_URL . 'assets/images/readability icon navy.png" alt="" width="54"></div>
×
158
                                <div class="edac-panel-number' . ( ( (int) $summary['content_grade'] <= 9 || 'none' === $simplified_summary_prompt ) ? ' passed-text-color' : ' failed-text-color' ) . '">
×
159
                                        ' . $summary['readability'] . '
×
160
                                </div>
161
                                <div class="edac-panel-number-label' . ( ( (int) $summary['readability'] <= 9 || 'none' === $simplified_summary_prompt ) ? ' passed-text-color' : ' failed-text-color' ) . '">Reading <br />Level</div>
×
162
                        </div>
163
                        <div class="edac-summary-readability-summary">
164
                                <div class="edac-summary-readability-summary-icon' . ( ( ( 'none' === $simplified_summary_prompt || $summary['simplified_summary'] || (int) $summary['content_grade'] <= 9 ) && ! $simplified_summary_grade_failed ) ? ' active' : '' ) . '"></div>
×
165
                                <div class="edac-summary-readability-summary-text' . ( ( ( 'none' === $simplified_summary_prompt || $summary['simplified_summary'] || (int) $summary['content_grade'] <= 9 ) && ! $simplified_summary_grade_failed ) ? ' active' : '' ) . '">' . $simplified_summary_text . '</div>
×
166
                        </div>
167
                </div>
168
                <div id="edac-summary-disclaimer" class="edac-summary-disclaimer"><small>* True accessibility requires manual testing in addition to automated scans. <a href="https://a11ychecker.com/help4280">Learn how to manually test for accessibility</a>.</small></div>
169
                ';
×
170

171
                if ( ! $html ) {
×
172

NEW
173
                        $error = new \WP_Error( '-3', __( 'No summary to return', 'accessibility-checker' ) );
×
174
                        wp_send_json_error( $error );
×
175

176
                }
177

178
                wp_send_json_success( wp_json_encode( $html ) );
×
179
        }
180

181
        /**
182
         * Details Ajax
183
         *
184
         * @return void
185
         *
186
         *  - '-1' means that nonce could not be varified
187
         *  - '-2' means that the post ID was not specified
188
         *  - '-3' means that the table name is not valid
189
         *  - '-4' means that there isn't any details to return
190
         */
191
        public function details() {
192

193
                // nonce security.
194
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
195

NEW
196
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
197
                        wp_send_json_error( $error );
×
198

199
                }
200

201
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
202

NEW
203
                        $error = new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) );
×
204
                        wp_send_json_error( $error );
×
205

206
                }
207

208
                $html = '';
×
209
                global $wpdb;
×
210
                $table_name = edac_get_valid_table_name( $wpdb->prefix . 'accessibility_checker' );
×
211
                $postid     = (int) $_REQUEST['post_id'];
×
212
                $siteid     = get_current_blog_id();
×
213

214
                // Send error if table name is not valid.
215
                if ( ! $table_name ) {
×
216

NEW
217
                        $error = new \WP_Error( '-3', __( 'Invalid table name', 'accessibility-checker' ) );
×
218
                        wp_send_json_error( $error );
×
219

220
                }
221

222
                $rules = edac_register_rules();
×
223
                if ( $rules ) {
×
224

225
                        // if ANWW is active remove link_blank for details meta box.
NEW
226
                        if ( defined( 'ANWW_VERSION' ) ) {
×
227
                                $rules = edac_remove_element_with_value( $rules, 'slug', 'link_blank' );
×
228
                        }
229

230
                        // separate rule types.
231
                        $passed_rules  = [];
×
232
                        $error_rules   = edac_remove_element_with_value( $rules, 'rule_type', 'warning' );
×
233
                        $warning_rules = edac_remove_element_with_value( $rules, 'rule_type', 'error' );
×
234

235
                        // add count, unset passed error rules and add passed rules to array.
236
                        if ( $error_rules ) {
×
237
                                foreach ( $error_rules as $key => $error_rule ) {
×
238
                                        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
239
                                        $count = count( $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment FROM %i where postid = %d and rule = %s and siteid = %d and ignre = %d', $table_name, $postid, $error_rule['slug'], $siteid, 0 ), ARRAY_A ) );
×
240
                                        if ( $count ) {
×
241
                                                $error_rules[ $key ]['count'] = $count;
×
242
                                        } else {
243
                                                $error_rule['count'] = 0;
×
244
                                                $passed_rules[]      = $error_rule;
×
245
                                                unset( $error_rules[ $key ] );
×
246
                                        }
247
                                }
248
                        }
249

250
                        // add count, unset passed warning rules and add passed rules to array.
251
                        if ( $warning_rules ) {
×
252
                                foreach ( $warning_rules as $key => $error_rule ) {
×
253
                                        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
254
                                        $count = count( $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment FROM %i where postid = %d and rule = %s and siteid = %d and ignre = %d', $table_name, $postid, $error_rule['slug'], $siteid, 0 ), ARRAY_A ) );
×
255
                                        if ( $count ) {
×
256
                                                $warning_rules[ $key ]['count'] = $count;
×
257
                                        } else {
258
                                                $error_rule['count'] = 0;
×
259
                                                $passed_rules[]      = $error_rule;
×
260
                                                unset( $warning_rules[ $key ] );
×
261
                                        }
262
                                }
263
                        }
264
                }
265

266
                // sort error rules by count.
267
                usort(
×
268
                        $error_rules,
×
269
                        function ( $a, $b ) {
×
270

271
                                return strcmp( $b['count'], $a['count'] );
×
272
                        }
×
273
                );
×
274

275
                // sort warning rules by count.
276
                usort(
×
277
                        $warning_rules,
×
278
                        function ( $a, $b ) {
×
279

280
                                return strcmp( $b['count'], $a['count'] );
×
281
                        }
×
282
                );
×
283

284
                // sort passed rules array by title.
285
                usort(
×
286
                        $passed_rules,
×
287
                        function ( $a, $b ) {
×
288

289
                                return strcmp( $b['title'], $a['title'] );
×
290
                        }
×
291
                );
×
292

293
                // merge rule arrays together.
294
                $rules = array_merge( $error_rules, $warning_rules, $passed_rules );
×
295

296
                if ( $rules ) {
×
297
                        /**
298
                         * Filters if a user can ignore issues.
299
                         *
300
                         * @since 1.4.0
301
                         *
302
                         * @allowed bool True if allowed, false if not
303
                         */
304
                        $ignore_permission = apply_filters( 'edac_ignore_permission', true );
×
305

306
                        foreach ( $rules as $rule ) {
×
307
                                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
308
                                $results        = $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment, ignre_global FROM %i where postid = %d and rule = %s and siteid = %d', $table_name, $postid, $rule['slug'], $siteid ), ARRAY_A );
×
309
                                $count_classes  = ( 'error' === $rule['rule_type'] ) ? ' edac-details-rule-count-error' : ' edac-details-rule-count-warning';
×
310
                                $count_classes .= ( 0 !== $rule['count'] ) ? ' active' : '';
×
311

312
                                $count_ignored = 0;
×
313
                                $ignores       = array_column( $results, 'ignre' );
×
314
                                if ( $ignores ) {
×
315
                                        foreach ( $ignores as $ignore ) {
×
316
                                                if ( true === (bool) $ignore ) {
×
317
                                                        ++$count_ignored;
×
318
                                                }
319
                                        }
320
                                }
321

322
                                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for interacting with custom database, safe variable used for table name, caching not required for one time operation.
323
                                $expand_rule = count( $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM %i where postid = %d and rule = %s and siteid = %d', $table_name, $postid, $rule['slug'], $siteid ), ARRAY_A ) );
×
324

325
                                $tool_tip_link = edac_documentation_link( $rule );
×
326

327
                                $html .= '<div class="edac-details-rule">';
×
328

329
                                $html .= '<div class="edac-details-rule-title">';
×
330

331
                                $html .= '<h3>';
×
332
                                $html .= '<span class="edac-details-rule-count' . $count_classes . '">' . $rule['count'] . '</span> ';
×
333
                                $html .= esc_html( $rule['title'] );
×
334
                                if ( $count_ignored > 0 ) {
×
335
                                        $html .= '<span class="edac-details-rule-count-ignore">' . $count_ignored . ' Ignored Items</span>';
×
336
                                }
337
                                $html .= '</h3>';
×
338
                                $html .= '<a href="' . $tool_tip_link . '" class="edac-details-rule-information" target="_blank" aria-label="Read documentation for ' . esc_html( $rule['title'] ) . '. ' . esc_attr__( 'Opens in a new window.', 'accessibility-checker' ) . '"><span class="dashicons dashicons-info"></span></a>';
×
339
                                $html .= ( $expand_rule ) ? '<button class="edac-details-rule-title-arrow" aria-expanded="false" aria-controls="edac-details-rule-records-' . $rule['slug'] . '" aria-label="Expand issues for ' . esc_html( $rule['title'] ) . '"><i class="dashicons dashicons-arrow-down-alt2"></i></button>' : '';
×
340

341
                                $html .= '</div>';
×
342

343
                                if ( $results ) {
×
344

345
                                        $html .= '<div id="edac-details-rule-records-' . $rule['slug'] . '" class="edac-details-rule-records">';
×
346

347
                                        $fixes_for_item = [];
×
348
                                        if ( isset( $rule['fixes'] ) && current_user_can( apply_filters( 'edac_filter_settings_capability', 'manage_options' ) ) ) {
×
349
                                                foreach ( $rule['fixes'] as $fix_slug ) {
×
350
                                                        $fixes_for_item[] = FixesManager::get_instance()->get_fix( $fix_slug );
×
351
                                                }
352

353
                                                $controls_id = 'edac-fix-modal-' . $rule['slug'] . '__' . implode( '__', $rule['fixes'] );
×
354
                                                ob_start();
×
355
                                                // NOTE: This is markup to be cloned into a thickbox modal. It gets cloned from the inner div.
356
                                                ?>
357
                                                <div style="display:none">
×
358
                                                        <div id="<?php echo esc_attr( $controls_id ); ?>" class="edac-details-fix-settings fix-settings--container">
×
359
                                                                <div class="setting-row fix-settings--container" data-fix="<?php echo esc_attr( $controls_id ); ?>">
×
360
                                                                        <?php
361
                                                                        printf(
×
362
                                                                                '<p class="modal-opening-message">%s <span class="hide-in-editor">%s</span></p>',
×
363
                                                                                esc_html__( 'These settings enable global fixes across your entire site.', 'accessibility-checker' ),
×
364
                                                                                esc_html__( 'Pages may need to be resaved or a full site scan run to see fixes reflected in reports.', 'accessibility-checker' )
×
365
                                                                        )
×
366
                                                                        ?>
×
367
                                                                        <div class="edac-fix-settings">
×
368
                                                                                <?php
369
                                                                                foreach ( $fixes_for_item as $index => $fix ) :
×
370
                                                                                        ?>
371
                                                                                        <div class="edac-fix-settings--fields">
×
372
                                                                                                <fieldset>
×
373
                                                                                                        <div class="title">
×
374
                                                                                                                <legend>
×
375
                                                                                                                        <h2 class="edac-fix-settings--title"><?php echo esc_html( $fix->get_nicename() ); ?></h2>
×
376
                                                                                                                </legend>
377
                                                                                                        </div>
378
                                                                                                        <?php
379
                                                                                                        foreach ( $fix->get_fields_array() as $name => $field ) {
×
380
                                                                                                                $field['name']     = $name;
×
381
                                                                                                                $field['location'] = 'details-panel';
×
382
                                                                                                                FixesPage::{$field['type']}( $field );
×
383
                                                                                                        }
384
                                                                                                        ?>
385
                                                                                                </fieldset>
×
386
                                                                                                <?php
×
387
                                                                                                // Output the save button only in the last group.
388
                                                                                                if ( count( $fixes_for_item ) === $index + 1 ) :
×
389
                                                                                                        ?>
390
                                                                                                        <div class="edac-fix-settings--action-row">
×
391
                                                                                                                <button role="button" class="button button-primary edac-fix-settings--button--save">
×
392
                                                                                                                        <?php esc_html_e( 'Save', 'accessibility-checker' ); ?>
×
393
                                                                                                                </button>
×
394
                                                                                                                <span class="edac-fix-settings--notice-slot" aria-live="polite" role="alert"></span>
×
395
                                                                                                        </div>
×
396
                                                                                                        <?php
×
397
                                                                                                endif;
398
                                                                                                ?>
399
                                                                                        </div>
×
400
                                                                                <?php endforeach; ?>
×
401
                                                                        </div>
×
402
                                                                </div>
×
403
                                                        </div>
×
404
                                                </div>
×
405
                                                <?php
×
406
                                                $html .= ob_get_clean();
×
407
                                        }
408

409
                                        $html .=
×
410
                                                '<div class="edac-details-rule-records-labels">
×
411
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
NEW
412
                                                                ' . esc_html__( 'Affected Code', 'accessibility-checker' ) . '
×
413
                                                        </div>
414
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
415
                                                                Image
416
                                                        </div>
417
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
418
                                                                Actions
419
                                                        </div>
420
                                                </div>';
×
421

422
                                        foreach ( $results as $row ) {
×
423

424
                                                $id                      = (int) $row['id'];
×
425
                                                $ignore                  = (int) $row['ignre'];
×
426
                                                $ignore_class            = $ignore ? ' active' : '';
×
427
                                                $ignore_label            = $ignore ? 'Ignored' : 'Ignore';
×
428
                                                $ignore_user             = (int) $row['ignre_user'];
×
429
                                                $ignore_user_info        = get_userdata( $ignore_user );
×
430
                                                $ignore_username         = is_object( $ignore_user_info ) ? '<strong>Username:</strong> ' . $ignore_user_info->user_login : '';
×
431
                                                $ignore_date             = ( $row['ignre_date'] && '0000-00-00 00:00:00' !== $row['ignre_date'] ) ? '<strong>Date:</strong> ' . gmdate( 'F j, Y g:i a', strtotime( esc_html( $row['ignre_date'] ) ) ) : '';
×
432
                                                $ignore_comment          = esc_html( $row['ignre_comment'] );
×
433
                                                $ignore_action           = $ignore ? 'disable' : 'enable';
×
434
                                                $ignore_type             = $rule['rule_type'];
×
435
                                                $ignore_submit_label     = $ignore ? 'Stop Ignoring' : 'Ignore This ' . $ignore_type;
×
436
                                                $ignore_comment_disabled = $ignore ? 'disabled' : '';
×
437
                                                $ignore_global           = (int) $row['ignre_global'];
×
438

439
                                                // check for images and svgs in object code.
440
                                                $media      = edac_parse_html_for_media( $row['object'] );
×
441
                                                $object_img = $media['img'];
×
442
                                                $object_svg = $media['svg'];
×
443

444
                                                $html .= '<h4 class="screen-reader-text">Issue ID ' . $id . '</h4>';
×
445

446
                                                $html .= '<div id="edac-details-rule-records-record-' . $id . '" class="edac-details-rule-records-record">';
×
447

448
                                                $html .= '<div class="edac-details-rule-records-record-cell edac-details-rule-records-record-object">';
×
449

450
                                                $html .= '<code>' . esc_html( $row['object'] ) . '</code>';
×
451

452
                                                $html .= '</div>';
×
453

454
                                                $html .= '<div class="edac-details-rule-records-record-cell edac-details-rule-records-record-image">';
×
455

456
                                                if ( $object_img ) {
×
457
                                                        $html .= '<img src="' . $object_img . '" alt="image for issue ' . $id . '" />';
×
458
                                                } elseif ( $object_svg ) {
×
459
                                                        $html .= $object_svg;
×
460
                                                }
461

462
                                                $html .= '</div>';
×
463

464
                                                $html .= '<div class="edac-details-rule-records-record-cell edac-details-rule-records-record-actions">';
×
465

466
                                                if ( ! isset( $rule['viewable'] ) || $rule['viewable'] ) {
×
467

468
                                                        $url = add_query_arg(
×
469
                                                                [
×
470
                                                                        'edac'       => $id,
×
471
                                                                        'edac_nonce' => wp_create_nonce( 'edac_highlight' ),
×
472
                                                                ],
×
473
                                                                get_the_permalink( $postid )
×
474
                                                        );
×
475

476
                                                        // Translators: %d is the issue ID.
477
                                                        $aria_label = sprintf( __( 'View Issue ID %d on website, opens a new window', 'accessibility-checker' ), $id );
×
478
                                                        $html      .= '<a href="' . $url . '" class="edac-details-rule-records-record-actions-highlight-front" target="_blank" aria-label="' . esc_attr( $aria_label ) . '" ><span class="dashicons dashicons-welcome-view-site"></span>' . __( 'View on page', 'accessibility-checker' ) . '</a>';
×
479
                                                }
480

481
                                                if ( true === $ignore_permission ) {
×
482
                                                        $html .= '<button class="edac-details-rule-records-record-actions-ignore' . $ignore_class . '" aria-expanded="false" aria-controls="edac-details-rule-records-record-ignore-' . $row['id'] . '">' . EDAC_SVG_IGNORE_ICON . '<span class="edac-details-rule-records-record-actions-ignore-label">' . $ignore_label . '</span></button>';
×
483
                                                }
484

485
                                                if ( ! empty( $fixes_for_item ) ) {
×
486
                                                        $html .= sprintf(
×
487
                                                                '<button class="edac-details-rule-records-record-actions-fix"
×
488
                                                                        aria-haspopup="true"
489
                                                                        aria-controls="%1$s"
490
                                                                        aria-label="%2$s"
491
                                                                        type="button"
492
                                                                >
493
                                                                        <span class="dashicons dashicons-admin-tools"></span>
494
                                                                        %3$s
495
                                                                </button>',
×
496
                                                                esc_attr( $controls_id ),
×
497
                                                                esc_attr( __( 'Fix: ', 'accessibility-checker' ) . $fixes_for_item[0]->get_nicename() ),
×
498
                                                                esc_html__( 'Fix', 'accessibility-checker' )
×
499
                                                        );
×
500
                                                }
501

502
                                                $html .= '</div>';
×
503

504
                                                $html .= '<div id="edac-details-rule-records-record-ignore-' . $row['id'] . '" class="edac-details-rule-records-record-ignore">';
×
505

506
                                                $html .= '<div class="edac-details-rule-records-record-ignore-info">';
×
507
                                                $html .= '<span class="edac-details-rule-records-record-ignore-info-user">' . $ignore_username . '</span>';
×
508

509
                                                $html .= ' <span class="edac-details-rule-records-record-ignore-info-date">' . $ignore_date . '</span>';
×
510
                                                $html .= '</div>';
×
511

512
                                                $html .= ( true === $ignore_permission || ! empty( $ignore_comment ) ) ? '<label for="edac-details-rule-records-record-ignore-comment-' . $id . '">Comment</label><br>' : '';
×
513
                                                $html .= ( true === $ignore_permission || ! empty( $ignore_comment ) ) ? '<textarea rows="4" class="edac-details-rule-records-record-ignore-comment" id="edac-details-rule-records-record-ignore-comment-' . $id . '" ' . $ignore_comment_disabled . '>' . $ignore_comment . '</textarea>' : '';
×
514

515
                                                if ( $ignore_global ) {
×
516
                                                        $html .= ( true === $ignore_permission ) ? '<a href="' . admin_url( 'admin.php?page=accessibility_checker_ignored&tab=global' ) . '" class="edac-details-rule-records-record-ignore-global">Manage Globally Ignored</a>' : '';
×
517
                                                } else {
518
                                                        $html .= ( true === $ignore_permission ) ? '<button class="edac-details-rule-records-record-ignore-submit" data-id=' . $id . ' data-action=' . $ignore_action . ' data-type=' . $ignore_type . '>' . EDAC_SVG_IGNORE_ICON . ' <span class="edac-details-rule-records-record-ignore-submit-label">' . $ignore_submit_label . '<span></button>' : '';
×
519
                                                }
520

521
                                                $html .= ( false === $ignore_permission && false === $ignore ) ? __( 'Your user account doesn\'t have permission to ignore this issue.', 'accessibility-checker' ) : '';
×
522

523
                                                $html .= '</div>';
×
524

525
                                                $html .= '</div>';
×
526

527
                                        }
528

529
                                        $html .= '</div>';
×
530

531
                                }
532

533
                                $html .= '</div>';
×
534
                        }
535
                }
536

537
                if ( ! $html ) {
×
538

NEW
539
                        $error = new \WP_Error( '-4', __( 'No details to return', 'accessibility-checker' ) );
×
540
                        wp_send_json_error( $error );
×
541

542
                }
543

544
                wp_send_json_success( wp_json_encode( $html ) );
×
545
        }
546

547
        /**
548
         * Readability Ajax
549
         *
550
         * @return void
551
         *
552
         *  - '-1' means that nonce could not be varified
553
         *  - '-2' means that the post ID was not specified
554
         *  - '-3' means that there isn't any readability data to return
555
         */
556
        public function readability() {
557

558
                // nonce security.
559
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
560

NEW
561
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
562
                        wp_send_json_error( $error );
×
563

564
                }
565

566
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
567

NEW
568
                        $error = new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) );
×
569
                        wp_send_json_error( $error );
×
570

571
                }
572

573
                $post_id                     = (int) $_REQUEST['post_id'];
×
574
                $html                        = '';
×
575
                $simplified_summary          = get_post_meta( $post_id, '_edac_simplified_summary', true ) ? get_post_meta( $post_id, '_edac_simplified_summary', true ) : '';
×
576
                $simplified_summary_position = get_option( 'edac_simplified_summary_position', $default = false );
×
577
                $content_post                = get_post( $post_id );
×
578
                $content                     = $content_post->post_content;
×
579
                $content                     = apply_filters( 'the_content', $content );
×
580

581
                /**
582
                 * Filter the content used for reading grade readability analysis.
583
                 *
584
                 * @since 1.4.0
585
                 *
586
                 * @param string $content The content to be filtered.
587
                 * @param int    $post_id The post ID.
588
                 */
589
                $content = apply_filters( 'edac_filter_readability_content', $content, $post_id );
×
590
                $content = wp_filter_nohtml_kses( $content );
×
591
                $content = str_replace( ']]>', ']]&gt;', $content );
×
592

593
                // get readability metadata and determine if a simplified summary is required.
594
                $edac_summary           = get_post_meta( $post_id, '_edac_summary', true );
×
595
                $post_grade_readability = ( isset( $edac_summary['readability'] ) ) ? $edac_summary['readability'] : 0;
×
596
                $post_grade             = (int) filter_var( $post_grade_readability, FILTER_SANITIZE_NUMBER_INT );
×
597
                $post_grade_failed      = ( $post_grade < 9 ) ? false : true;
×
598

599
                $simplified_summary_grade = 0;
×
600
                if ( class_exists( 'DaveChild\TextStatistics\TextStatistics' ) ) {
×
601
                        $text_statistics          = new \DaveChild\TextStatistics\TextStatistics();
×
602
                        $simplified_summary_grade = (int) floor( $text_statistics->fleschKincaidGradeLevel( $simplified_summary ) );
×
603
                }
604

605
                $simplified_summary_grade_failed = ( $simplified_summary_grade > 9 ) ? true : false;
×
606
                $simplified_summary_prompt       = get_option( 'edac_simplified_summary_prompt' );
×
607

608
                $html .= '<ul class="edac-readability-list">';
×
609

610
                $html .= '<li class="edac-readability-list-item edac-readability-grade-level">
×
611
                <span class="edac-readability-list-item-icon dashicons ' . ( ( $post_grade_failed || 0 === $post_grade ) ? 'dashicons-no-alt' : 'dashicons-saved' ) . '"></span>
×
612
                <p class="edac-readability-list-item-title">Post Reading Grade Level: <strong class="' . ( ( $post_grade_failed || 0 === $post_grade ) ? 'failed-text-color' : 'passed-text-color' ) . '">' . ( ( 0 === $post_grade ) ? 'None' : $post_grade_readability ) . '</strong><br /></p>';
×
613
                if ( $post_grade_failed ) {
×
614
                        $html .= '<p class="edac-readability-list-item-description">Your post has a reading level higher than 9th grade. Web Content Accessibility Guidelines (WCAG) at the AAA level require a simplified summary of your post that is 9th grade or below.</p>';
×
615
                } elseif ( 0 === $post_grade ) {
×
616
                        $html .= '<p class="edac-readability-list-item-description">Your post does not contain enough content to calculate its reading level.</p>';
×
617
                } else {
618
                        $html .= '<p class="edac-readability-list-item-description">A simplified summary is not necessary when content reading level is 9th grade or below. Choose when to prompt for a simplified summary on the settings page.</p>';
×
619
                }
620
                $html .= '</li>';
×
621

622
                if ( $post_grade_failed ) {
×
623

624
                        if ( $simplified_summary && 'none' !== $simplified_summary_prompt ) {
×
625
                                $html .= '<li class="edac-readability-list-item edac-readability-summary-grade-level">
×
626
                                        <span class="edac-readability-list-item-icon dashicons ' . ( ( $simplified_summary_grade_failed ) ? 'dashicons-no-alt' : 'dashicons-saved' ) . '"></span>
×
627
                                        <p class="edac-readability-list-item-title">Simplified Summary Reading Grade Level: <strong class="' . ( ( $simplified_summary_grade_failed ) ? 'failed-text-color' : 'passed-text-color' ) . '">' . edac_ordinal( $simplified_summary_grade ) . '</strong></p>
×
628
                                        <p class="edac-readability-list-item-description">Your simplified summary has a reading level ' . ( ( $simplified_summary_grade_failed ) ? 'higher' : 'lower' ) . ' than 9th grade.</p>
×
629
                                </li>';
×
630
                        }
631

632
                        if ( 'none' === $simplified_summary_prompt ) {
×
633

634
                                $html .=
×
635
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
636
                                        <span class="edac-readability-list-item-icon"><img src="' . plugin_dir_url( __FILE__ ) . 'assets/images/warning icon yellow.png" alt="" width="22"></span>
×
637
                                        <p class="edac-readability-list-item-title">Simplified summary is not being automatically inserted into the content.</p>
638
                                                <p class="edac-readability-list-item-description">Your Prompt for Simplified Summary is set to "never." If you would like the simplified summary to be displayed automatically, you can change this on the <a href="' . get_bloginfo( 'url' ) . '/wp-admin/admin.php?page=accessibility_checker_settings">settings page</a>.</p>
×
639
                                </li>';
×
640

641
                        } elseif ( 'none' !== $simplified_summary_position ) {
×
642

643
                                $html .=
×
644
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
645
                                        <span class="edac-readability-list-item-icon dashicons dashicons-saved"></span>
646
                                        <p class="edac-readability-list-item-title">Simplified summary is being automatically inserted <strong>' . $simplified_summary_position . ' the content</strong>.</p>
×
647
                                                <p class="edac-readability-list-item-description">Set where the Simplified Summary is inserted into the content on the <a href="' . get_bloginfo( 'url' ) . '/wp-admin/admin.php?page=accessibility_checker_settings">settings page</a>.</p>
×
648
                                </li>';
×
649

650
                        } else {
651

652
                                $html .=
×
653
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
654
                                        <span class="edac-readability-list-item-icon"><img src="' . plugin_dir_url( __FILE__ ) . 'assets/images/warning icon yellow.png" alt="" width="22"></span>
×
655
                                        <p class="edac-readability-list-item-title">Simplified summary is not being automatically inserted into the content.</p>
656
                                                <p class="edac-readability-list-item-description">Your Simplified Summary location is set to "manually" which requires a function be added to your page template. If you would like the simplified summary to be displayed automatically, you can change this on the <a href="' . get_bloginfo( 'url' ) . '/wp-admin/admin.php?page=accessibility_checker_settings">settings page</a>.</p>
×
657
                                </li>';
×
658

659
                        }
660
                }
661

662
                $html .= '</ul>';
×
663

664
                if ( ( $post_grade_failed || 'always' === $simplified_summary_prompt ) && ( 'none' !== $simplified_summary_prompt ) ) {
×
665
                        $html .=
×
666
                                '</form>
×
667
                        <form action="/" class="edac-readability-simplified-summary">
668
                                <label for="edac-readability-text">Simplified Summary</label>
669
                                <textarea name="" id="edac-readability-text" cols="30" rows="10">' . $simplified_summary . '</textarea>
×
670
                                <input type="submit" value="Submit">
671
                        </form>';
×
672
                }
673

674
                global $wp_version;
×
675
                $html .= '<span class="dashicons dashicons-info"></span><a href="https://a11ychecker.com/help3265?utm_source=accessibility-checker&utm_medium=software&utm_term=readability&utm_content=content-analysis&utm_campaign=wordpress-general&php_version=' . PHP_VERSION . '&platform=wordpress&platform_version=' . $wp_version . '&software=free&software_version=' . EDAC_VERSION . '&days_active=' . edac_days_active() . '" target="_blank">Learn more about improving readability and simplified summary requirements</a>';
×
676

677
                if ( ! $html ) {
×
678

NEW
679
                        $error = new \WP_Error( '-3', __( 'No readability data to return', 'accessibility-checker' ) );
×
680
                        wp_send_json_error( $error );
×
681

682
                }
683

684
                wp_send_json_success( wp_json_encode( $html ) );
×
685
        }
686

687
        /**
688
         * Insert ignore data into database
689
         *
690
         * @return void
691
         *
692
         *  - '-1' means that nonce could not be varified
693
         *  - '-2' means that there isn't any ignore data to return
694
         */
695
        public function add_ignore() {
696

697
                // nonce security.
698
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
699

NEW
700
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
701
                        wp_send_json_error( $error );
×
702

703
                }
704

705
                global $wpdb;
×
706
                $table_name           = $wpdb->prefix . 'accessibility_checker';
×
707
                $raw_ids              = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitization handled below.
×
708
                $ids                  = array_map(
×
709
                        function ( $value ) {
×
710
                                return (int) $value;
×
711
                        },
×
712
                        $raw_ids
×
713
                ); // Sanitizing array elements to integers.
×
714
                $action               = isset( $_REQUEST['ignore_action'] ) ? sanitize_text_field( $_REQUEST['ignore_action'] ) : '';
×
715
                $type                 = isset( $_REQUEST['ignore_type'] ) ? sanitize_text_field( $_REQUEST['ignore_type'] ) : '';
×
716
                $siteid               = get_current_blog_id();
×
717
                $ignre                = ( 'enable' === $action ) ? 1 : 0;
×
718
                $ignre_user           = ( 'enable' === $action ) ? get_current_user_id() : null;
×
719
                $ignre_user_info      = ( 'enable' === $action ) ? get_userdata( $ignre_user ) : '';
×
720
                $ignre_username       = ( 'enable' === $action ) ? $ignre_user_info->user_login : '';
×
721
                $ignre_date           = ( 'enable' === $action ) ? gmdate( 'Y-m-d H:i:s' ) : null;
×
722
                $ignre_date_formatted = ( 'enable' === $action ) ? gmdate( 'F j, Y g:i a', strtotime( $ignre_date ) ) : '';
×
723
                $ignre_comment        = ( 'enable' === $action && isset( $_REQUEST['comment'] ) ) ? sanitize_textarea_field( $_REQUEST['comment'] ) : null;
×
724
                $ignore_global        = ( 'enable' === $action && isset( $_REQUEST['ignore_global'] ) ) ? sanitize_textarea_field( $_REQUEST['ignore_global'] ) : 0;
×
725

726
                // If largeBatch is set and 'true', we need to perform an update using the 'object'
727
                // instead of IDs. It is a much less efficient query than by IDs - but many IDs run
728
                // into request size limits which caused this to not function at all.
729
                if ( isset( $_REQUEST['largeBatch'] ) && 'true' === $_REQUEST['largeBatch'] ) {
×
730
                        // Get the 'object' from the first id.
731
                        $first_id = $ids[0];
×
732
                        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to get the latest value, not a cached value.
733
                        $object = $wpdb->get_var( $wpdb->prepare( 'SELECT object FROM %i WHERE id = %d', $table_name, $first_id ) );
×
734

735
                        if ( ! $object ) {
×
NEW
736
                                $error = new \WP_Error( '-2', __( 'No ignore data to return', 'accessibility-checker' ) );
×
737
                                wp_send_json_error( $error );
×
738
                        }
739
                        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
740
                        $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_global = %d WHERE siteid = %d and object = %s', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignore_global, $siteid, $object ) );
×
741
                } else {
742
                        // For small batches of IDs, we can just loop through.
743
                        foreach ( $ids as $id ) {
×
744
                                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
745
                                $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_global = %d WHERE siteid = %d and id = %d', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignore_global, $siteid, $id ) );
×
746
                        }
747
                }
748

749
                $data = [
×
750
                        'ids'    => $ids,
×
751
                        'action' => $action,
×
752
                        'type'   => $type,
×
753
                        'user'   => $ignre_username,
×
754
                        'date'   => $ignre_date_formatted,
×
755
                ];
×
756

757
                if ( ! $data ) {
×
758

NEW
759
                        $error = new \WP_Error( '-2', __( 'No ignore data to return', 'accessibility-checker' ) );
×
760
                        wp_send_json_error( $error );
×
761

762
                }
763
                wp_send_json_success( wp_json_encode( $data ) );
×
764
        }
765

766
        /**
767
         * Update simplified summary
768
         *
769
         * @return void
770
         *
771
         *  - '-1' means that nonce could not be varified
772
         *  - '-2' means that the post ID was not specified
773
         *  - '-3' means that the summary was not specified
774
         */
775
        public function simplified_summary() {
776

777
                // nonce security.
778
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
779

NEW
780
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
781
                        wp_send_json_error( $error );
×
782

783
                }
784

785
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
786

NEW
787
                        $error = new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) );
×
788
                        wp_send_json_error( $error );
×
789

790
                }
791

792
                if ( ! isset( $_REQUEST['summary'] ) ) {
×
793

NEW
794
                        $error = new \WP_Error( '-3', __( 'The summary was not set', 'accessibility-checker' ) );
×
795
                        wp_send_json_error( $error );
×
796

797
                }
798

799
                $post_id = (int) $_REQUEST['post_id'];
×
800
                update_post_meta(
×
801
                        $post_id,
×
802
                        '_edac_simplified_summary',
×
803
                        sanitize_text_field( $_REQUEST['summary'] )
×
804
                );
×
805

806
                $edac_simplified_summary = get_post_meta( $post_id, '_edac_simplified_summary', $single = true );
×
807
                $simplified_summary      = $edac_simplified_summary ? $edac_simplified_summary : '';
×
808

809
                wp_send_json_success( wp_json_encode( $simplified_summary ) );
×
810
        }
811

812
        /**
813
         * Handle AJAX request to dismiss Welcome CTA
814
         *
815
         * @return void
816
         */
817
        public function dismiss_welcome_cta() {
818

819
                update_user_meta( get_current_user_id(), 'edac_welcome_cta_dismissed', true );
×
820

821
                wp_send_json( 'success' );
×
822
        }
823

824
        /**
825
         * Handle AJAX request to dismiss dashboard CTA
826
         *
827
         * @return void
828
         */
829
        public function dismiss_dashboard_cta() {
830

831
                update_user_meta( get_current_user_id(), 'edac_dashboard_cta_dismissed', true );
×
832

833
                wp_send_json( 'success' );
×
834
        }
835
}
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

© 2025 Coveralls, Inc