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

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

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

0.0
/admin/notifiers/dismissible-notification.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Notifiers
6
 */
7

8
/**
9
 * Abstract class representing a dismissible notification.
10
 */
11
abstract class WPSEO_Dismissible_Notification implements WPSEO_Listener, WPSEO_Notification_Handler {
12

13
        /**
14
         * The identifier for the notification.
15
         *
16
         * @var string
17
         */
18
        protected $notification_identifier = '';
19

20
        /**
21
         * Retrieves instance of a notification.
22
         *
23
         * @return Yoast_Notification The notification.
24
         */
25
        abstract protected function get_notification();
26

27
        /**
28
         * Listens to an argument in the request URL and triggers an action.
29
         *
30
         * @return void
31
         */
UNCOV
32
        public function listen() {
×
UNCOV
33
                if ( $this->get_listener_value() !== $this->notification_identifier ) {
×
UNCOV
34
                        return;
×
35
                }
36

UNCOV
37
                $this->dismiss();
×
38
        }
39

40
        /**
41
         * Adds the notification if applicable, otherwise removes it.
42
         *
43
         * @param Yoast_Notification_Center $notification_center The notification center object.
44
         *
45
         * @return void
46
         */
UNCOV
47
        public function handle( Yoast_Notification_Center $notification_center ) {
×
UNCOV
48
                if ( $this->is_applicable() ) {
×
UNCOV
49
                        $notification = $this->get_notification();
×
UNCOV
50
                        $notification_center->add_notification( $notification );
×
51

UNCOV
52
                        return;
×
53
                }
54

UNCOV
55
                $notification_center->remove_notification_by_id( 'wpseo-' . $this->notification_identifier );
×
56
        }
57

58
        /**
59
         * Listens to an argument in the request URL and triggers an action.
60
         *
61
         * @return void
62
         */
UNCOV
63
        protected function dismiss() {
×
UNCOV
64
                $this->set_dismissal_state();
×
UNCOV
65
                $this->redirect_to_dashboard();
×
66
        }
67

68
        /**
69
         * Checks if a notice is applicable.
70
         *
71
         * @return bool Whether a notice should be shown or not.
72
         */
UNCOV
73
        protected function is_applicable() {
×
UNCOV
74
                return $this->is_notice_dismissed() === false;
×
75
        }
76

77
        /**
78
         * Checks whether the notification has been dismissed.
79
         *
80
         * @codeCoverageIgnore
81
         *
82
         * @return bool True when notification is dismissed.
83
         */
84
        protected function is_notice_dismissed() {
85
                return get_user_meta( get_current_user_id(), 'wpseo-remove-' . $this->notification_identifier, true ) === '1';
86
        }
87

88
        /**
89
         * Retrieves the value where listener is listening for.
90
         *
91
         * @codeCoverageIgnore
92
         *
93
         * @return string|null The listener value or null if not set.
94
         */
95
        protected function get_listener_value() {
96
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: Normally we would need to check for a nonce here but this class is not used anymore.
97
                if ( isset( $_GET['yoast_dismiss'] ) && is_string( $_GET['yoast_dismiss'] ) ) {
98
                        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: Normally we would need to check for a nonce here but this class is not used anymore.
99
                        return sanitize_text_field( wp_unslash( $_GET['yoast_dismiss'] ) );
100
                }
101
                return null;
102
        }
103

104
        /**
105
         * Dismisses the notification.
106
         *
107
         * @codeCoverageIgnore
108
         *
109
         * @return void
110
         */
111
        protected function set_dismissal_state() {
112
                update_user_meta( get_current_user_id(), 'wpseo-remove-' . $this->notification_identifier, true );
113
        }
114

115
        /**
116
         * Redirects the user back to the dashboard.
117
         *
118
         * @codeCoverageIgnore
119
         *
120
         * @return void
121
         */
122
        protected function redirect_to_dashboard() {
123
                wp_safe_redirect( admin_url( 'admin.php?page=wpseo_dashboard' ) );
124
                exit;
125
        }
126
}
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