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

Yoast / wordpress-seo / 49cdf70e861509c37a279de77f1105ee59c0f57f

20 Feb 2024 09:17AM UTC coverage: 53.172%. First build
49cdf70e861509c37a279de77f1105ee59c0f57f

push

github

YoastBot
Bump version to 22.1 on free

7564 of 13903 branches covered (54.41%)

Branch coverage included in aggregate %.

29067 of 54988 relevant lines covered (52.86%)

40245.15 hits per line

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

0.0
/admin/ajax/class-yoast-dismissable-notice.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Ajax
6
 */
7

8
/**
9
 * This class will catch the request to dismiss the target notice (set by notice_name)
10
 * and will store the dismiss status as an user meta in the database.
11
 */
12
class Yoast_Dismissable_Notice_Ajax {
13

14
        /**
15
         * Notice type toggle value for user notices.
16
         *
17
         * @var string
18
         */
19
        public const FOR_USER = 'user_meta';
20

21
        /**
22
         * Notice type toggle value for network notices.
23
         *
24
         * @var string
25
         */
26
        public const FOR_NETWORK = 'site_option';
27

28
        /**
29
         * Notice type toggle value for site notices.
30
         *
31
         * @var string
32
         */
33
        public const FOR_SITE = 'option';
34

35
        /**
36
         * Name of the notice that will be dismissed.
37
         *
38
         * @var string
39
         */
40
        private $notice_name;
41

42
        /**
43
         * The type of the current notice.
44
         *
45
         * @var string
46
         */
47
        private $notice_type;
48

49
        /**
50
         * Initialize the hooks for the AJAX request.
51
         *
52
         * @param string $notice_name The name for the hook to catch the notice.
53
         * @param string $notice_type The notice type.
54
         */
55
        public function __construct( $notice_name, $notice_type = self::FOR_USER ) {
×
56
                $this->notice_name = $notice_name;
×
57
                $this->notice_type = $notice_type;
×
58

59
                add_action( 'wp_ajax_wpseo_dismiss_' . $notice_name, [ $this, 'dismiss_notice' ] );
×
60
        }
61

62
        /**
63
         * Handles the dismiss notice request.
64
         *
65
         * @return void
66
         */
67
        public function dismiss_notice() {
×
68
                check_ajax_referer( 'wpseo-dismiss-' . $this->notice_name );
×
69

70
                $this->save_dismissed();
×
71

72
                wp_die( 'true' );
×
73
        }
74

75
        /**
76
         * Storing the dismissed value in the database. The target location is based on the set notification type.
77
         *
78
         * @return void
79
         */
80
        private function save_dismissed() {
×
81
                if ( $this->notice_type === self::FOR_SITE ) {
×
82
                        update_option( 'wpseo_dismiss_' . $this->notice_name, 1 );
×
83

84
                        return;
×
85
                }
86

87
                if ( $this->notice_type === self::FOR_NETWORK ) {
×
88
                        update_site_option( 'wpseo_dismiss_' . $this->notice_name, 1 );
×
89

90
                        return;
×
91
                }
92

93
                update_user_meta( get_current_user_id(), 'wpseo_dismiss_' . $this->notice_name, 1 );
×
94
        }
95
}
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

© 2025 Coveralls, Inc