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

equalizedigital / accessibility-checker / 23157253887

16 Mar 2026 05:31PM UTC coverage: 60.027% (-0.4%) from 60.388%
23157253887

push

github

web-flow
Merge pull request #1522 from equalizedigital/copilot/translate-strings-ajax-class

Translate all strings in the ajax class

0 of 64 new or added lines in 1 file covered. (0.0%)

4 existing lines in 1 file now uncovered.

4825 of 8038 relevant lines covered (60.03%)

4.7 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\Admin\IgnoreUI;
14
use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager;
15

16
if ( ! defined( 'ABSPATH' ) ) {
×
17
        exit;
×
18
}
19

20
/**
21
 * Class that handles ajax requests.
22
 */
23
class Ajax {
24

25
        /**
26
         * Constructor function for the class.
27
         */
28
        public function __construct() {
29
        }
×
30

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

46
        /**
47
         * Summary Ajax
48
         *
49
         * @return void
50
         *
51
         *  - '-1' means that nonce could not be varified
52
         *  - '-2' means that the post ID was not specified
53
         *  - '-3' means that there isn't any summary data to return
54
         *  - '-5' means that the user does not have permission to view this information for this post
55
         */
56
        public function summary() {
57

58
                // nonce security.
59
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['nonce'] ) ), 'ajax-nonce' ) ) {
×
60
                        wp_send_json_error( new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) ) );
×
61
                }
62

63
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
64
                        wp_send_json_error( new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) ) );
×
65
                }
66

67
                if ( ! current_user_can( 'edit_post', (int) $_REQUEST['post_id'] ) ) {
×
68
                        wp_send_json_error( new \WP_Error( '-5', __( 'You do not have permission to view this information for this post.', 'accessibility-checker' ) ) );
×
69
                }
70

71
                $html            = [];
×
72
                $html['content'] = '';
×
73

74
                $post_id                   = (int) $_REQUEST['post_id'];
×
75
                $summary                   = ( new Summary_Generator( $post_id ) )->generate_summary();
×
76
                $simplified_summary_text   = '';
×
77
                $simplified_summary_prompt = get_option( 'edac_simplified_summary_prompt' );
×
78
                $simplified_summary        = get_post_meta( $post_id, '_edac_simplified_summary', true ) ? get_post_meta( $post_id, '_edac_simplified_summary', true ) : '';
×
79

80
                $simplified_summary_grade = 0;
×
81
                if ( class_exists( 'DaveChild\TextStatistics\TextStatistics' ) ) {
×
82
                        $text_statistics          = new \DaveChild\TextStatistics\TextStatistics();
×
83
                        $simplified_summary_grade = (int) floor( $text_statistics->fleschKincaidGradeLevel( $simplified_summary ) );
×
84
                }
85
                $simplified_summary_grade_failed = ( $simplified_summary_grade > 9 ) ? true : false;
×
86

87
                $simplified_summary_text = esc_html__( 'A Simplified summary has not been included for this content.', 'accessibility-checker' );
×
88
                if ( 'none' !== $simplified_summary_prompt ) {
×
89
                        if ( $summary['content_grade'] <= 9 ) {
×
90
                                $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' );
×
91
                        } elseif ( $summary['simplified_summary'] ) {
×
92
                                if ( $simplified_summary_grade_failed ) {
×
93
                                        $simplified_summary_text = esc_html__( 'The reading level of the simplified summary is too high.', 'accessibility-checker' );
×
94
                                } else {
95
                                        $simplified_summary_text = esc_html__( 'A simplified summary has been included for this content.', 'accessibility-checker' );
×
96
                                }
97
                        }
98
                }
99

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

102
                        $html['content'] .= '<li class="edac-summary-total">';
×
103

NEW
104
                                $html['content'] .= '<span class="screen-reader-text">' . sprintf(
×
105
                                /* translators: %d: percentage of passed checks */
NEW
106
                                        esc_html__( '%d%% Passed Checks', 'accessibility-checker' ),
×
NEW
107
                                        $summary['passed_tests']
×
NEW
108
                                ) . '</span>';
×
109

110
                                $html['content'] .= edac_icon( 'info', '', true );
×
111

112
                                $html['content'] .= '<div aria-hidden="true" class="edac-summary-total-progress-circle ' . ( ( $summary['passed_tests'] > 50 ) ? ' over50' : '' ) . '">
×
113
                                        <div class="edac-summary-total-progress-circle-label">
114
                                                <div class="edac-panel-number">' . $summary['passed_tests'] . '%</div>
×
NEW
115
                                                <div class="edac-panel-number-label">' . esc_html__( 'Passed Checks', 'accessibility-checker' ) . '<sup>*</sup></div>
×
116
                                        </div>
117
                                        <div class="left-half-clipper">
118
                                                <div class="first50-bar"></div>
119
                                                <div class="value-bar" style="transform: rotate(' . $summary['passed_tests'] * 3.6 . 'deg);"></div>
×
120
                                        </div>
121
                                </div>';
×
122

123
                                $html['content'] .= '<div aria-hidden="true" class="edac-summary-total-mobile">
×
124
                                        <div class="edac-panel-number">' . $summary['passed_tests'] . '%</div>
×
NEW
125
                                        <div class="edac-panel-number-label">' . esc_html__( 'Passed Tests', 'accessibility-checker' ) . '<sup>*</sup></div>
×
126
                                        <div class="edac-summary-total-mobile-bar"><span style="width:' . ( $summary['passed_tests'] ) . '%;"></span></div>
×
127
                                </div>';
×
128

129
                        $html['content'] .= '</li>';
×
130

131
                        // if this is a virtual page, we don't show the readability section.
132
                        $is_virtual_page = edac_is_virtual_page( $post_id );
×
133

134
                        $html['content'] .= '
×
135
                                ' . edac_generate_summary_stat(
×
136
                                'edac-summary-errors',
×
137
                                $summary['errors'],
