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

equalizedigital / accessibility-checker / 13683549811

05 Mar 2025 07:04PM UTC coverage: 24.689% (-0.05%) from 24.736%
13683549811

push

github

web-flow
Merge pull request #861 from equalizedigital/william/no-issue/bump-cache-action-version-in-jslint-workflow

Bump the actions/cache to v4 to avoid fails due to v2 deprecated

1765 of 7149 relevant lines covered (24.69%)

5.51 hits per line

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

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

8
namespace EDAC\Admin;
9

10
use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager;
11

12
/**
13
 * Class that handles admin notices
14
 */
15
class Admin_Notices {
16

17
        /**
18
         * Initialize the class and set its properties.
19
         */
20
        public function __construct() {
21
        }
20✔
22

23
        /**
24
         * Initialize class hooks.
25
         *
26
         * @return void
27
         */
28
        public function init_hooks() {
29

30
                add_action( 'in_admin_header', [ $this, 'edac_remove_admin_notices' ], 1000 );
2✔
31
                add_action( 'in_admin_header', [ $this, 'hook_notices' ], 1001 );
2✔
32
                // Ajax handlers for notices.
33
                add_action( 'wp_ajax_edac_black_friday_notice_ajax', [ $this, 'edac_black_friday_notice_ajax' ] );
2✔
34
                add_action( 'wp_ajax_edac_gaad_notice_ajax', [ $this, 'edac_gaad_notice_ajax' ] );
2✔
35
                add_action( 'wp_ajax_edac_review_notice_ajax', [ $this, 'edac_review_notice_ajax' ] );
2✔
36
                add_action( 'wp_ajax_edac_password_protected_notice_ajax', [ $this, 'edac_password_protected_notice_ajax' ] );
2✔
37
                add_action( 'wp_ajax_edac_welcome_page_post_count_change_notice_dismiss_ajax', [ $this, 'welcome_page_post_count_change_notice_ajax' ] );
2✔
38
                // Save fixes transient on save.
39
                add_action( 'updated_option', [ $this, 'set_fixes_transient_on_save' ] );
2✔
40
        }
41

42
        /**
43
         * Hook Notices
44
         *
45
         * @since 1.9.3
46
         *
47
         * @return void
48
         */
49
        public function hook_notices() {
50
                if ( ! Helpers::current_user_can_see_widgets_and_notices() ) {
×
51
                        return;
×
52
                }
53

54
                add_action( 'admin_notices', [ $this, 'edac_black_friday_notice' ] );
×
55
                add_action( 'admin_notices', [ $this, 'edac_gaad_notice' ] );
×
56
                add_action( 'admin_notices', [ $this, 'edac_review_notice' ] );
×
57
                add_action( 'admin_notices', [ $this, 'edac_password_protected_notice' ] );
×
58
                add_action( 'admin_notices', [ $this, 'welcome_page_post_count_change_notice' ] );
×
59
        }
60

61
        /**
62
         * Notify users of the improvements to stats calculations.
63
         *
64
         * In version 1.21.0 we changed how posts_scanned was counted along with how other values like averages
65
         * were calculated.
66
         *
67
         * @since 1.21.0
68
         *
69
         * @return void
70
         */
71
        public function welcome_page_post_count_change_notice() {
72
                // Only show this notice if the version number is below 1.22.0.
73
                if ( version_compare( EDAC_VERSION, '1.22.0', '>=' ) ) {
×
74
                        return;
×
75
                }
76

77
                // Only output this message on the welcome page.
78
                if ( 'toplevel_page_accessibility_checker' !== get_current_screen()->id ) {
×
79
                        return;
×
80
                }
81

82
                // Check if the notice has been dismissed.
83
                if ( absint( get_option( 'edac_welcome_page_post_count_change_notice_dismiss', 0 ) ) ) {
×
84
                        return;
×
85
                }
86

87
                ?>
88
                <div class="notice notice-info is-dismissible edac-stats-improvement-notice">
×
89
                        <p>
×
90
                                <?php
×
91
                                        $release_post_link = edac_generate_link_type( [], 'custom', [ 'base_link' => 'https://equalizedigital.com/corrected-calculations-in-accessibility-checker-pro-and-audit-history/' ] );
×
92
                                        printf(
×
93
                                                // translators: %1$s is the opening anchor tag, %2$s is the closing anchor tag.
94
                                                esc_html__( 'We have improved the statistics calculations in version 1.21.0. As a result, some numbers in the data below may have changed. Read more in our %1$srelease announcement post%2$s.', 'accessibility-checker' ),
×
95
                                                '<a href="' . esc_url( $release_post_link ) . '" target="_blank">',
×
96
                                                '</a>'
×
97
                                        );
×
98
                                ?>
99
                        </p>
×
100
                </div>
×
101
                <?php
×
102
        }
103

104
        /**
105
         * Store a option to remember when user has dismissed this notice.
106
         *
107
         * @return void
108
         */
109
        public function welcome_page_post_count_change_notice_ajax() {
110

111
                // nonce security.
112
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
113

114
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
115
                        wp_send_json_error( $error );
×
116

117
                }
118

119
                $results = update_option( 'edac_welcome_page_post_count_change_notice_dismiss', true );
×
120

121
                if ( ! $results ) {
×
122

123
                        $error = new \WP_Error( '-2', 'Update option wasn\'t successful' );
×
124
                        wp_send_json_error( $error );
×
125

126
                }
127

128
                wp_send_json_success( wp_json_encode( $results ) );
×
129
        }
