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

equalizedigital / accessibility-checker / 13016226847

28 Jan 2025 05:35PM UTC coverage: 24.679%. First build
13016226847

Pull #843

github

web-flow
Merge 5b76a47bb into 96c2059cd
Pull Request #843: Release v1.19.0

2 of 28 new or added lines in 5 files covered. (7.14%)

1751 of 7095 relevant lines covered (24.68%)

5.54 hits per line

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

20.0
/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
                add_action( 'updated_option', [ $this, 'set_fixes_transient_on_save' ] );
2✔
33
        }
34

35
        /**
36
         * Hook Notices
37
         *
38
         * @since 1.9.3
39
         *
40
         * @return void
41
         */
42
        public function hook_notices() {
43
                if ( ! Helpers::current_user_can_see_widgets_and_notices() ) {
×
44
                        return;
×
45
                }
46

47
                add_action( 'admin_notices', [ $this, 'edac_black_friday_notice' ] );
×
48
                add_action( 'wp_ajax_edac_black_friday_notice_ajax', [ $this, 'edac_black_friday_notice_ajax' ] );
×
49
                add_action( 'admin_notices', [ $this, 'edac_gaad_notice' ] );
×
50
                add_action( 'wp_ajax_edac_gaad_notice_ajax', [ $this, 'edac_gaad_notice_ajax' ] );
×
51
                add_action( 'admin_notices', [ $this, 'edac_review_notice' ] );
×
52
                add_action( 'wp_ajax_edac_review_notice_ajax', [ $this, 'edac_review_notice_ajax' ] );
×
53
                add_action( 'admin_notices', [ $this, 'edac_password_protected_notice' ] );
×
54
                add_action( 'wp_ajax_edac_password_protected_notice_ajax', [ $this, 'edac_password_protected_notice_ajax' ] );
×
55
        }
56

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

NEW
64
                $current_screen = get_current_screen();
×
NEW
65
                $screens        = [
×
NEW
66
                        'toplevel_page_accessibility_checker',
×
NEW
67
                        'accessibility-checker_page_accessibility_checker_issues',
×
NEW
68
                        'accessibility-checker_page_accessibility_checker_ignored',
×
NEW
69
                        'accessibility-checker_page_accessibility_checker_settings',
×
NEW
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
                 */
NEW
79
                $screens = apply_filters( 'edac_filter_remove_admin_notices_screens', $screens );
×
80

NEW
81
                if ( in_array( $current_screen->id, $screens, true ) ) {
×
NEW
82
                        remove_all_actions( 'admin_notices' );
×
NEW
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 ( is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' ) ) {
×
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( '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✔
132
                $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✔
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' );
×
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' );
×
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 string
172
         */
173
        public function edac_gaad_notice() {
174

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

179
                // Check if Accessibility Checker Pro is active.
180
                $pro = is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' );
×
181
                if ( $pro ) {
×
182
                        return;
×
183
                }
184

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

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

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

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

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

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

205
                }
206
        }
207

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

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

223
                return $message;
4✔
224
        }
225

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

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

239
                        $error = new \WP_Error( '-1', 'Permission Denied' );
×
240
                        wp_send_json_error( $error );
×
241

242
                }
243

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

248
                if ( ! $results ) {
×
249

250
                        $error = new \WP_Error( '-2', 'Update option wasn\'t successful' );
×
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"><?php esc_html_e( 'Write A Review', 'accessibility-checker' ); ?></button>
×
306
                                <button class="edac-review-notice-remind"><?php esc_html_e( 'Remind Me In Two Weeks', 'accessibility-checker' ); ?></button>
×
307
                                <button class="edac-review-notice-dismiss"><?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' );
×
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' );
×
335
                        wp_send_json_error( $error );
×
336

337
                }
338

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

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

345
                if ( ! $results ) {
×
346

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

350
                }
351

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

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

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

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

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

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

412
                }
413

414
                $results = update_option( 'edac_password_protected_notice_dismiss', true );
×
415

416
                if ( ! $results ) {
×
417

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

421
                }
422

423
                wp_send_json_success( wp_json_encode( $results ) );
×
424
        }
425

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