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

equalizedigital / accessibility-checker / 18719438959

22 Oct 2025 02:23PM UTC coverage: 57.551%. First build
18719438959

Pull #1263

github

web-flow
Merge 9629edd96 into 0b5b9ed0a
Pull Request #1263: Release v1.34.0

3 of 236 new or added lines in 6 files covered. (1.27%)

4154 of 7218 relevant lines covered (57.55%)

3.45 hits per line

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

16.8
/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
        }
14✔
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
                // Save fixes transient on save.
37
                add_action( 'updated_option', [ $this, 'set_fixes_transient_on_save' ] );
2✔
38
        }
39

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

52
                add_action( 'admin_notices', [ $this, 'edac_black_friday_notice' ] );
×
53
                add_action( 'admin_notices', [ $this, 'edac_gaad_notice' ] );
×
54
                add_action( 'admin_notices', [ $this, 'edac_review_notice' ] );
×
55
        }
56

57
        /**
58
         * Remove Admin Notices
59
         *
60
         * @return void
61
         */
62
        public function edac_remove_admin_notices() {
63

64
                $current_screen = get_current_screen();
×
65
                $screens        = [
×
66
                        'toplevel_page_accessibility_checker',
×
67
                        'accessibility-checker_page_accessibility_checker_issues',
×
68
                        'accessibility-checker_page_accessibility_checker_ignored',
×
69
                        'accessibility-checker_page_accessibility_checker_settings',
×
70
                ];
×
71

72
                /**
73
                 * Filter the screens where admin notices should be removed.
74
                 *
75
                 * @since 1.14.0
76
                 *
77
                 * @param array $screens The screens where admin notices should be removed.
78
                 */
79
                $screens = apply_filters( 'edac_filter_remove_admin_notices_screens', $screens );
×
80

81
                if ( in_array( $current_screen->id, $screens, true ) ) {
×
82
                        remove_all_actions( 'admin_notices' );
×
83
                        remove_all_actions( 'all_admin_notices' );
×
84
                }
85
        }
86

87
        /**
88
         * Black Friday Admin Notice
89
         *
90
         * @return void
91
         */
92
        public function edac_black_friday_notice() {
93

94
                // Check if Accessibility Checker Pro is active.
95
                if ( defined( 'EDACP_VERSION' ) ) {
×
96
                        return;
×
97
                }
98

99
                // Check if the notice has been dismissed.
NEW
100
                if ( absint( get_option( 'edac_black_friday_2025_notice_dismiss', 0 ) ) ) {
×
101
                        return;
×
102
                }
103

104
                // Show from November 24 to December 03.
105
                $current_date = date_i18n( 'Ymd' ); // Use date_i18n for localization.
×
NEW
106
                $start_date   = '20251124';
×
NEW
107
                $end_date     = '20251203';
×
108

109
                if ( $current_date >= $start_date && $current_date <= $end_date ) {
×
110

111
                        // Get the promotional message from a separate function/file.
112
                        $message = $this->edac_get_black_friday_message();
×
113

114
                        // Output the message with appropriate sanitization.
115
                        echo wp_kses_post( $message );
×
116

117
                }
118
        }
119

120
        /**
121
         * Get Black Friday Promo Message
122
         *
123
         * @return string
124
         */
125
        public function edac_get_black_friday_message() {
126

127
                // Construct the promotional message.
128
                $message  = '<div class="edac_black_friday_notice notice notice-info is-dismissible">';
4✔
129
                $message .= '<p><strong>' . esc_html__( '🎉 Black Friday special! 🎉', 'accessibility-checker' ) . '</strong><br />';
4✔
130
                $message .= esc_html__( 'Upgrade to a paid version of Accessibility Checker from November 24th to December 3rd and get 30% off! Full site scanning, site-wide open issues report, ignore logs, and more.', 'accessibility-checker' ) . '<br />';
4✔
131
                $message .= '<a class="button button-primary" href="' . esc_url( edac_link_wrapper( 'https://my.equalizedigital.com/support/pre-sale-questions/', 'admin-notice', 'BlackFriday25-presale', false ) ) . '">' . esc_html__( 'Ask a Pre-Sale Question', 'accessibility-checker' ) . '</a> ';
4✔
132
                $message .= '<a class="button button-primary" href="' . esc_url( edac_link_wrapper( 'https://equalizedigital.com/accessibility-checker/pricing/', 'admin-notice', 'BlackFriday25-pricing', false ) ) . '">' . esc_html__( 'Upgrade Now', 'accessibility-checker' ) . '</a></p>';
4✔
133
                $message .= '</div>';
4✔
134

135
                return $message;
4✔
136
        }
137

138
        /**
139
         * Black Friday Admin Notice Ajax
140
         *
141
         * @return void
142
         *
143
         *  - '-1' means that nonce could not be varified
144
         *  - '-2' means that update option wasn't successful
145
         */