130

131
        /**
132
         * Remove Admin Notices
133
         *
134
         * @return void
135
         */
136
        public function edac_remove_admin_notices() {
137

138
                $current_screen = get_current_screen();
×
139
                $screens        = [
×
140
                        'toplevel_page_accessibility_checker',
×
141
                        'accessibility-checker_page_accessibility_checker_issues',
×
142
                        'accessibility-checker_page_accessibility_checker_ignored',
×
143
                        'accessibility-checker_page_accessibility_checker_settings',
×
144
                ];
×
145

146
                /**
147
                 * Filter the screens where admin notices should be removed.
148
                 *
149
                 * @since 1.14.0
150
                 *
151
                 * @param array $screens The screens where admin notices should be removed.
152
                 */
153
                $screens = apply_filters( 'edac_filter_remove_admin_notices_screens', $screens );
×
154

155
                if ( in_array( $current_screen->id, $screens, true ) ) {
×
156
                        remove_all_actions( 'admin_notices' );
×
157
                        remove_all_actions( 'all_admin_notices' );
×
158
                }
159
        }
160

161
        /**
162
         * Black Friday Admin Notice
163
         *
164
         * @return void
165
         */
166
        public function edac_black_friday_notice() {
167

168
                // check if accessibility checker pro is active.
169
                if ( is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' ) ) {
×
170
                        return;
×
171
                }
172

173
                // Check if the notice has been dismissed.
174
                if ( absint( get_option( 'edac_black_friday_2024_notice_dismiss', 0 ) ) ) {
×
175
                        return;
×
176
                }
177

178
                // Show from November 25 to December 03.
179
                $current_date = date_i18n( 'Ymd' ); // Use date_i18n for localization.
×
180
                $start_date   = '20241125';
×
181
                $end_date     = '20241203';
×
182

183
                if ( $current_date >= $start_date && $current_date <= $end_date ) {
×
184

185
                        // Get the promotional message from a separate function/file.
186
                        $message = $this->edac_get_black_friday_message();
×
187

188
                        // Output the message with appropriate sanitization.
189
                        echo wp_kses_post( $message );
×
190

191
                }
192
        }
193

194
        /**
195
         * Get Black Friday Promo Message
196
         *
197
         * @return string
198
         */
199
        public function edac_get_black_friday_message() {
200

201
                // Construct the promotional message.
202
                $message  = '<div class="edac_black_friday_notice notice notice-info is-dismissible">';
4✔
203
                $message .= '<p><strong>' . esc_html__( '🎉 Black Friday special! 🎉', 'accessibility-checker' ) . '</strong><br />';
4✔
204
                $message .= esc_html__( 'Upgrade to a paid version of Accessibility Checker from November 25th to December 3rd and get 30% off! Full site scanning, site-wide open issues report, ignore logs, and more.', 'accessibility-checker' ) . '<br />';
4✔
205
                $message .= '<a class="button button-primary" href="' . esc_url( 'https://my.equalizedigital.com/support/pre-sale-questions/?utm_source=accessibility-checker&utm_medium=software&utm_campaign=BlackFriday' ) . '">' . esc_html__( 'Ask a Pre-Sale Question', 'accessibility-checker' ) . '</a> ';
4✔
206
                $message .= '<a class="button button-primary" href="' . esc_url( 'https://equalizedigital.com/accessibility-checker/pricing/?utm_source=WPadmin&utm_medium=banner&utm_campaign=BlackFriday' ) . '">' . esc_html__( 'Upgrade Now', 'accessibility-checker' ) . '</a></p>';
4✔
207
                $message .= '</div>';
4✔
208

209
                return $message;
4✔
210
        }