×
138
                                _n( 'Problem', 'Problems', $summary['errors'], 'accessibility-checker' ),
×
139
                                $summary['errors'] > 0 ? 'error' : 'check'
×
140
                        ) . '
×
141
                                ' . edac_generate_summary_stat(
×
142
                                'edac-summary-contrast',
×
143
                                $summary['contrast_errors'],
×
144
                                _n( 'Contrast Problem', 'Contrast Problems', $summary['contrast_errors'], 'accessibility-checker' ),
×
145
                                $summary['contrast_errors'] > 0 ? 'error' : 'check'
×
146
                        ) . '
×
147
                                ' . edac_generate_summary_stat(
×
148
                                'edac-summary-warnings',
×
149
                                $summary['warnings'],
×
150
                                _n( 'Needs Review', 'Needs Review', $summary['warnings'], 'accessibility-checker' ),
×
151
                                $summary['warnings'] > 0 ? 'warning' : 'check'
×
152
                        ) . '
×
153
                                ' . edac_generate_summary_stat(
×
154
                                'edac-summary-ignored',
×
155
                                $summary['ignored'],
×
156
                                _n( 'Dismissed Issue', 'Dismissed Issues', $summary['ignored'], 'accessibility-checker' ),
×
157
                                'dismissed'
×
158
                        ) . '
×
159

160
                </ul>
161
                <div class="edac-summary-readability" ' . ( $is_virtual_page ? 'style="display: none;"' : '' ) . '>
×
162
                        <div class="edac-summary-readability-level">
163
                                <div>' . edac_icon(
×
164
                        edac_get_readability_panel_icon(
×
165
                                (int) $summary['content_grade'] > 0,
×
166
                                (int) $summary['content_grade'],
×
167
                                (int) $summary['content_grade'] > 9,
×
168
                                $simplified_summary,
×
169
                                $simplified_summary_grade,
×
170
                                $simplified_summary_grade_failed
×
171
                        )
×
172
                ) . '</div>
×
173
                                <div class="edac-panel-number">
174
                                        ' . $summary['readability'] . '
×
175
                                </div>
NEW
176
                                <div class="edac-panel-number-label">' . esc_html__( 'Reading Level', 'accessibility-checker' ) . '</div>
×
177
                        </div>
178
                        <div class="edac-summary-readability-summary">
179
                                <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>
×
180
                        </div>
181
                </div>
182
                ';
×
183

184
                $html['content'] .= '<div class="edac-summary-disclaimer" id="edac-summary-disclaimer"><small>' . PHP_EOL;
×
185
                $html['content'] .= sprintf(
×
186
                        /* translators: 1: opening anchor tag, 2: closing anchor tag with arrow icon and screen reader text */
NEW
187
                        __( '* True accessibility requires manual testing in addition to automated scans. %1$sLearn how to manually test for accessibility%2$s', 'accessibility-checker' ),
×
188
                        '<a target="_blank" href="' . esc_url(
×
189
                                edac_generate_link_type(
×
190
                                        [
×
191
                                                'utm_campaign' => 'dashboard-widget',
×
192
                                                'utm_content'  => 'how-to-manually-check',
×
193
                                        ],
×
194
                                        'help',
×
195
                                        [ 'help_id' => 4280 ]
×
196
                                )
×
197
                        ) . '">',
×
198
                        '<span aria-hidden="true"> ↗</span><span class="screen-reader-text">' . __( ', opens a new window', 'accessibility-checker' ) . '</span></a>'
×
199
                ) . PHP_EOL;
×
200
                $html['content'] .= '</small></div>' . PHP_EOL;
×
201

202
                if ( ! $html ) {
×
203
                        wp_send_json_error( new \WP_Error( '-3', __( 'No summary to return', 'accessibility-checker' ) ) );
×
204
                }
205

206
                wp_send_json_success( wp_json_encode( $html ) );
×
207
        }
208

209
        /**
210
         * Details Ajax
211
         *
212
         * @return void
213
         *
214
         *  - '-1' means that nonce could not be varified
215
         *  - '-2' means that the post ID was not specified
216
         *  - '-3' means that the table name is not valid
217
         *  - '-4' means that there isn't any details to return
218
         *  - '-5' means that the user does not have permission to view this information for this post
219
         */
220
        public function details() {
221

222
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['nonce'] ) ), 'ajax-nonce' ) ) {
×
223
                        wp_send_json_error( new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) ) );
×
224
                }
225

226
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
227
                        wp_send_json_error( new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) ) );
×
228
                }
229

230
                if ( ! current_user_can( 'edit_post', (int) $_REQUEST['post_id'] ) ) {
×
231
                        wp_send_json_error( new \WP_Error( '-5', __( 'You do not have permission to view this information for this post.', 'accessibility-checker' ) ) );
×
232
                }
233

234
                $html = '';
×
235
                global $wpdb;
×
236
                $table_name = edac_get_valid_table_name( $wpdb->prefix . 'accessibility_checker' );
×
237
                $postid     = (int) $_REQUEST['post_id'];
×
238
                $siteid     = get_current_blog_id();
×
239

240
                // Send error if table name is not valid.
241
                if ( ! $table_name ) {
×
242
                        wp_send_json_error( new \WP_Error( '-3', __( 'Invalid table name', 'accessibility-checker' ) ) );
×
243
                }
244

245
                $rules = edac_register_rules();
×
246
                if ( $rules ) {
×
247

248
                        // if ANWW is active remove link_blank for details meta box.
249
                        if ( defined( 'ANWW_VERSION' ) ) {
×
250
                                $rules = edac_remove_element_with_value( $rules, 'slug', 'link_blank' );
×
251
                        }
252

253
                        // separate rule types.
254
                        $passed_rules  = [];
×
255
                        $error_rules   = edac_remove_element_with_value( $rules, 'rule_type', 'warning' );
×
256
                        $warning_rules = edac_remove_element_with_value( $rules, 'rule_type', 'error' );
×
257

258
                        // add count, unset passed error rules and add passed rules to array.
259
                        if ( $error_rules ) {
×
260
                                foreach ( $error_rules as $key => $error_rule ) {
×
261
                                        // 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.
262
                                        $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 ) );
×
263
                                        if ( $count ) {
×
264
                                                $error_rules[ $key ]['count'] = $count;
×
265
                                        } else {
266
                                                $error_rule['count'] = 0;
×
267
                                                $passed_rules[]      = $error_rule;
×
268
                                                unset( $error_rules[ $key ] );
×
269
                                        }
270
                                }
