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

equalizedigital / accessibility-checker / 14763041616

30 Apr 2025 07:46PM UTC coverage: 25.605% (-0.004%) from 25.609%
14763041616

push

github

web-flow
Merge pull request #947 from equalizedigital/william/pro-69-update-gaad25-admin-banner

Update GAAD notice dates and coupon code for 2025 promotion

3 of 8 new or added lines in 1 file covered. (37.5%)

1 existing line in 1 file now uncovered.

1681 of 6565 relevant lines covered (25.61%)

1.33 hits per line

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

19.54
/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.
NEW
250
                define( 'EDAC_GAAD_NOTICE_START_DATE', '2025-04-13' );
×
NEW
251
                define( 'EDAC_GAAD_NOTICE_END_DATE', '2025-05-21' );
×
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.
NEW
260
                $dismissed = absint( get_option( 'edac_gaad_notice_dismiss_2025', 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 GAAD25 from May 13th-May 21st 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=GAAD25' ) . '">' . 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=GAAD25' ) . '">' . 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

NEW
318
                $results = update_option( 'edac_gaad_notice_dismiss_2025', true );
×
319
                // Delete old meta keys if they exist.
NEW
320
                delete_option( 'edac_gaad_notice_dismiss_2024' );
×
UNCOV
321
                delete_option( 'edac_gaad_notice_dismiss' );
×
322

323
                if ( ! $results ) {
×
324

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

328
                }
329

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

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

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

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

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

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

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

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

374
                ?>
375
                <div class="notice notice-info edac-review-notice">
×
376
                        <p>
×
377
                                <?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' ); ?>
×
378
                        </p>
×
379
                        <p>
×
380
                                <button class="edac-review-notice-review button button-small button-primary"><?php esc_html_e( 'Write A Review', 'accessibility-checker' ); ?></button>
×
381
                                <button class="edac-review-notice-remind button button-small"><?php esc_html_e( 'Remind Me In Two Weeks', 'accessibility-checker' ); ?></button>
×
382
                                <button class="edac-review-notice-dismiss button button-small"><?php esc_html_e( 'Never Ask Again', 'accessibility-checker' ); ?></button>
×
383
                        </p>
384
                </div>
385
                <?php
386
        }
387

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

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

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

405
                }
406

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

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

412
                }
413

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

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

420
                if ( ! $results ) {
×
421

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

425
                }
426

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

430
        /**
431
         * Password Protected Notice Text
432
         *
433
         * @return string
434
         */
435
        public function edac_password_protected_notice_text() {
436
                /**
437
                 * Filter the password protected notice text.
438
                 *
439
                 * @since 1.4.0
440
                 *
441
                 * @param string $text The password protected notice text.
442
                 */
443
                return apply_filters(
4✔
444
                        'edac_filter_password_protected_notice_text',
4✔
445
                        sprintf(
4✔
446
                                // translators: %s is the link to upgrade to pro, with "upgrade to pro" as the anchor text.
447
                                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✔
448
                                sprintf(
4✔
449
                                        '<a href="https://equalizedigital.com/accessibility-checker/pricing/" target="_blank" aria-label="%1$s">%2$s</a>',
4✔
450
                                        esc_attr__( 'Upgrade to accessibility checker pro. Opens in a new window.', 'accessibility-checker' ),
4✔
451
                                        esc_html__( 'upgrade to pro', 'accessibility-checker' )
4✔
452
                                )
4✔
453
                        )
4✔
454
                );
4✔
455
        }
456

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

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

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

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

487
                }
488

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

491
                if ( ! $results ) {
×
492

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

496
                }
497

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

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