• 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
/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

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

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>
UNCOV
168
                ';
×
169

NEW
170
                $html['content'] .= '<div class="edac-summary-disclaimer" id="edac-summary-disclaimer"><small>' . PHP_EOL;
×
NEW
171
                $html['content'] .= sprintf(
×
NEW
172
                        '* True accessibility requires manual testing in addition to automated scans. %1$sLearn how to manually test for accessibility%2$s.',
×
NEW
173
                        '<a href="' . esc_url(
×
NEW
174
                                edac_generate_link_type(
×
NEW
175
                                        [
×
NEW
176
                                                'utm_campaign' => 'dashboard-widget',
×
NEW
177
                                                'utm_content'  => 'how-to-manually-check',
×
NEW
178
                                        ],
×
NEW
179
                                        'help',
×
NEW
180
                                        [ 'help_id' => 4280 ]
×
NEW
181
                                )
×
NEW
182
                        ) . '">',
×
NEW
183
                        '</a>'
×
NEW
184
                ) . PHP_EOL;
×
NEW
185
                $html['content'] .= '</small></div>' . PHP_EOL;
×
186

UNCOV
187
                if ( ! $html ) {
×
188

189
                        $error = new \WP_Error( '-3', __( 'No summary to return', 'accessibility-checker' ) );
×
190
                        wp_send_json_error( $error );
×
191

192
                }
193

194
                wp_send_json_success( wp_json_encode( $html ) );
×
195
        }
196

197
        /**
198
         * Details Ajax
199
         *
200
         * @return void
201
         *
202
         *  - '-1' means that nonce could not be varified
203
         *  - '-2' means that the post ID was not specified
204
         *  - '-3' means that the table name is not valid
205
         *  - '-4' means that there isn't any details to return
206
         */
207
        public function details() {
208

209
                // nonce security.
210
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
211

212
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
213
                        wp_send_json_error( $error );
×
214

215
                }
216

217
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
218

219
                        $error = new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) );
×
220
                        wp_send_json_error( $error );
×
221

222
                }
223

224
                $html = '';
×
225
                global $wpdb;
×
226
                $table_name = edac_get_valid_table_name( $wpdb->prefix . 'accessibility_checker' );
×
227
                $postid     = (int) $_REQUEST['post_id'];
×
228
                $siteid     = get_current_blog_id();
×
229

230
                // Send error if table name is not valid.
231
                if ( ! $table_name ) {
×
232

233
                        $error = new \WP_Error( '-3', __( 'Invalid table name', 'accessibility-checker' ) );
×
234
                        wp_send_json_error( $error );
×
235

236
                }
237

238
                $rules = edac_register_rules();
×
239
                if ( $rules ) {
×
240

241
                        // if ANWW is active remove link_blank for details meta box.
242
                        if ( defined( 'ANWW_VERSION' ) ) {
×
243
                                $rules = edac_remove_element_with_value( $rules, 'slug', 'link_blank' );
×
244
                        }
245

246
                        // separate rule types.
247
                        $passed_rules  = [];
×
248
                        $error_rules   = edac_remove_element_with_value( $rules, 'rule_type', 'warning' );
×
249
                        $warning_rules = edac_remove_element_with_value( $rules, 'rule_type', 'error' );
×
250

251
                        // add count, unset passed error rules and add passed rules to array.
252
                        if ( $error_rules ) {
×
253
                                foreach ( $error_rules as $key => $error_rule ) {
×
254
                                        // 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.
255
                                        $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 ) );
×
256
                                        if ( $count ) {
×
257
                                                $error_rules[ $key ]['count'] = $count;
×
258
                                        } else {
259
                                                $error_rule['count'] = 0;
×
260
                                                $passed_rules[]      = $error_rule;
×
261
                                                unset( $error_rules[ $key ] );
×
262
                                        }
263
                                }
264
                        }
265

266
                        // add count, unset passed warning rules and add passed rules to array.
267
                        if ( $warning_rules ) {
×
268
                                foreach ( $warning_rules as $key => $error_rule ) {
×
269
                                        // 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.
270
                                        $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 ) );