271
                        }
272

273
                        // add count, unset passed warning rules and add passed rules to array.
274
                        if ( $warning_rules ) {
×
275
                                foreach ( $warning_rules as $key => $error_rule ) {
×
276
                                        // 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.
277
                                        $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 ) );
×
278
                                        if ( $count ) {
×
279
                                                $warning_rules[ $key ]['count'] = $count;
×
280
                                        } else {
281
                                                $error_rule['count'] = 0;
×
282
                                                $passed_rules[]      = $error_rule;
×
283
                                                unset( $warning_rules[ $key ] );
×
284
                                        }
285
                                }
286
                        }
287
                }
288

289
                // shared comparator: sort by severity (ascending, 1=critical first), then count (descending).
290
                $sort_by_severity_then_count = function ( $a, $b ) {
×
291
                        $severity_a = isset( $a['severity'] ) ? (int) $a['severity'] : PHP_INT_MAX;
×
292
                        $severity_b = isset( $b['severity'] ) ? (int) $b['severity'] : PHP_INT_MAX;
×
293
                        if ( $severity_a !== $severity_b ) {
×
294
                                return $severity_a - $severity_b;
×
295
                        }
296
                        return (int) $b['count'] - (int) $a['count'];
×
297
                };
×
298

299
                usort( $error_rules, $sort_by_severity_then_count );
×
300
                usort( $warning_rules, $sort_by_severity_then_count );
×
301

302
                // sort passed rules array by severity (ascending, 1=critical first), then title.
303
                usort(
×
304
                        $passed_rules,
×
305
                        function ( $a, $b ) {
×
306
                                $severity_a = isset( $a['severity'] ) ? (int) $a['severity'] : PHP_INT_MAX;
×
307
                                $severity_b = isset( $b['severity'] ) ? (int) $b['severity'] : PHP_INT_MAX;
×
308
                                if ( $severity_a !== $severity_b ) {
×
309
                                        return $severity_a - $severity_b;
×
310
                                }
311
                                return strcmp( $b['title'], $a['title'] );
×
312
                        }
×
313
                );
×
314

315
                // merge rule arrays together.
316
                $rules = array_merge( $error_rules, $warning_rules, $passed_rules );
×
317

318
                if ( $rules ) {
×
319
                        /**
320
                         * Filters if a user can ignore issues.
321
                         *
322
                         * @since 1.4.0
323
                         *
324
                         * @allowed bool True if allowed, false if not
325
                         */
326
                        $ignore_permission = apply_filters( 'edac_ignore_permission', true );
×
327

328
                        $severity_map = [
×
329
                                1 => [
×
330
                                        'label' => __( 'Critical', 'accessibility-checker' ),
×
331
                                        'class' => 'severity-critical',
×
332
                                ],
×
333
                                2 => [
×
334
                                        'label' => __( 'High', 'accessibility-checker' ),
×
335
                                        'class' => 'severity-high',
×
336
                                ],
×
337
                                3 => [
×
338
                                        'label' => __( 'Medium', 'accessibility-checker' ),
×
339
                                        'class' => 'severity-medium',
×
340
                                ],
×
341
                                4 => [
×
342
                                        'label' => __( 'Low', 'accessibility-checker' ),
×
343
                                        'class' => 'severity-low',
×
344
                                ],
×
345
                        ];
×
346

347
                        foreach ( $rules as $rule ) {
×
348
                                // 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.
349
                                $results        = $wpdb->get_results( $wpdb->prepare( 'SELECT id, postid, object, ruletype, ignre, ignre_user, ignre_date, ignre_comment, ignre_reason, ignre_global, landmark, landmark_selector FROM %i where postid = %d and rule = %s and siteid = %d', $table_name, $postid, $rule['slug'], $siteid ), ARRAY_A );
×
350
                                $count_classes  = ( 'error' === $rule['rule_type'] ) ? ' edac-details-rule-count-error' : ' edac-details-rule-count-warning';
×
351
                                $count_classes .= ( 0 !== $rule['count'] ) ? ' active' : '';
×
352

353
                                $count_ignored = 0;
×
354
                                $ignores       = array_column( $results, 'ignre' );
×
355
                                if ( $ignores ) {
×
356
                                        foreach ( $ignores as $ignore ) {
×
357
                                                if ( true === (bool) $ignore ) {
×
358
                                                        ++$count_ignored;
×
359
                                                }
360
                                        }
361
                                }
362

363
                                // 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.
364
                                $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 ) );
×
365

366
                                $tool_tip_link = edac_link_wrapper( $rule['info_url'], 'frontend-highlighter', $rule['slug'], false );
×
367

368
                                $severity_badge = '';
×
369
                                if ( ! empty( $rule['severity'] ) && isset( $severity_map[ (int) $rule['severity'] ] ) ) {
×
370
                                        $sev            = $severity_map[ (int) $rule['severity'] ];
×
371
                                        $severity_badge = '<span class="edac-badge edac-badge--' . esc_attr( $sev['class'] ) . '"><span class="edac-badge__label">' . esc_html( $sev['label'] ) . '</span></span>';
×
372
                                }
373

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

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

378
                                $icon_name = ( 0 === $rule['count'] ) ? 'check' : ( ( 'error' === $rule['rule_type'] ) ? 'error' : 'warning' );
×
379

380
                                $html .= '<h3>';
×
381
                                $html .= edac_icon( $icon_name );
×
382
                                $html .= ' ' . esc_html( $rule['title'] );
