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

equalizedigital / accessibility-checker / 13163549850

05 Feb 2025 05:55PM UTC coverage: 24.736%. First build
13163549850

Pull #850

github

web-flow
Merge 9a27bde64 into bb25d453d
Pull Request #850: Release v1.20.0

4 of 14 new or added lines in 5 files covered. (28.57%)

1755 of 7095 relevant lines covered (24.74%)

5.54 hits per line

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

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

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

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

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

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

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

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

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

96
                // check if accessibility checker pro is active.
97
                if ( is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' ) ) {
×
98
                        return;
×
99
                }
100

101
                // Check if the notice has been dismissed.
102
                if ( absint( get_option( 'edac_black_friday_2024_notice_dismiss', 0 ) ) ) {
×
103
                        return;
×
104
                }
105

106
                // Show from November 25 to December 03.
107
                $current_date = date_i18n( 'Ymd' ); // Use date_i18n for localization.
×
108
                $start_date   = '20241125';
×
109
                $end_date     = '20241203';
×
110

111
                if ( $current_date >= $start_date && $current_date <= $end_date ) {
×
112

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

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

119
                }
120
        }
121

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

129
                // Construct the promotional message.
130
                $message  = '<div class="edac_black_friday_notice notice notice-info is-dismissible">';
4✔
131
                $message .= '<p><strong>' . esc_html__( '🎉 Black Friday special! 🎉', 'accessibility-checker' ) . '</strong><br />';
4✔
132
                $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✔
133
                $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✔
134
                $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✔
135
                $message .= '</div>';
4✔
136

137
                return $message;
4✔
138
        }
139

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

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

153
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
154
                        wp_send_json_error( $error );
×
155

156
                }
157

158
                $results = update_option( 'edac_black_friday_2024_notice_dismiss', true );
×
159

160
                if ( ! $results ) {
×
161

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

165
                }
166

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

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

177
                // Define constants for start and end dates.
178
                define( 'EDAC_GAAD_NOTICE_START_DATE', '2024-05-16' );
×
179
                define( 'EDAC_GAAD_NOTICE_END_DATE', '2024-05-23' );
×
180

181
                // Check if Accessibility Checker Pro is active.
182
                $pro = is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' );
×
183
                if ( $pro ) {
×
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_2024', 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 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✔
221
                $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✔
222
                $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✔
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' );
×
242
                        wp_send_json_error( $error );
×
243

244
                }
245

246
                $results = update_option( 'edac_gaad_notice_dismiss_2024', true );
×
247
                // delete old meta key.
248
                delete_option( 'edac_gaad_notice_dismiss' );
×
249

250
                if ( ! $results ) {
×
251

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

255
                }
256

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

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

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

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

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

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

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

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

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

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

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

329
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
330
                        wp_send_json_error( $error );
×
331

332
                }
333

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

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

339
                }
340

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

343
                if ( 'pause' === $_REQUEST['review_action'] ) {
×
344
                        set_transient( 'edac_review_notice_reminder', true, 14 * DAY_IN_SECONDS );
×
345
                }
346

347
                if ( ! $results ) {
×
348

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

352
                }
353

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

357
        /**
358
         * Password Protected Notice Text
359
         *
360
         * @return string
361
         */
362
        public function edac_password_protected_notice_text() {
363
                /**
364
                 * Filter the password protected notice text.
365
                 *
366
                 * @since 1.4.0
367
                 *
368
                 * @param string $text The password protected notice text.
369
                 */
370
                return apply_filters(
4✔
371
                        'edac_filter_password_protected_notice_text',
4✔
372
                        sprintf(
4✔
373
                                // translators: %s is the link to upgrade to pro, with "upgrade to pro" as the anchor text.
374
                                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✔
375
                                sprintf(
4✔
376
                                        '<a href="https://equalizedigital.com/accessibility-checker/pricing/" target="_blank" aria-label="%1$s">%2$s</a>',
4✔
377
                                        esc_attr__( 'Upgrade to accessibility checker pro. Opens in a new window.', 'accessibility-checker' ),
4✔
378
                                        esc_html__( 'upgrade to pro', 'accessibility-checker' )
4✔
379
                                )
4✔
380
                        )
4✔
381
                );
4✔
382
        }
383

384
        /**
385
         * Password Protected Notice
386
         *
387
         * @return string
388
         */
389
        public function edac_password_protected_notice() {
390
                if ( (bool) get_option( 'edac_password_protected' )
×
391
                        && ! (bool) get_option( 'edac_password_protected_notice_dismiss' )
×
392
                ) {
393
                        echo wp_kses( '<div class="edac_password_protected_notice notice notice-error is-dismissible"><p>' . $this->edac_password_protected_notice_text() . '</p></div>', 'post' );
×
394
                        return;
×
395
                }
396
        }
397

398
        /**
399
         * Password Protected Admin Notice Ajax
400
         *
401
         * @return void
402
         *
403
         *  - '-1' means that nonce could not be varified
404
         *  - '-2' means that update option wasn't successful
405
         */
406
        public function edac_password_protected_notice_ajax() {
407

408
                // nonce security.
409
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
410

411
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
412
                        wp_send_json_error( $error );
×
413

414
                }
415

416
                $results = update_option( 'edac_password_protected_notice_dismiss', true );
×
417

418
                if ( ! $results ) {
×
419

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

423
                }
424

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

428
        /**
429
         * Save a transient to indicate that the fixes settings have been updated.
430
         *
431
         * @param string $option    The option name that was saved.
432
         *
433
         * @return void
434
         */
435
        public function set_fixes_transient_on_save( $option ) {
436
                if ( ! class_exists( 'EqualizeDigital\AccessibilityChecker\Fixes\FixesManager' ) ) {
×
437
                        return;
×
438
                }
439
                $fixes_settings = FixesManager::get_instance()->get_fixes_settings();
×
440
                $options_keys   = [];
×
441
                foreach ( $fixes_settings as $fix ) {
×
442
                        $options_keys = array_merge( $options_keys, array_keys( $fix['fields'] ) );
×
443
                }
444
                if ( in_array( $option, $options_keys, true ) ) {
×
445
                        // Set a custom transient as a flag.
446
                        set_transient( 'edac_fixes_settings_saved', true, 60 );
×
447
                }
448
        }
449
}
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