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

equalizedigital / accessibility-checker / 17830224702

18 Sep 2025 01:26PM UTC coverage: 59.387%. First build
17830224702

Pull #1236

github

web-flow
Merge f9edada56 into 7b5a0cf76
Pull Request #1236: Release v1.32.0

15 of 18 new or added lines in 2 files covered. (83.33%)

4144 of 6978 relevant lines covered (59.39%)

3.55 hits per line

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

17.36
/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.
100
                if ( absint( get_option( 'edac_black_friday_2024_notice_dismiss', 0 ) ) ) {
×
101
                        return;
×
102
                }
103

104
                // Show from November 25 to December 03.
105
                $current_date = date_i18n( 'Ymd' ); // Use date_i18n for localization.
×
106
                $start_date   = '20241125';
×
107
                $end_date     = '20241203';
×
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 25th 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', 'BF2025-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', 'BF2025-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

156
                $results = update_option( 'edac_black_friday_2024_notice_dismiss', true );
×
157

158
                if ( ! $results ) {
×
159

160
                        $error = new \WP_Error( '-2', __( 'Update option wasn\'t successful', 'accessibility-checker' ) );
×
161
                        wp_send_json_error( $error );
×
162

163
                }
164

165
                wp_send_json_success( wp_json_encode( $results ) );
×
166
        }
167

168
        /**
169
         * GAAD Notice
170
         *
171
         * @return void
172
         */
173
        public function edac_gaad_notice() {
174

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

179
                // Check if Accessibility Checker Pro is active.
180
                if ( defined( 'EDACP_VERSION' ) ) {
×
181
                        return;
×
182
                }
183

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

187
                // Check if the notice has been dismissed.
188
                if ( $dismissed ) {
×
189
                        return;
×
190
                }
191

192
                // Get the current date in the 'Y-m-d' format.
193
                $current_date = gmdate( 'Y-m-d' );
×
194

195
                // Check if the current date is within the specified range.
196
                if ( $current_date >= EDAC_GAAD_NOTICE_START_DATE && $current_date <= EDAC_GAAD_NOTICE_END_DATE ) {
×
197

198
                        // Get the promotional message from a separate function/file.
199
                        $message = $this->edac_get_gaad_promo_message();
×
200

201
                        // Output the message with appropriate sanitization.
202
                        echo wp_kses_post( $message );
×
203

204
                }
205
        }
206

207
        /**
208
         * Get GAAD Promo Message
209
         *
210
         * @return string
211
         */
212
        public function edac_get_gaad_promo_message() {
213

214
                // Construct the promotional message.
215
                $message  = '<div class="edac_gaad_notice notice notice-info is-dismissible">';
4✔
216
                $message .= '<p><strong>' . esc_html__( '🎉 Get 25% off Accessibility Checker Pro in honor of Global Accessibility Awareness Day! 🎉', 'accessibility-checker' ) . '</strong><br />';
4✔
217
                $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✔
218
                $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✔
219
                $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✔
220
                $message .= '</div>';
4✔
221

222
                return $message;
4✔
223
        }
224

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

235
                // nonce security.
236
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
237

238
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
239
                        wp_send_json_error( $error );
×
240

241
                }
242

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

248
                if ( ! $results ) {
×
249

250
                        $error = new \WP_Error( '-2', __( 'Update option wasn\'t successful', 'accessibility-checker' ) );
×
251
                        wp_send_json_error( $error );
×
252

253
                }
254

255
                wp_send_json_success( wp_json_encode( $results ) );
×
256
        }
257

258
        /**
259
         * Review Admin Notice
260
         *
261
         * @return void
262
         */
263
        public function edac_review_notice() {
264

265
                $option             = 'edac_review_notice';
×
266
                $edac_review_notice = get_option( $option );
×
267

268
                // exit if option is set to stop.
269
                if ( 'stop' === $edac_review_notice ) {
×
270
                        return;
×
271
                }
272

273
                $transient                   = 'edac_review_notice_reminder';
×
274
                $edac_review_notice_reminder = get_transient( $transient );
×
275

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

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

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

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

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

324
                // nonce security.
325
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
326

327
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
328
                        wp_send_json_error( $error );
×
329

330
                }
331

332
                if ( ! isset( $_REQUEST['review_action'] ) ) {
×
333

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

337
                }
338

NEW
339
                $review_action = sanitize_text_field( wp_unslash( $_REQUEST['review_action'] ) );
×
NEW
340
                $results       = update_option( 'edac_review_notice', $review_action );
×
341

NEW
342
                if ( 'pause' === $review_action ) {
×
343
                        set_transient( 'edac_review_notice_reminder', true, 14 * DAY_IN_SECONDS );
×
344
                }
345

346
                if ( ! $results ) {
×
347

348
                        $error = new \WP_Error( '-3', __( 'Update option wasn\'t successful', 'accessibility-checker' ) );
×
349
                        wp_send_json_error( $error );
×
350

351
                }
352

353
                wp_send_json_success( wp_json_encode( $results ) );
×
354
        }
355

356

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