×
383
                                $html .= ' <span class="edac-details-rule-count' . $count_classes . '"><span aria-hidden="true">(</span>' . $rule['count'] . '<span aria-hidden="true">)</span><span class="screen-reader-text">' . esc_html__( ' total', 'accessibility-checker' ) . '</span></span></span>';
×
384
                                if ( $count_ignored > 0 ) {
×
385
                                        $html .= '<span class="edac-details-rule-count-ignore">' . $count_ignored . ' ' . esc_html( _n( 'Dismissed Issue', 'Dismissed Issues', $count_ignored, 'accessibility-checker' ) ) . '</span>';
×
386
                                }
387
                                $html .= $severity_badge;
×
388
                                $html .= '</h3>';
×
NEW
389
                                $html .= '<a href="' . $tool_tip_link . '" class="edac-details-rule-information" target="_blank" aria-label="' . esc_attr(
×
NEW
390
                                        sprintf(
×
391
                                                /* translators: 1: rule title, 2: "Opens in a new window." */
NEW
392
                                                __( 'Read documentation for %1$s. %2$s', 'accessibility-checker' ),
×
NEW
393
                                                $rule['title'],
×
NEW
394
                                                __( 'Opens in a new window.', 'accessibility-checker' )
×
NEW
395
                                        )
×
NEW
396
                                ) . '"><span class="dashicons dashicons-info"></span></a>';
×
NEW
397
                                $html .= ( $expand_rule ) ? '<button class="edac-details-rule-title-arrow" aria-expanded="false" aria-controls="edac-details-rule-records-' . $rule['slug'] . '" aria-label="' . esc_attr(
×
NEW
398
                                        sprintf(
×
399
                                                /* translators: %s: rule title */
NEW
400
                                                __( 'Expand issues for %s', 'accessibility-checker' ),
×
NEW
401
                                                $rule['title']
×
NEW
402
                                        )
×
NEW
403
                                ) . '"><i class="dashicons dashicons-arrow-down-alt2"></i></button>' : '';
×
UNCOV
404
                                $html .= '</div>';
×
405