×
271
                                        if ( $count ) {
×
272
                                                $warning_rules[ $key ]['count'] = $count;
×
273
                                        } else {
274
                                                $error_rule['count'] = 0;
×
275
                                                $passed_rules[]      = $error_rule;
×
276
                                                unset( $warning_rules[ $key ] );
×
277
                                        }
278
                                }
279
                        }
280
                }
281

282
                // sort error rules by count.
283
                usort(
×
284
                        $error_rules,
×
285
                        function ( $a, $b ) {
×
286

287
                                return strcmp( $b['count'], $a['count'] );
×
288
                        }
×
289
                );
×
290

291
                // sort warning rules by count.
292
                usort(
×
293
                        $warning_rules,
×
294
                        function ( $a, $b ) {
×
295

296
                                return strcmp( $b['count'], $a['count'] );
×
297
                        }
×
298
                );
×
299

300
                // sort passed rules array by title.
301
                usort(
×
302
                        $passed_rules,
×
303
                        function ( $a, $b ) {
×
304

305
                                return strcmp( $b['title'], $a['title'] );
×
306
                        }
×
307
                );
×
308

309
                // merge rule arrays together.
310
                $rules = array_merge( $error_rules, $warning_rules, $passed_rules );
×
311

312
                if ( $rules ) {
×
313
                        /**
314
                         * Filters if a user can ignore issues.
315
                         *
316
                         * @since 1.4.0
317
                         *
318
                         * @allowed bool True if allowed, false if not
319
                         */
320
                        $ignore_permission = apply_filters( 'edac_ignore_permission', true );
×
321

322
                        foreach ( $rules as $rule ) {
×
323
                                // 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.
324
                                $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 );
×
325
                                $count_classes  = ( 'error' === $rule['rule_type'] ) ? ' edac-details-rule-count-error' : ' edac-details-rule-count-warning';
×
326
                                $count_classes .= ( 0 !== $rule['count'] ) ? ' active' : '';
×
327

328
                                $count_ignored = 0;
×
329
                                $ignores       = array_column( $results, 'ignre' );
×
330
                                if ( $ignores ) {
×
331
                                        foreach ( $ignores as $ignore ) {
×
332
                                                if ( true === (bool) $ignore ) {
×
333
                                                        ++$count_ignored;
×
334
                                                }
335
                                        }
336
                                }
337

338
                                // 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.
339
                                $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 ) );
×
340

NEW
341
                                $tool_tip_link = edac_link_wrapper( $rule['info_url'], 'frontend-highlighter', $rule['slug'], false );
×
342

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

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

347
                                $html .= '<h3>';
×
348
                                $html .= '<span class="edac-details-rule-count' . $count_classes . '">' . $rule['count'] . '</span> ';
×
349
                                $html .= esc_html( $rule['title'] );
×
350
                                if ( $count_ignored > 0 ) {
×
351
                                        $html .= '<span class="edac-details-rule-count-ignore">' . $count_ignored . ' Ignored Items</span>';
×
352
                                }
353
                                $html .= '</h3>';
×
354
                                $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>';
×
355
                                $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>' : '';
×
356

357
                                $html .= '</div>';
×
358