146
        public function edac_black_friday_notice_ajax() {
147

148
                // nonce security.
149
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
150

151
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
152
                        wp_send_json_error( $error );
×
153

154
                }
155

NEW
156
                $results = update_option( 'edac_black_friday_2025_notice_dismiss', true );
×
157
                // Delete old options if they exist.
NEW
158
                delete_option( 'edac_black_friday_2024_notice_dismiss' );
×
NEW
159
                delete_option( 'edac_black_friday_2023_notice_dismiss' );
×
160

161
                if ( ! $results ) {
×
162

163
                        $error = new \WP_Error( '-2', __( 'Update option wasn\'t successful', 'accessibility-checker' ) );
×
164
                        wp_send_json_error( $error );
×
165

166
                }
167

168
                wp_send_json_success( wp_json_encode( $results ) );
×
169
        }
170

171
        /**
172
         * GAAD Notice
173
         *
174
         * @return void
175
         */
176
        public function edac_gaad_notice() {
177

178
                // Define constants for start and end dates.
179
                define( 'EDAC_GAAD_NOTICE_START_DATE', '2025-05-13' );
×
180
                define( 'EDAC_GAAD_NOTICE_END_DATE', '2025-05-21' );
×
181

182
                // Check if Accessibility Checker Pro is active.
183
                if ( defined( 'EDACP_VERSION' ) ) {
×
184
                        return;
×
185
                }
186

187
                // Get the value of the 'edac_gaad_notice_dismiss' option and sanitize it.
188
                $dismissed = absint( get_option( 'edac_gaad_notice_dismiss_2025', 0 ) );
×
189

190
                // Check if the notice has been dismissed.
191
                if ( $dismissed ) {
×
192
                        return;
×
193
                }
194

195
                // Get the current date in the 'Y-m-d' format.
196
                $current_date = gmdate( 'Y-m-d' );
×
197

198
                // Check if the current date is within the specified range.
199
                if ( $current_date >= EDAC_GAAD_NOTICE_START_DATE && $current_date <= EDAC_GAAD_NOTICE_END_DATE ) {
×
200

201
                        // Get the promotional message from a separate function/file.
202
                        $message = $this->edac_get_gaad_promo_message();
×
203

204
                        // Output the message with appropriate sanitization.
205
                        echo wp_kses_post( $message );
×
206

207
                }
208
        }
209

210
        /**
211
         * Get GAAD Promo Message
212
         *
213
         * @return string
214
         */
215
        public function edac_get_gaad_promo_message() {
216

217
                // Construct the promotional message.
218
                $message  = '<div class="edac_gaad_notice notice notice-info is-dismissible">';
4✔
219
                $message .= '<p><strong>' . esc_html__( '🎉 Get 25% off Accessibility Checker Pro in honor of Global Accessibility Awareness Day! 🎉', 'accessibility-checker' ) . '</strong><br />';
4✔
220
                $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✔
221
                $message .= '<a class="button button-primary" href="' . esc_url( edac_link_wrapper( 'https://equalizedigital.com/contact/', 'admin-notice', 'GAAD25-presale', false ) ) . '">' . esc_html__( 'Ask a Pre-Sale Question', 'accessibility-checker' ) . '</a> ';
4✔
222
                $message .= '<a class="button button-primary" href="' . esc_url( edac_link_wrapper( 'https://equalizedigital.com/accessibility-checker/pricing/', 'admin-notice', 'GAAD25-pricing', false ) ) . '">' . esc_html__( 'Upgrade Now', 'accessibility-checker' ) . '</a></p>';
4✔
223
                $message .= '</div>';
4✔
224

225
                return $message;
4✔
226
        }
227

228
        /**
229
         * GAAD Admin Notice Ajax
230
         *
231
         * @return void
232
         *
233
         *  - '-1' means that nonce could not be varified
234
         *  - '-2' means that update option wasn't successful
235
         */
236
        public function edac_gaad_notice_ajax() {
237

238
                // nonce security.
239
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
240

241
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
242
                        wp_send_json_error( $error );
×
243

244
                }
245

246
                $results = update_option( 'edac_gaad_notice_dismiss_2025', true );
×
247
                // Delete old meta keys if they exist.
248
                delete_option( 'edac_gaad_notice_dismiss_2024' );
×
249
                delete_option( 'edac_gaad_notice_dismiss' );
×
250

251
                if ( ! $results ) {
×
252

253
                        $error = new \WP_Error( '-2', __( 'Update option wasn\'t successful', 'accessibility-checker' ) );
×
254
                        wp_send_json_error( $error );
×
255

256
                }
257

258
                wp_send_json_success( wp_json_encode( $results ) );
×
259
        }
260