406
                                if ( $results ) {
×
407

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

410
                                        $fixes_for_item = [];
×
411
                                        if ( isset( $rule['fixes'] ) && current_user_can( apply_filters( 'edac_filter_settings_capability', 'manage_options' ) ) ) {
×
412
                                                foreach ( $rule['fixes'] as $fix_slug ) {
×
413
                                                        $fixes_for_item[] = FixesManager::get_instance()->get_fix( $fix_slug );
×
414
                                                }
415

416
                                                $controls_id = 'edac-fix-modal-' . $rule['slug'] . '__' . implode( '__', $rule['fixes'] );
×
417
                                                ob_start();
×
418
                                                // NOTE: This is markup to be cloned into a thickbox modal. It gets cloned from the inner div.
419
                                                ?>
420
                                                <div style="display:none">
×
421
                                                        <div id="<?php echo esc_attr( $controls_id ); ?>" class="edac-details-fix-settings fix-settings--container">
×
422
                                                                <div class="setting-row fix-settings--container" data-fix="<?php echo esc_attr( $controls_id ); ?>">
×
423
                                                                        <?php
424
                                                                        printf(
×
425
                                                                                '<p class="modal-opening-message">%s <span class="hide-in-editor">%s</span></p>',
×
426
                                                                                esc_html__( 'These settings enable global fixes across your entire site.', 'accessibility-checker' ),
×
427
                                                                                esc_html__( 'Pages may need to be resaved or a full site scan run to see fixes reflected in reports.', 'accessibility-checker' )
×
428
                                                                        )
×
429
                                                                        ?>
×
430
                                                                        <div class="edac-fix-settings">
×
431
                                                                                <?php
432
                                                                                foreach ( $fixes_for_item as $index => $fix ) :
×
433
                                                                                        ?>
434
                                                                                        <div class="edac-fix-settings--fields">
×
435
                                                                                                <fieldset>
×
436
                                                                                                        <div class="title">
×
437
                                                                                                                <legend>
×
438
                                                                                                                        <h2 class="edac-fix-settings--title"><?php echo esc_html( $fix->get_nicename() ); ?></h2>
×
439
                                                                                                                </legend>
440
                                                                                                        </div>
441
                                                                                                        <?php
442
                                                                                                        foreach ( $fix->get_fields_array() as $name => $field ) {
×
443
                                                                                                                $field['name']     = $name;
×
444
                                                                                                                $field['location'] = 'details-panel';
×
445
                                                                                                                FixesPage::{$field['type']}( $field );
×
446
                                                                                                        }
447
                                                                                                        ?>
448
                                                                                                </fieldset>
×
449
                                                                                                <?php
×
450
                                                                                                // Output the save button only in the last group.
451
                                                                                                if ( count( $fixes_for_item ) === $index + 1 ) :
×
452
                                                                                                        ?>
453
                                                                                                        <div class="edac-fix-settings--action-row">
×
454
                                                                                                                <button role="button" class="button button-primary edac-fix-settings--button--save">
×
455
                                                                                                                        <?php esc_html_e( 'Save', 'accessibility-checker' ); ?>
×
456
                                                                                                                </button>
×
457
                                                                                                                <span class="edac-fix-settings--notice-slot" aria-live="polite" role="alert"></span>
×
458
                                                                                                        </div>
×
459
                                                                                                        <?php
×
460
                                                                                                endif;
461
                                                                                                ?>
462
                                                                                        </div>
×
463
                                                                                <?php endforeach; ?>
×
464
                                                                        </div>
×
465
                                                                </div>
×
466
                                                        </div>
×
467
                                                </div>
×
468
                                                <?php
×
469
                                                $html .= ob_get_clean();
×
470
                                        }
471

472

473

474
                                        $html .=
×
475
                                                '<div class="edac-details-rule-records-labels">
×
476
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
477
                                                                ' . esc_html__( 'Affected Code', 'accessibility-checker' ) . '
×
478
                                                        </div>
479
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
NEW
480
                                                                ' . esc_html__( 'Image', 'accessibility-checker' ) . '
×
481
                                                        </div>
482
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
NEW
483
                                                                ' . esc_html__( 'Landmark', 'accessibility-checker' ) . '
×
484
                                                        </div>
485
                                                        <div class="edac-details-rule-records-labels-label" aria-hidden="true">
NEW
486
                                                                ' . esc_html__( 'Actions', 'accessibility-checker' ) . '
×
487
                                                        </div>
488
                                                </div>';
×
489

490
                                        foreach ( $results as $row ) {
×
491

492
                                                $id            = (int) $row['id'];
×
493
                                                $ignore        = (int) $row['ignre'];
×
494
                                                $ignore_class  = $ignore ? ' active' : '';
×
NEW
495
                                                $ignore_label  = $ignore ? __( 'Dismissed', 'accessibility-checker' ) : __( 'Dismiss', 'accessibility-checker' );
×
496
                                                $ignore_global = (int) $row['ignre_global'];
×
497
                                                $ignore_reason = isset( $row['ignre_reason'] ) ? sanitize_text_field( $row['ignre_reason'] ) : '';
×
498

499
                                                // check for images and svgs in object code.
500
                                                $media      = edac_parse_html_for_media( $row['object'] );
×
501
                                                $object_img = $media['img'];
×
502
                                                $object_svg = $media['svg'];
×
503

NEW
504
                                                $html .= '<h4 class="screen-reader-text">' . sprintf(
×
505
                                                        /* translators: %d: issue ID number */
NEW
506
                                                        esc_html__( 'Issue ID %d', 'accessibility-checker' ),
×
NEW
507
                                                        $id
×
NEW
508
                                                ) . '</h4>';
×
509

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

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

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

516
                                                $html .= '</div>';
×
517

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

520
                                                if ( $object_img ) {
×
NEW
521
                                                        $html .= '<img src="' . esc_url( $object_img ) . '" alt="' . esc_attr(
×
NEW
522
                                                                sprintf(
×
523
                                                                        /* translators: %d: issue ID number */
NEW
524
                                                                        __( 'image for issue %d', 'accessibility-checker' ),
×
NEW
525
                                                                        $id
×
NEW
526
                                                                )
×
NEW
527
                                                        ) . '" />';
×
528
                                                } elseif ( $object_svg ) {
×
529
                                                        $html .= $object_svg;
×
530
                                                }
531

532
                                                $html .= '</div>';
×
533

534
                                                $html .= '<div class="edac-details-rule-records-record-cell edac-details-rule-records-record-landmark">';
×
535

536
                                                $landmark          = isset( $row['landmark'] ) ? $row['landmark'] : '';
×
537
                                                $landmark_selector = isset( $row['landmark_selector'] ) ? $row['landmark_selector'] : '';
×
538

539
                                                $html .= edac_generate_landmark_link( $landmark, $landmark_selector, $postid );
×
540

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

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

545
                                                if ( ! isset( $rule['viewable'] ) || $rule['viewable'] ) {
×
546

547
                                                        $post_view_link = apply_filters(
×
548
                                                                'edac_get_origin_url_for_virtual_page',
×
549
                                                                get_the_permalink( $postid ),
×
550
                                                                $postid
×
551
                                                        );
×
552

553
                                                        $url = add_query_arg(
×
554
                                                                [
×
555
                                                                        'edac'       => $id,
×
556
                                                                        'edac_nonce' => wp_create_nonce( 'edac_highlight' ),
×
557
                                                                ],
×
558
                                                                $post_view_link
×
559
                                                        );
×
560
                                                        // Translators: %d is the issue ID.
561
                                                        $aria_label = sprintf( __( 'View Issue ID %d on website, opens a new window', 'accessibility-checker' ), $id );
×
562
                                                        $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>';
×
563
                                                }
564

565
                                                if ( true === $ignore_permission ) {
×
566
                                                        $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>';
×
567
                                                }
568

569
                                                if ( ! empty( $fixes_for_item ) ) {
×
570
                                                        $html .= sprintf(
×
571
                                                                '<button class="edac-details-rule-records-record-actions-fix"
×
572
                                                                        aria-haspopup="true"
573
                                                                        aria-controls="%1$s"
574
                                                                        aria-label="%2$s"
575
                                                                        type="button"
576
                                                                >
577
                                                                        <span class="dashicons dashicons-admin-tools"></span>
578
                                                                        %3$s
579
                                                                </button>',
×
580
                                                                esc_attr( $controls_id ),
×
581
                                                                esc_attr( __( 'Fix: ', 'accessibility-checker' ) . $fixes_for_item[0]->get_nicename() ),
×
582
                                                                esc_html__( 'Fix', 'accessibility-checker' )
×
583
                                                        );
×
584
                                                }
585

586
                                                $html .= '</div>';
×
587

588
                                                $html .= IgnoreUI::render_ignore_panel(
×
589
                                                        [
×
590
                                                                'issue_id'          => $id,
×
591
                                                                'is_ignored'        => (bool) $ignore,
×
592
                                                                'ignore_user'       => (int) $row['ignre_user'],
×
593
                                                                'ignore_date'       => $row['ignre_date'] ?? '',
×
594
                                                                'ignore_comment'    => $row['ignre_comment'] ?? '',
×
595
                                                                'ignore_reason'     => $ignore_reason,
×
596
                                                                'ignore_global'     => $ignore_global,
×
597
                                                                'ignore_type'       => $rule['rule_type'],
×
598
                                                                'ignore_permission' => $ignore_permission,
×
599
                                                        ]
×
600
                                                );
×
601

602
                                                $html .= '</div>';
×
603

604
                                        }
605

606
                                        $html .= '</div>';
×
607

608
                                }
609

610
                                $html .= '</div>';
×
611
                        }
612
                }
613