359
                                if ( $results ) {
×
360

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

363
                                        $fixes_for_item = [];
×
364
                                        if ( isset( $rule['fixes'] ) && current_user_can( apply_filters( 'edac_filter_settings_capability', 'manage_options' ) ) ) {
×
365
                                                foreach ( $rule['fixes'] as $fix_slug ) {
×
366
                                                        $fixes_for_item[] = FixesManager::get_instance()->get_fix( $fix_slug );
×
367
                                                }
368

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

425
                                        $html .=
×
426
                                                '<div class="edac-details-rule-records-labels">
×
427
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
428
                                                                ' . esc_html__( 'Affected Code', 'accessibility-checker' ) . '
×
429
                                                        </div>
430
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
431
                                                                Image
432
                                                        </div>
433
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
434
                                                                Actions
435
                                                        </div>
436
                                                </div>';
×
437

438
                                        foreach ( $results as $row ) {
×
439

440
                                                $id                      = (int) $row['id'];
×
441
                                                $ignore                  = (int) $row['ignre'];
×
442
                                                $ignore_class            = $ignore ? ' active' : '';
×
443
                                                $ignore_label            = $ignore ? 'Ignored' : 'Ignore';
×
444
                                                $ignore_user             = (int) $row['ignre_user'];
×
445
                                                $ignore_user_info        = get_userdata( $ignore_user );
×
446
                                                $ignore_username         = is_object( $ignore_user_info ) ? '<strong>Username:</strong> ' . $ignore_user_info->user_login : '';
×
447
                                                $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'] ) ) ) : '';
×
448
                                                $ignore_comment          = esc_html( $row['ignre_comment'] );
×
449
                                                $ignore_action           = $ignore ? 'disable' : 'enable';
×
450
                                                $ignore_type             = $rule['rule_type'];
×
451
                                                $ignore_submit_label     = $ignore ? 'Stop Ignoring' : 'Ignore This ' . $ignore_type;
×
452
                                                $ignore_comment_disabled = $ignore ? 'disabled' : '';
×
453
                                                $ignore_global           = (int) $row['ignre_global'];
×
454

455
                                                // check for images and svgs in object code.
456
                                                $media      = edac_parse_html_for_media( $row['object'] );
×
457
                                                $object_img = $media['img'];
×
458
                                                $object_svg = $media['svg'];
×
459

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

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

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

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

468
                                                $html .= '</div>';
×
469

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

472
                                                if ( $object_img ) {
×
473
                                                        $html .= '<img src="' . $object_img . '" alt="image for issue ' . $id . '" />';
×
474
                                                } elseif ( $object_svg ) {
×
475
                                                        $html .= $object_svg;
×
476
                                                }
477

478
                                                $html .= '</div>';
×
479

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

482
                                                if ( ! isset( $rule['viewable'] ) || $rule['viewable'] ) {
×
483

484
                                                        $url = add_query_arg(
×
485
                                                                [
×
486
                                                                        'edac'       => $id,
×
487
                                                                        'edac_nonce' => wp_create_nonce( 'edac_highlight' ),
×
488
                                                                ],
×
489
                                                                get_the_permalink( $postid )
×
490
                                                        );
×
491

492
                                                        // Translators: %d is the issue ID.
493
                                                        $aria_label = sprintf( __( 'View Issue ID %d on website, opens a new window', 'accessibility-checker' ), $id );
×
494
                                                        $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>';
×
495
                                                }
496

497
                                                if ( true === $ignore_permission ) {
×
498
                                                        $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>';
×
499
                                                }
500

501
                                                if ( ! empty( $fixes_for_item ) ) {
×
502
                                                        $html .= sprintf(
×
503
                                                                '<button class="edac-details-rule-records-record-actions-fix"
×
504
                                                                        aria-haspopup="true"
505
                                                                        aria-controls="%1$s"
506
                                                                        aria-label="%2$s"
507
                                                                        type="button"
508
                                                                >
509
                                                                        <span class="dashicons dashicons-admin-tools"></span>
510
                                                                        %3$s
511
                                                                </button>',
×
512
                                                                esc_attr( $controls_id ),
×
513
                                                                esc_attr( __( 'Fix: ', 'accessibility-checker' ) . $fixes_for_item[0]->get_nicename() ),
×
514
                                                                esc_html__( 'Fix', 'accessibility-checker' )
×
515
                                                        );
×
516
                                                }
517

518
                                                $html .= '</div>';
×
519

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

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

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

528
                                                $html .= ( true === $ignore_permission || ! empty( $ignore_comment ) ) ? '<label for="edac-details-rule-records-record-ignore-comment-' . $id . '">Comment</label><br>' : '';
×
529
                                                $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>' : '';
×
530

531
                                                if ( $ignore_global ) {
×
532
                                                        $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>' : '';
×
533
                                                } else {
534
                                                        $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>' : '';
×
535
                                                }
536

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

539
                                                $html .= '</div>';
×
540

541
                                                $html .= '</div>';
×
542

543
                                        }
544

545
                                        $html .= '</div>';
×
546

547
                                }
548

549
                                $html .= '</div>';
×
550
                        }
551
                }
552