211

212
        /**
213
         * Black Friday Admin Notice Ajax
214
         *
215
         * @return void
216
         *
217
         *  - '-1' means that nonce could not be varified
218
         *  - '-2' means that update option wasn't successful
219
         */
220
        public function edac_black_friday_notice_ajax() {
221

222
                // nonce security.
223
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
224

225
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
226
                        wp_send_json_error( $error );
×
227

228
                }
229

230
                $results = update_option( 'edac_black_friday_2024_notice_dismiss', true );
×
231

232
                if ( ! $results ) {
×
233

234
                        $error = new \WP_Error( '-2', 'Update option wasn\'t successful' );
×
235
                        wp_send_json_error( $error );
×
236

237
                }
238

239
                wp_send_json_success( wp_json_encode( $results ) );
×
240
        }
241

242
        /**
243
         * GAAD Notice
244
         *
245
         * @return string
246
         */
247
        public function edac_gaad_notice() {
248

249
                // Define constants for start and end dates.
250
                define( 'EDAC_GAAD_NOTICE_START_DATE', '2024-05-16' );
×
251
                define( 'EDAC_GAAD_NOTICE_END_DATE', '2024-05-23' );
×
252

253
                // Check if Accessibility Checker Pro is active.
254
                $pro = is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' );
×
255
                if ( $pro ) {
×
256
                        return;
×
257
                }
258

259
                // Get the value of the 'edac_gaad_notice_dismiss' option and sanitize it.
260
                $dismissed = absint( get_option( 'edac_gaad_notice_dismiss_2024', 0 ) );
×
261

262
                // Check if the notice has been dismissed.
263
                if ( $dismissed ) {
×
264
                        return;
×
265
                }
266

267
                // Get the current date in the 'Y-m-d' format.
268
                $current_date = gmdate( 'Y-m-d' );
×
269

270
                // Check if the current date is within the specified range.
271
                if ( $current_date >= EDAC_GAAD_NOTICE_START_DATE && $current_date <= EDAC_GAAD_NOTICE_END_DATE ) {
×
272

273
                        // Get the promotional message from a separate function/file.
274
                        $message = $this->edac_get_gaad_promo_message();
×
275

276
                        // Output the message with appropriate sanitization.
277
                        echo wp_kses_post( $message );
×
278

279
                }
280
        }
281

282
        /**
283
         * Get GAAD Promo Message
284
         *
285
         * @return string
286
         */
287
        public function edac_get_gaad_promo_message() {
288

289
                // Construct the promotional message.
290
                $message  = '<div class="edac_gaad_notice notice notice-info is-dismissible">';
4✔
291
                $message .= '<p><strong>' . esc_html__( '🎉 Get 25% off Accessibility Checker Pro in honor of Global Accessibility Awareness Day! 🎉', 'accessibility-checker' ) . '</strong><br />';
4✔
292
                $message .= esc_html__( 'Use coupon code GAAD24 from May 16th-May 23rd to get access to full-site scanning and other pro features at a special discount. Not sure if upgrading is right for you?', 'accessibility-checker' ) . '<br />';
4✔
293
                $message .= '<a class="button button-primary" href="' . esc_url( 'https://my.equalizedigital.com/support/pre-sale-questions/?utm_source=accessibility-checker&utm_medium=software&utm_campaign=GAAD24' ) . '">' . esc_html__( 'Ask a Pre-Sale Question', 'accessibility-checker' ) . '</a> ';
4✔
294
                $message .= '<a class="button button-primary" href="' . esc_url( 'https://equalizedigital.com/accessibility-checker/pricing/?utm_source=accessibility-checker&utm_medium=software&utm_campaign=GAAD24' ) . '">' . esc_html__( 'Upgrade Now', 'accessibility-checker' ) . '</a></p>';
4✔
295
                $message .= '</div>';
4✔
296

297
                return $message;
4✔
298
        }