614
                if ( ! $html ) {
×
615
                        wp_send_json_error( new \WP_Error( '-4', __( 'No details to return', 'accessibility-checker' ) ) );
×
616
                }
617

618
                wp_send_json_success( wp_json_encode( $html ) );
×
619
        }
620

621
        /**
622
         * Readability Ajax
623
         *
624
         * @return void
625
         *
626
         *  - '-1' means that nonce could not be varified
627
         *  - '-2' means that the post ID was not specified
628
         *  - '-3' means that there isn't any readability data to return
629
         *  - '-5' means that the user does not have permission to view this information for this post
630
         */
631
        public function readability() {
632

633
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['nonce'] ) ), 'ajax-nonce' ) ) {
×
634
                        wp_send_json_error( new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) ) );
×
635
                }
636

637
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
638
                        wp_send_json_error( new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) ) );
×
639
                }
640

641
                if ( ! current_user_can( 'edit_post', (int) $_REQUEST['post_id'] ) ) {
×
642
                        wp_send_json_error( new \WP_Error( '-5', __( 'You do not have permission to view this information for this post.', 'accessibility-checker' ) ) );
×
643
                }
644

645
                $post_id                     = (int) $_REQUEST['post_id'];
×
646
                $html                        = '';
×
647
                $simplified_summary          = get_post_meta( $post_id, '_edac_simplified_summary', true ) ? get_post_meta( $post_id, '_edac_simplified_summary', true ) : '';
×
648
                $simplified_summary_position = get_option( 'edac_simplified_summary_position', $default = false );
×
649
                $content_post                = get_post( $post_id );
×
650
                $content                     = $content_post->post_content;
×
651
                $content                     = apply_filters( 'the_content', $content );
×
652

653
                /**
654
                 * Filter the content used for reading grade readability analysis.
655
                 *
656
                 * @since 1.4.0
657
                 *
658
                 * @param string $content The content to be filtered.
659
                 * @param int    $post_id The post ID.
660
                 */
661
                $content = apply_filters( 'edac_filter_readability_content', $content, $post_id );
×
662
                $content = wp_filter_nohtml_kses( $content );
×
663
                $content = str_replace( ']]>', ']]&gt;', $content );
×
664

665
                // get readability metadata and determine if a simplified summary is required.
666
                $edac_summary           = get_post_meta( $post_id, '_edac_summary', true );
×
667
                $post_grade_readability = ( isset( $edac_summary['readability'] ) ) ? $edac_summary['readability'] : 0;
×
668
                $post_grade             = (int) filter_var( $post_grade_readability, FILTER_SANITIZE_NUMBER_INT );
×
669
                $post_grade_failed      = ( $post_grade < 9 ) ? false : true;
×
670

671
                $simplified_summary_grade = 0;
×
672
                if ( class_exists( 'DaveChild\TextStatistics\TextStatistics' ) ) {
×
673
                        $text_statistics          = new \DaveChild\TextStatistics\TextStatistics();
×
674
                        $simplified_summary_grade = (int) floor( $text_statistics->fleschKincaidGradeLevel( $simplified_summary ) );
×
675
                }
676

677
                $simplified_summary_grade_failed = ( $simplified_summary_grade > 9 ) ? true : false;
×
678
                $simplified_summary_prompt       = get_option( 'edac_simplified_summary_prompt' );
×
679

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

682
                $html .= '<li class="edac-readability-list-item edac-readability-grade-level">
×
683
                ' . edac_icon( ( $post_grade_failed && $simplified_summary && $simplified_summary_grade > 0 && ! $simplified_summary_grade_failed ) ? 'info' : ( ( $post_grade_failed || 0 === $post_grade ) ? 'warning' : 'check' ), '', true, '', 'edac-readability-list-item-icon' ) . '
×
NEW
684
                <h3 class="edac-readability-list-item-title">' .
×
NEW
685
                sprintf(
×
686
                        /* translators: %s: reading grade level value e.g. "8th Grade (Flesch-Kincaid)", displayed in a <strong> element. Do not translate the %s placeholder. */
NEW
687
                        esc_html__( 'Post Reading Grade Level: %s', 'accessibility-checker' ),
×
NEW
688
                        '<strong class="' . ( ( $post_grade_failed || 0 === $post_grade ) ? 'failed-text-color' : 'passed-text-color' ) . '">' . ( ( 0 === $post_grade ) ? esc_html__( 'None', 'accessibility-checker' ) : esc_html( $post_grade_readability ) ) . '</strong>'
×
NEW
689
                ) . '<br /></h3>';
×
690
                if ( $post_grade_failed ) {
×
NEW
691
                        $html .= '<p class="edac-readability-list-item-description">' . esc_html__( '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.', 'accessibility-checker' ) . '</p>';
×
692
                } elseif ( 0 === $post_grade ) {
×
NEW
693
                        $html .= '<p class="edac-readability-list-item-description">' . esc_html__( 'Your post does not contain enough content to calculate its reading level.', 'accessibility-checker' ) . '</p>';
×
694
                } else {
NEW
695
                        $html .= '<p class="edac-readability-list-item-description">' . esc_html__( '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.', 'accessibility-checker' ) . '</p>';
×
696
                }
697
                $html .= '</li>';
×
698