553
                if ( ! $html ) {
×
554

555
                        $error = new \WP_Error( '-4', __( 'No details to return', 'accessibility-checker' ) );
×
556
                        wp_send_json_error( $error );
×
557

558
                }
559

560
                wp_send_json_success( wp_json_encode( $html ) );
×
561
        }
562

563
        /**
564
         * Readability Ajax
565
         *
566
         * @return void
567
         *
568
         *  - '-1' means that nonce could not be varified
569
         *  - '-2' means that the post ID was not specified
570
         *  - '-3' means that there isn't any readability data to return
571
         */
572
        public function readability() {
573

574
                // nonce security.
575
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
576

577
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
578
                        wp_send_json_error( $error );
×
579

580
                }
581

582
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
583

584
                        $error = new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) );
×
585
                        wp_send_json_error( $error );
×
586

587
                }
588

589
                $post_id                     = (int) $_REQUEST['post_id'];
×
590
                $html                        = '';
×
591
                $simplified_summary          = get_post_meta( $post_id, '_edac_simplified_summary', true ) ? get_post_meta( $post_id, '_edac_simplified_summary', true ) : '';
×
592
                $simplified_summary_position = get_option( 'edac_simplified_summary_position', $default = false );
×
593
                $content_post                = get_post( $post_id );
×
594
                $content                     = $content_post->post_content;
×
595
                $content                     = apply_filters( 'the_content', $content );
×
596

597
                /**
598
                 * Filter the content used for reading grade readability analysis.
599
                 *
600
                 * @since 1.4.0
601
                 *
602
                 * @param string $content The content to be filtered.
603
                 * @param int    $post_id The post ID.
604
                 */
605
                $content = apply_filters( 'edac_filter_readability_content', $content, $post_id );
×
606
                $content = wp_filter_nohtml_kses( $content );
×
607
                $content = str_replace( ']]>', ']]&gt;', $content );
×
608

609
                // get readability metadata and determine if a simplified summary is required.
610
                $edac_summary           = get_post_meta( $post_id, '_edac_summary', true );
×
611
                $post_grade_readability = ( isset( $edac_summary['readability'] ) ) ? $edac_summary['readability'] : 0;
×
612
                $post_grade             = (int) filter_var( $post_grade_readability, FILTER_SANITIZE_NUMBER_INT );
×
613
                $post_grade_failed      = ( $post_grade < 9 ) ? false : true;
×
614

615
                $simplified_summary_grade = 0;
×
616
                if ( class_exists( 'DaveChild\TextStatistics\TextStatistics' ) ) {
×
617
                        $text_statistics          = new \DaveChild\TextStatistics\TextStatistics();
×
618
                        $simplified_summary_grade = (int) floor( $text_statistics->fleschKincaidGradeLevel( $simplified_summary ) );
×
619
                }
620

621
                $simplified_summary_grade_failed = ( $simplified_summary_grade > 9 ) ? true : false;
×
622
                $simplified_summary_prompt       = get_option( 'edac_simplified_summary_prompt' );
×
623

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

626
                $html .= '<li class="edac-readability-list-item edac-readability-grade-level">
×
627
                <span class="edac-readability-list-item-icon dashicons ' . ( ( $post_grade_failed || 0 === $post_grade ) ? 'dashicons-no-alt' : 'dashicons-saved' ) . '"></span>
×
628
                <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>';
×
629
                if ( $post_grade_failed ) {
×
630
                        $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>';
×
631
                } elseif ( 0 === $post_grade ) {
×
632
                        $html .= '<p class="edac-readability-list-item-description">Your post does not contain enough content to calculate its reading level.</p>';
×
633
                } else {
634
                        $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>';
×
635
                }
636
                $html .= '</li>';
×
637