299

300
        /**
301
         * GAAD Admin Notice Ajax
302
         *
303
         * @return void
304
         *
305
         *  - '-1' means that nonce could not be varified
306
         *  - '-2' means that update option wasn't successful
307
         */
308
        public function edac_gaad_notice_ajax() {
309

310
                // nonce security.
311
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
312

313
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
314
                        wp_send_json_error( $error );
×
315

316
                }
317

318
                $results = update_option( 'edac_gaad_notice_dismiss_2024', true );
×
319
                // delete old meta key.
320
                delete_option( 'edac_gaad_notice_dismiss' );
×
321

322
                if ( ! $results ) {
×
323

324
                        $error = new \WP_Error( '-2', 'Update option wasn\'t successful' );
×
325
                        wp_send_json_error( $error );
×
326

327
                }
328

329
                wp_send_json_success( wp_json_encode( $results ) );
×
330
        }
331

332
        /**
333
         * Review Admin Notice
334
         *
335
         * @return void
336
         */
337
        public function edac_review_notice() {
338

339
                $option             = 'edac_review_notice';
×
340
                $edac_review_notice = get_option( $option );
×
341

342
                // exit if option is set to stop.
343
                if ( 'stop' === $edac_review_notice ) {
×
344
                        return;
×
345
                }
346

347
                $transient                   = 'edac_review_notice_reminder';
×
348
                $edac_review_notice_reminder = get_transient( $transient );
×
349

350
                // first time if notice has never been shown wait 14 days.
351
                if ( false === $edac_review_notice_reminder && empty( $edac_review_notice ) ) {
×
352
                        // if option isn't set and plugin has been active for more than 14 days show notice. This is for current users.
353
                        if ( edac_days_active() > 14 ) {
×
354
                                update_option( $option, 'play' );
×
355
                        } else {
356
                                // if plugin has been active less than 14 days set transient for 14 days.
357
                                set_transient( $transient, true, 14 * DAY_IN_SECONDS );
×
358
                                // set option to pause.
359
                                update_option( $option, 'pause' );
×
360
                        }
361
                }
362

363
                // if transient has expired and option is set to pause update option to play.
364
                if ( false === $edac_review_notice_reminder && 'pause' === $edac_review_notice ) {
×
365
                        update_option( $option, 'play' );
×
366
                }
367

368
                // if option is not set to play exit.
369
                if ( get_option( $option ) !== 'play' ) {
×
370
                        return;
×
371
                }
372

373
                ?>
374
                <div class="notice notice-info edac-review-notice">
×
375
                        <p>
×
376
                                <?php esc_html_e( "Hello! Thank you for using Accessibility Checker as part of your accessibility toolkit. Since you've been using it for a while, would you please write a 5-star review of Accessibility Checker in the WordPress plugin directory? This will help increase our visibility so more people can learn about the importance of web accessibility. Thanks so much!", 'accessibility-checker' ); ?>
×
377
                        </p>
×
378
                        <p>
×
379
                                <button class="edac-review-notice-review button button-small button-primary"><?php esc_html_e( 'Write A Review', 'accessibility-checker' ); ?></button>
×
380
                                <button class="edac-review-notice-remind button button-small"><?php esc_html_e( 'Remind Me In Two Weeks', 'accessibility-checker' ); ?></button>
×
381
                                <button class="edac-review-notice-dismiss button button-small"><?php esc_html_e( 'Never Ask Again', 'accessibility-checker' ); ?></button>
×
382
                        </p>
383
                </div>
384
                <?php
385
        }
386

387
        /**
388
         * Review Admin Notice Ajax
389
         *
390
         * @return void
391
         *
392
         *  - '-1' means that nonce could not be varified
393
         *  - '-2' means that the review action value was not specified
394
         *  - '-3' means that update option wasn't successful
395
         */
396
        public function edac_review_notice_ajax() {
397

398
                // nonce security.
399
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
400

401
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
402
                        wp_send_json_error( $error );
×
403

404
                }
405

406
                if ( ! isset( $_REQUEST['review_action'] ) ) {
×
407

408
                        $error = new \WP_Error( '-2', 'The review action value was not set' );
×
409
                        wp_send_json_error( $error );
×
410

411
                }