699
                if ( $post_grade_failed ) {
×
700

701
                        if ( $simplified_summary && 'none' !== $simplified_summary_prompt ) {
×
702
                                if ( 0 === $simplified_summary_grade ) {
×
703
                                        $html .= '<li class="edac-readability-list-item edac-readability-summary-grade-level">
×
704
                                        ' . edac_icon( 'warning', '', true, '', 'edac-readability-list-item-icon' ) . '
×
705
                                                <h3 class="edac-readability-list-item-title">' .
×
706
                                                sprintf(
×
707
                                                        /* translators: %s: the simplified summary grade level value (wrapped in a <strong> tag) */
708
                                                        esc_html__( 'Simplified Summary Reading Grade Level: %s', 'accessibility-checker' ),
×
709
                                                        '<strong class="failed-text-color">' . esc_html__( 'None', 'accessibility-checker' ) . '</strong>'
×
710
                                                )
×
711
                                                . '</h3>
×
712
                                                <p class="edac-readability-list-item-description">' . esc_html__( 'Not enough content to determine an accurate reading level.', 'accessibility-checker' ) . '</p>
×
713
                                        </li>';
×
714
                                } else {
715
                                        $html .= '<li class="edac-readability-list-item edac-readability-summary-grade-level">
×
716
                                ' . edac_icon( $simplified_summary_grade_failed ? 'warning' : 'check', '', true, '', 'edac-readability-list-item-icon' ) . '
×
717
                                        <h3 class="edac-readability-list-item-title">' .
×
718
                                                sprintf(
×
719
                                                        /* translators: %s: the simplified summary grade level value (wrapped in a <strong> tag) */
720
                                                        esc_html__( 'Simplified Summary Reading Grade Level: %s', 'accessibility-checker' ),
×
721
                                                        '<strong class="' . ( ( $simplified_summary_grade_failed ) ? 'failed-text-color' : 'passed-text-color' ) . '">' . esc_html( edac_ordinal( $simplified_summary_grade ) ) . '</strong>'
×
722
                                                )
×
723
                                        . '</h3>
×
724
                                        <p class="edac-readability-list-item-description">' . ( ( $simplified_summary_grade_failed )
×
725
                                                ? esc_html__( 'Your simplified summary has a reading level above 9th grade.', 'accessibility-checker' )
×
726
                                                : esc_html__( 'Your simplified summary has a reading level at or below 9th grade.', 'accessibility-checker' )
×
727
                                        ) . '</p>
×
728
                                </li>';
×
729
                                }
730
                        }
731

732
                        if ( 'none' === $simplified_summary_prompt ) {
×
733

734
                                $html .=
×
735
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
736
                                        ' . edac_icon( 'warning', '', true, '', 'edac-readability-list-item-icon' ) . '
×
NEW
737
                                        <h3 class="edac-readability-list-item-title">' . esc_html__( 'Simplified summary is not being automatically inserted into the content.', 'accessibility-checker' ) . '</h3>
×
NEW
738
                                                <p class="edac-readability-list-item-description">' . sprintf(
×
739
                                                        /* translators: %s: link to the settings page */
NEW
740
                                                __( 'Your Prompt for Simplified Summary is set to &ldquo;never.&rdquo; If you would like the simplified summary to be displayed automatically, you can change this on the %s.', 'accessibility-checker' ),
×
NEW
741
                                                '<a href="' . esc_url( admin_url( 'admin.php?page=accessibility_checker_settings' ) ) . '">' . esc_html__( 'settings page', 'accessibility-checker' ) . '</a>'
×
NEW
742
                                        ) . '</p>
×
UNCOV
743
                                </li>';
×
744

745
                        } elseif ( 'none' !== $simplified_summary_position ) {
×
746

747
                                $html .=
×
748
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
749
                                ' . edac_icon( 'check', '', true, '', 'edac-readability-list-item-icon' ) . '
×
NEW
750
                                        <h3 class="edac-readability-list-item-title">' . sprintf(
×
751
                                                /* translators: %s: position phrase wrapped in a <strong> element (e.g. "<strong>before the content</strong>"). Do not translate the %s placeholder. */
NEW
752
                                        __( 'Simplified summary is being automatically inserted %s.', 'accessibility-checker' ),
×
NEW
753
                                        '<strong>' . esc_html( $simplified_summary_position ) . ' ' . esc_html__( 'the content', 'accessibility-checker' ) . '</strong>'
×
NEW
754
                                ) . '</h3>
×
NEW
755
                                                <p class="edac-readability-list-item-description">' . sprintf(
×
756
                                                        /* translators: %s: link to the settings page */
NEW
757
                                        __( 'Set where the Simplified Summary is inserted into the content on the %s.', 'accessibility-checker' ),
×
NEW
758
                                        '<a href="' . esc_url( admin_url( 'admin.php?page=accessibility_checker_settings' ) ) . '">' . esc_html__( 'settings page', 'accessibility-checker' ) . '</a>'
×
NEW
759
                                ) . '</p>
×
UNCOV
760
                                </li>';
×
761

762
                        } else {
763

764
                                $html .=
×
765
                                        '<li class="edac-readability-list-item edac-readability-summary-position">
×
766
                                        ' . edac_icon( 'warning', '', true, '', 'edac-readability-list-item-icon' ) . '
×
NEW
767
                                        <h3 class="edac-readability-list-item-title">' . esc_html__( 'Simplified summary is not being automatically inserted into the content.', 'accessibility-checker' ) . '</h3>
×
NEW
768
                                                <p class="edac-readability-list-item-description">' . sprintf(
×
769
                                                        /* translators: %s: link to the settings page */
NEW
770
                                                __( 'Your Simplified Summary location is set to &ldquo;manually&rdquo; 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 %s.', 'accessibility-checker' ),
×
NEW
771
                                                '<a href="' . esc_url( admin_url( 'admin.php?page=accessibility_checker_settings' ) ) . '">' . esc_html__( 'settings page', 'accessibility-checker' ) . '</a>'
×
NEW
772
                                        ) . '</p>
×
UNCOV
773
                                </li>';
×
774

775
                        }
776
                }
777

778
                $html .= '</ul>';
×
779

780
                if ( ( $post_grade_failed || 'always' === $simplified_summary_prompt ) && ( 'none' !== $simplified_summary_prompt ) ) {
×
781
                        $html .=
×
782
                                '</form>
×
783
                        <form action="/" class="edac-readability-simplified-summary">
NEW
784
                                <label for="edac-readability-text">' . esc_html__( 'Simplified Summary', 'accessibility-checker' ) . '</label>
×
785
                                <textarea name="" id="edac-readability-text" cols="30" rows="10">' . $simplified_summary . '</textarea>
×
NEW
786
                                <p><input type="submit" class="button button-primary" value="' . esc_attr__( 'Save Summary', 'accessibility-checker' ) . '"></p>
×
787
                        </form>';
×
788
                }