638
                if ( $post_grade_failed ) {
×
639

640
                        if ( $simplified_summary && 'none' !== $simplified_summary_prompt ) {
×
641
                                $html .= '<li class="edac-readability-list-item edac-readability-summary-grade-level">
×
642
                                        <span class="edac-readability-list-item-icon dashicons ' . ( ( $simplified_summary_grade_failed ) ? 'dashicons-no-alt' : 'dashicons-saved' ) . '"></span>
×
643
                                        <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>
×
644
                                        <p class="edac-readability-list-item-description">Your simplified summary has a reading level ' . ( ( $simplified_summary_grade_failed ) ? 'higher' : 'lower' ) . ' than 9th grade.</p>
×
645
                                </li>';
×
646
                        }
647

648
                        if ( 'none' === $simplified_summary_prompt ) {
×
649

650
                                $html .=
×
651
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
652
                                        <span class="edac-readability-list-item-icon"><img src="' . plugin_dir_url( __FILE__ ) . 'assets/images/warning-icon-yellow.png" alt="" width="22"></span>
×
653
                                        <p class="edac-readability-list-item-title">Simplified summary is not being automatically inserted into the content.</p>
654
                                                <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>
×
655
                                </li>';
×
656

657
                        } elseif ( 'none' !== $simplified_summary_position ) {
×
658

659
                                $html .=
×
660
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
661
                                        <span class="edac-readability-list-item-icon dashicons dashicons-saved"></span>
662
                                        <p class="edac-readability-list-item-title">Simplified summary is being automatically inserted <strong>' . $simplified_summary_position . ' the content</strong>.</p>
×
663
                                                <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>
×
664
                                </li>';
×
665

666
                        } else {
667

668
                                $html .=
×
669
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
670
                                        <span class="edac-readability-list-item-icon"><img src="' . plugin_dir_url( __FILE__ ) . 'assets/images/warning-icon-yellow.png" alt="" width="22"></span>
×
671
                                        <p class="edac-readability-list-item-title">Simplified summary is not being automatically inserted into the content.</p>
672
                                                <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>
×
673
                                </li>';
×
674

675
                        }
676
                }
677

678
                $html .= '</ul>';
×
679

680
                if ( ( $post_grade_failed || 'always' === $simplified_summary_prompt ) && ( 'none' !== $simplified_summary_prompt ) ) {
×
681
                        $html .=
×
682
                                '</form>
×
683
                        <form action="/" class="edac-readability-simplified-summary">
684
                                <label for="edac-readability-text">Simplified Summary</label>
685
                                <textarea name="" id="edac-readability-text" cols="30" rows="10">' . $simplified_summary . '</textarea>
×
686
                                <input type="submit" value="Submit">
687
                        </form>';
×
688
                }
689

NEW
690
                $html .= '<span class="dashicons dashicons-info"></span><a href="' . esc_url( edac_link_wrapper( 'https://a11ychecker.com/help3265', 'wordpress-general', 'content-analysis', false ) ) . '" target="_blank">Learn more about improving readability and simplified summary requirements</a>';
×
691

692
                if ( ! $html ) {
×
693

694
                        $error = new \WP_Error( '-3', __( 'No readability data to return', 'accessibility-checker' ) );
×
695
                        wp_send_json_error( $error );
×
696

697
                }
698

699
                wp_send_json_success( wp_json_encode( $html ) );
×
700
        }
701

702
        /**
703
         * Insert ignore data into database
704
         *
705
         * @return void
706
         *
707
         *  - '-1' means that nonce could not be varified
708
         *  - '-2' means that there isn't any ignore data to return
709
         */
710
        public function add_ignore() {
711

712
                // nonce security.
713
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
714

715
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
716
                        wp_send_json_error( $error );
×
717

718
                }
719

720
                global $wpdb;
×
721
                $table_name           = $wpdb->prefix . 'accessibility_checker';
×
722
                $raw_ids              = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitization handled below.
×
723
                $ids                  = array_map(
×
724
                        function ( $value ) {
×
725
                                return (int) $value;
×
726
                        },
×
727
                        $raw_ids
×
728
                ); // Sanitizing array elements to integers.
×
729
                $action               = isset( $_REQUEST['ignore_action'] ) ? sanitize_text_field( $_REQUEST['ignore_action'] ) : '';
×
730
                $type                 = isset( $_REQUEST['ignore_type'] ) ? sanitize_text_field( $_REQUEST['ignore_type'] ) : '';
×
731
                $siteid               = get_current_blog_id();
×
732
                $ignre                = ( 'enable' === $action ) ? 1 : 0;
×
733
                $ignre_user           = ( 'enable' === $action ) ? get_current_user_id() : null;