412

413
                $results = update_option( 'edac_review_notice', sanitize_text_field( $_REQUEST['review_action'] ) );
×
414

415
                if ( 'pause' === $_REQUEST['review_action'] ) {
×
416
                        set_transient( 'edac_review_notice_reminder', true, 14 * DAY_IN_SECONDS );
×
417
                }
418

419
                if ( ! $results ) {
×
420

421
                        $error = new \WP_Error( '-3', 'Update option wasn\'t successful' );
×
422
                        wp_send_json_error( $error );
×
423

424
                }
425

426
                wp_send_json_success( wp_json_encode( $results ) );
×
427
        }
428

429
        /**
430
         * Password Protected Notice Text
431
         *
432
         * @return string
433
         */
434
        public function edac_password_protected_notice_text() {
435
                /**
436
                 * Filter the password protected notice text.
437
                 *
438
                 * @since 1.4.0
439
                 *
440
                 * @param string $text The password protected notice text.
441
                 */
442
                return apply_filters(
4✔
443
                        'edac_filter_password_protected_notice_text',
4✔
444
                        sprintf(
4✔
445
                                // translators: %s is the link to upgrade to pro, with "upgrade to pro" as the anchor text.
446
                                esc_html__( 'Whoops! It looks like your website is currently password protected. The free version of Accessibility Checker can only scan live websites. To scan this website for accessibility problems either remove the password protection or %s. Scan results may be stored from a previous scan.', 'accessibility-checker' ),
4✔
447
                                sprintf(
4✔
448
                                        '<a href="https://equalizedigital.com/accessibility-checker/pricing/" target="_blank" aria-label="%1$s">%2$s</a>',
4✔
449
                                        esc_attr__( 'Upgrade to accessibility checker pro. Opens in a new window.', 'accessibility-checker' ),
4✔
450
                                        esc_html__( 'upgrade to pro', 'accessibility-checker' )
4✔
451
                                )
4✔
452
                        )
4✔
453
                );
4✔
454
        }
455

456
        /**
457
         * Password Protected Notice
458
         *
459
         * @return string
460
         */
461
        public function edac_password_protected_notice() {
462
                if ( (bool) get_option( 'edac_password_protected' )
×
463
                        && ! (bool) get_option( 'edac_password_protected_notice_dismiss' )
×
464
                ) {
465
                        echo wp_kses( '<div class="edac_password_protected_notice notice notice-error is-dismissible"><p>' . $this->edac_password_protected_notice_text() . '</p></div>', 'post' );
×
466
                        return;
×
467
                }
468
        }
469

470
        /**
471
         * Password Protected Admin Notice Ajax
472
         *
473
         * @return void
474
         *
475
         *  - '-1' means that nonce could not be varified
476
         *  - '-2' means that update option wasn't successful
477
         */
478
        public function edac_password_protected_notice_ajax() {
479

480
                // nonce security.
481
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
482

483
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
484
                        wp_send_json_error( $error );
×
485

486
                }
487

488
                $results = update_option( 'edac_password_protected_notice_dismiss', true );
×
489

490
                if ( ! $results ) {
×
491

492
                        $error = new \WP_Error( '-2', 'Update option wasn\'t successful' );
×
493
                        wp_send_json_error( $error );
×
494

495
                }
496

497
                wp_send_json_success( wp_json_encode( $results ) );
×
498
        }
499

500
        /**
501
         * Save a transient to indicate that the fixes settings have been updated.
502
         *
503
         * @param string $option    The option name that was saved.
504
         *
505
         * @return void
506
         */
507
        public function set_fixes_transient_on_save( $option ) {
508
                if ( ! class_exists( 'EqualizeDigital\AccessibilityChecker\Fixes\FixesManager' ) ) {
×
509
                        return;
×
510
                }
511
                $fixes_settings = FixesManager::get_instance()->get_fixes_settings();
×
512
                $options_keys   = [];
×
513
                foreach ( $fixes_settings as $fix ) {
×
514
                        $options_keys = array_merge( $options_keys, array_keys( $fix['fields'] ) );
×
515
                }
516
                if ( in_array( $option, $options_keys, true ) ) {
×
517
                        // Set a custom transient as a flag.
518
                        set_transient( 'edac_fixes_settings_saved', true, 60 );
×
519
                }
520
        }
521
}
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