789

NEW
790
                $html .= '<span class="dashicons dashicons-info" aria-hidden="true"></span> <a href="' . esc_url( edac_link_wrapper( 'https://a11ychecker.com/help3265', 'wordpress-general', 'content-analysis', false ) ) . '" target="_blank">' . esc_html__( 'Learn more about improving readability and simplified summary requirements', 'accessibility-checker' ) . '<span aria-hidden="true"> ↗</span><span class="screen-reader-text">' . __( ', opens a new window', 'accessibility-checker' ) . '</span></a>';
×
791

792
                if ( ! $html ) {
×
793
                        wp_send_json_error( new \WP_Error( '-3', __( 'No readability data to return', 'accessibility-checker' ) ) );
×
794
                }
795

796
                wp_send_json_success( wp_json_encode( $html ) );
×
797
        }
798

799
        /**
800
         * Insert ignore data into database
801
         *
802
         * Note: There is a new dismiss-issue rest endpoint that covers this functionality
803
         * now and should be used going forward. This ajax was updated to support dismiss
804
         * reasons to align with the new endpoint and allow other things to continue to
805
         * work here gracefully.
806
         *
807
         * This should be removed in a future release.
808
         *
809
         * @return void
810
         *
811
         *  - '-1' means that nonce could not be varified
812
         *  - '-2' means that there isn't any ignore data to return
813
         */
814
        public function add_ignore() {
815

816
                // nonce security.
817
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ), 'ajax-nonce' ) ) {
×
818
                        wp_send_json_error( new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) ) );
×
819
                }
820

821
                global $wpdb;
×
822
                $table_name           = $wpdb->prefix . 'accessibility_checker';
×
823
                $raw_ids              = isset( $_REQUEST['ids'] ) ? (array) wp_unslash( $_REQUEST['ids'] ) : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitization handled below.
×
824
                $ids                  = array_map(
×
825
                        function ( $value ) {
×
826
                                return (int) $value;
×
827
                        },
×
828
                        $raw_ids
×
829
                ); // Sanitizing array elements to integers.
×
830
                $action               = isset( $_REQUEST['ignore_action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['ignore_action'] ) ) : '';
×
831
                $type                 = isset( $_REQUEST['ignore_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['ignore_type'] ) ) : '';
×
832
                $siteid               = get_current_blog_id();
×
833
                $ignre                = ( 'enable' === $action ) ? 1 : 0;
×
834
                $ignre_user           = ( 'enable' === $action ) ? get_current_user_id() : null;
×
835
                $ignre_user_info      = ( 'enable' === $action ) ? get_userdata( $ignre_user ) : '';
×
836
                $ignre_username       = ( 'enable' === $action ) ? $ignre_user_info->user_login : '';
×
837
                $ignre_date           = ( 'enable' === $action ) ? edac_get_current_utc_datetime() : null;
×
838
                $ignre_date_formatted = ( 'enable' === $action ) ? edac_format_datetime_from_utc( $ignre_date ) : '';
×
839
                $ignre_comment        = ( 'enable' === $action && isset( $_REQUEST['comment'] ) ) ? sanitize_textarea_field( wp_unslash( $_REQUEST['comment'] ) ) : null;
×
840
                $ignre_reason         = ( 'enable' === $action && isset( $_REQUEST['reason'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['reason'] ) ) : null;
×
841
                $ignore_global        = ( 'enable' === $action && isset( $_REQUEST['ignore_global'] ) ) ? sanitize_textarea_field( wp_unslash( $_REQUEST['ignore_global'] ) ) : 0;
×
842

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

852
                        if ( ! $object ) {
×
853
                                wp_send_json_error( new \WP_Error( '-2', __( 'No ignore data to return', 'accessibility-checker' ) ) );
×
854
                        }
855
                        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
856
                        $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_reason = %s, ignre_global = %d WHERE siteid = %d and object = %s', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignre_reason, $ignore_global, $siteid, $object ) );
×
857
                } else {
858
                        // For small batches of IDs, we can just loop through.
859
                        foreach ( $ids as $id ) {
×
860
                                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name, caching not required for one time operation.
861
                                $wpdb->query( $wpdb->prepare( 'UPDATE %i SET ignre = %d, ignre_user = %d, ignre_date = %s, ignre_comment = %s, ignre_reason = %s, ignre_global = %d WHERE siteid = %d and id = %d', $table_name, $ignre, $ignre_user, $ignre_date, $ignre_comment, $ignre_reason, $ignore_global, $siteid, $id ) );
×
862
                        }
863
                }
864

865
                $data = [
×
866
                        'ids'    => $ids,
×
867
                        'action' => $action,
×
868
                        'type'   => $type,
×
869
                        'user'   => $ignre_username,
×
870
                        'date'   => $ignre_date_formatted,
×
871
                ];
×
872

873
                if ( ! $data ) {
×
874
                        wp_send_json_error( new \WP_Error( '-2', __( 'No ignore data to return', 'accessibility-checker' ) ) );
×
875
                }
876
                wp_send_json_success( wp_json_encode( $data ) );
×
877
        }
878

879
        /**
880
         * Handle AJAX request to dismiss Welcome CTA
881
         *
882
         * @return void
883
         */
884
        public function dismiss_welcome_cta() {
885

886
                update_user_meta( get_current_user_id(), 'edac_welcome_cta_dismissed', true );
×
887

888
                wp_send_json( 'success' );
×
889
        }
890

891
        /**
892
         * Handle AJAX request to dismiss dashboard CTA
893
         *
894
         * @return void
895
         */
896
        public function dismiss_dashboard_cta() {
897

898
                update_user_meta( get_current_user_id(), 'edac_dashboard_cta_dismissed', true );
×
899

900
                wp_send_json( 'success' );
×
901
        }
902
}
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