×
734
                $ignre_user_info      = ( 'enable' === $action ) ? get_userdata( $ignre_user ) : '';
×
735
                $ignre_username       = ( 'enable' === $action ) ? $ignre_user_info->user_login : '';
×
736
                $ignre_date           = ( 'enable' === $action ) ? gmdate( 'Y-m-d H:i:s' ) : null;
×
737
                $ignre_date_formatted = ( 'enable' === $action ) ? gmdate( 'F j, Y g:i a', strtotime( $ignre_date ) ) : '';
×
738
                $ignre_comment        = ( 'enable' === $action && isset( $_REQUEST['comment'] ) ) ? sanitize_textarea_field( $_REQUEST['comment'] ) : null;
×
739
                $ignore_global        = ( 'enable' === $action && isset( $_REQUEST['ignore_global'] ) ) ? sanitize_textarea_field( $_REQUEST['ignore_global'] ) : 0;
×
740

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

750
                        if ( ! $object ) {
×
751
                                $error = new \WP_Error( '-2', __( 'No ignore data to return', 'accessibility-checker' ) );
×
752
                                wp_send_json_error( $error );
×
753
                        }
754
                        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
755
                        $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 ) );
×
756
                } else {
757
                        // For small batches of IDs, we can just loop through.
758
                        foreach ( $ids as $id ) {
×
759
                                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
760
                                $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 ) );
×
761
                        }
762
                }
763

764
                $data = [
×
765
                        'ids'    => $ids,
×
766
                        'action' => $action,
×
767
                        'type'   => $type,
×
768
                        'user'   => $ignre_username,
×
769
                        'date'   => $ignre_date_formatted,
×
770
                ];
×
771

772
                if ( ! $data ) {
×
773

774
                        $error = new \WP_Error( '-2', __( 'No ignore data to return', 'accessibility-checker' ) );
×
775
                        wp_send_json_error( $error );
×
776

777
                }
778
                wp_send_json_success( wp_json_encode( $data ) );
×
779
        }
780

781
        /**
782
         * Update simplified summary
783
         *
784
         * @return void
785
         *
786
         *  - '-1' means that nonce could not be varified
787
         *  - '-2' means that the post ID was not specified
788
         *  - '-3' means that the summary was not specified
789
         */
790
        public function simplified_summary() {
791

792
                // nonce security.
793
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
794

795
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
796
                        wp_send_json_error( $error );
×
797

798
                }
799

800
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
801

802
                        $error = new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) );
×
803
                        wp_send_json_error( $error );
×
804

805
                }
806

807
                if ( ! isset( $_REQUEST['summary'] ) ) {
×
808

809
                        $error = new \WP_Error( '-3', __( 'The summary was not set', 'accessibility-checker' ) );
×
810
                        wp_send_json_error( $error );
×
811

812
                }
813

814
                $post_id = (int) $_REQUEST['post_id'];
×
815
                update_post_meta(
×
816
                        $post_id,
×
817
                        '_edac_simplified_summary',
×
818
                        sanitize_text_field( $_REQUEST['summary'] )
×
819
                );
×
820

821
                $edac_simplified_summary = get_post_meta( $post_id, '_edac_simplified_summary', $single = true );
×
822
                $simplified_summary      = $edac_simplified_summary ? $edac_simplified_summary : '';
×
823

824
                wp_send_json_success( wp_json_encode( $simplified_summary ) );
×
825
        }
826

827
        /**
828
         * Handle AJAX request to dismiss Welcome CTA
829
         *
830
         * @return void
831
         */
832
        public function dismiss_welcome_cta() {
833

834
                update_user_meta( get_current_user_id(), 'edac_welcome_cta_dismissed', true );
×
835

836
                wp_send_json( 'success' );
×
837
        }
838

839
        /**
840
         * Handle AJAX request to dismiss dashboard CTA
841
         *
842
         * @return void
843
         */
844
        public function dismiss_dashboard_cta() {
845

846
                update_user_meta( get_current_user_id(), 'edac_dashboard_cta_dismissed', true );
×
847

848
                wp_send_json( 'success' );
×
849
        }
850
}
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