261
        /**
262
         * Review Admin Notice
263
         *
264
         * @return void
265
         */
266
        public function edac_review_notice() {
267

268
                $option             = 'edac_review_notice';
×
269
                $edac_review_notice = get_option( $option );
×
270

271
                // exit if option is set to stop.
272
                if ( 'stop' === $edac_review_notice ) {
×
273
                        return;
×
274
                }
275

276
                $transient                   = 'edac_review_notice_reminder';
×
277
                $edac_review_notice_reminder = get_transient( $transient );
×
278

279
                // first time if notice has never been shown wait 14 days.
280
                if ( false === $edac_review_notice_reminder && empty( $edac_review_notice ) ) {
×
281
                        // if option isn't set and plugin has been active for more than 14 days show notice. This is for current users.
282
                        if ( edac_days_active() > 14 ) {
×
283
                                update_option( $option, 'play' );
×
284
                        } else {
285
                                // if plugin has been active less than 14 days set transient for 14 days.
286
                                set_transient( $transient, true, 14 * DAY_IN_SECONDS );
×
287
                                // set option to pause.
288
                                update_option( $option, 'pause' );
×
289
                        }
290
                }
291

292
                // if transient has expired and option is set to pause update option to play.
293
                if ( false === $edac_review_notice_reminder && 'pause' === $edac_review_notice ) {
×
294
                        update_option( $option, 'play' );
×
295
                }
296

297
                // if option is not set to play exit.
298
                if ( get_option( $option ) !== 'play' ) {
×
299
                        return;
×
300
                }
301

302
                ?>
303
                <div class="notice notice-info edac-review-notice">
×
304
                        <p>
×
305
                                <?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' ); ?>
×
306
                        </p>
×
307
                        <p>
×
308
                                <button class="edac-review-notice-review button button-small button-primary"><?php esc_html_e( 'Write A Review', 'accessibility-checker' ); ?></button>
×
309
                                <button class="edac-review-notice-remind button button-small"><?php esc_html_e( 'Remind Me In Two Weeks', 'accessibility-checker' ); ?></button>
×
310
                                <button class="edac-review-notice-dismiss button button-small"><?php esc_html_e( 'Never Ask Again', 'accessibility-checker' ); ?></button>
×
311
                        </p>
312
                </div>
313
                <?php
314
        }
315

316
        /**
317
         * Review Admin Notice Ajax
318
         *
319
         * @return void
320
         *
321
         *  - '-1' means that nonce could not be varified
322
         *  - '-2' means that the review action value was not specified
323
         *  - '-3' means that update option wasn't successful
324
         */
325
        public function edac_review_notice_ajax() {
326

327
                // nonce security.
328
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
329

330
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
331
                        wp_send_json_error( $error );
×
332

333
                }
334

335
                if ( ! isset( $_REQUEST['review_action'] ) ) {
×
336

337
                        $error = new \WP_Error( '-2', __( 'The review action value was not set', 'accessibility-checker' ) );
×
338
                        wp_send_json_error( $error );
×
339

340
                }
341

342
                $review_action = sanitize_text_field( wp_unslash( $_REQUEST['review_action'] ) );
×
343
                $results       = update_option( 'edac_review_notice', $review_action );
×
344
                if ( ! $results ) {
×
345
                        $results = get_option( 'edac_review_notice' ) === $review_action;
×
346
                }
347

348
                if ( 'pause' === $review_action ) {
×
349
                        set_transient( 'edac_review_notice_reminder', true, 14 * DAY_IN_SECONDS );
×
350
                }
351

352
                if ( ! $results ) {
×
353

354
                        $error = new \WP_Error( '-3', __( 'Update option wasn\'t successful', 'accessibility-checker' ) );
×
355
                        wp_send_json_error( $error );
×
356

357
                }
358

359
                wp_send_json_success( wp_json_encode( $results ) );
×
360
        }
361

362

363
        /**
364
         * Save a transient to indicate that the fixes settings have been updated.
365
         *
366
         * @param string $option    The option name that was saved.
367
         *
368
         * @return void
369
         */
370
        public function set_fixes_transient_on_save( $option ) {
371
                if ( ! class_exists( 'EqualizeDigital\AccessibilityChecker\Fixes\FixesManager' ) ) {
×
372
                        return;
×
373
                }
374
                $fixes_settings = FixesManager::get_instance()->get_fixes_settings();
×
375
                $options_keys   = [];
×
376
                foreach ( $fixes_settings as $fix ) {
×
377
                        $options_keys = array_merge( $options_keys, array_keys( $fix['fields'] ) );
×
378
                }
379
                if ( in_array( $option, $options_keys, true ) ) {
×
380
                        // Set a custom transient as a flag.
381
                        set_transient( 'edac_fixes_settings_saved', true, 60 );
×
382
                }
383
        }
384
}
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