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

Yoast / wordpress-seo / 19a970a13fef7ba40bbb159d0746dc885fad816a

20 Oct 2025 12:21PM UTC coverage: 52.78% (-0.5%) from 53.242%
19a970a13fef7ba40bbb159d0746dc885fad816a

Pull #22661

github

web-flow
Merge 4d12ad357 into 631b55e6a
Pull Request #22661: Revert notifying other admins of Yoast SEO

8150 of 15277 branches covered (53.35%)

Branch coverage included in aggregate %.

31468 of 59786 relevant lines covered (52.63%)

39945.84 hits per line

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

0.0
/src/alerts/application/ping-other-admins/ping-other-admins-alert.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3
namespace Yoast\WP\SEO\Alerts\Application\Ping_Other_Admins;
4

5
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
6
use Yoast\WP\SEO\Helpers\Options_Helper;
7
use Yoast\WP\SEO\Helpers\Product_Helper;
8
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
9
use Yoast\WP\SEO\Helpers\User_Helper;
10
use Yoast\WP\SEO\Integrations\Integration_Interface;
11
use Yoast_Notification;
12
use Yoast_Notification_Center;
13

14
/**
15
 * Ping_Other_Admins_Alert class.
16
 */
17
class Ping_Other_Admins_Alert implements Integration_Interface {
18

19
        public const NOTIFICATION_ID = 'wpseo-ping-other-admins';
20

21
        /**
22
         * The notifications center.
23
         *
24
         * @var Yoast_Notification_Center
25
         */
26
        private $notification_center;
27

28
        /**
29
         * The short link helper.
30
         *
31
         * @var Short_Link_Helper
32
         */
33
        private $short_link_helper;
34

35
        /**
36
         * The product helper.
37
         *
38
         * @var Product_Helper
39
         */
40
        private $product_helper;
41

42
        /**
43
         * The options helper.
44
         *
45
         * @var Options_Helper
46
         */
47
        private $options_helper;
48

49
        /**
50
         * The user helper.
51
         *
52
         * @var User_Helper
53
         */
54
        private $user_helper;
55

56
        /**
57
         * Ping_Other_Admins_Alert constructor.
58
         *
59
         * @param Yoast_Notification_Center $notification_center The notification center.
60
         * @param Short_Link_Helper         $short_link_helper   The short link helper.
61
         * @param Product_Helper            $product_helper      The product helper.
62
         * @param Options_Helper            $options_helper      The options helper.
63
         * @param User_Helper               $user_helper         The user helper.
64
         */
65
        public function __construct(
×
66
                Yoast_Notification_Center $notification_center,
67
                Short_Link_Helper $short_link_helper,
68
                Product_Helper $product_helper,
69
                Options_Helper $options_helper,
70
                User_Helper $user_helper
71
        ) {
72
                $this->notification_center = $notification_center;
×
73
                $this->short_link_helper   = $short_link_helper;
×
74
                $this->product_helper      = $product_helper;
×
75
                $this->options_helper      = $options_helper;
×
76
                $this->user_helper         = $user_helper;
×
77
        }
78

79
        /**
80
         * Returns the conditionals based on which this loadable should be active.
81
         *
82
         * @return array<string>
83
         */
84
        public static function get_conditionals() {
×
85
                return [ Admin_Conditional::class ];
×
86
        }
87

88
        /**
89
         * Initializes the integration.
90
         *
91
         * @return void
92
         */
93
        public function register_hooks() {
×
94
                // @phpcs:ignore Squiz.PHP.CommentedOutCode.Found, Squiz.Commenting.InlineComment.InvalidEndChar -- we're gonna postpone this notification until we're actually ready for it.
95
                // \add_action( 'admin_init', [ $this, 'add_notifications' ] );
96
        }
×
97

98
        /**
99
         * Adds notification when user has not installed Yoast SEO themselves and has not resolved the notification yet.
100
         *
101
         * @return void
102
         */
103
        public function add_notifications() {
×
104
                if ( $this->has_user_installed_yoast() ) {
×
105
                        $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
×
106
                        return;
×
107
                }
108

109
                if ( $this->has_notification_been_resolved() ) {
×
110
                        $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
×
111
                        return;
×
112
                }
113

114
                $notification = $this->get_ping_other_admins_notification();
×
115

116
                $this->notification_center->add_notification( $notification );
×
117
        }
118

119
        /**
120
         * Returns whether user has installed Yoast SEO themselves.
121
         *
122
         * @return bool Whether the user has installed Yoast SEO themselves.
123
         */
124
        private function has_user_installed_yoast(): bool {
×
125
                $first_activated_by = $this->options_helper->get( 'first_activated_by', 0 );
×
126

127
                if ( $first_activated_by === 0 ) {
×
128
                        return true; // We cannot be sure, so we assume they did.
×
129
                }
130

131
                if ( \get_current_user_id() === $first_activated_by ) {
×
132
                        return true;
×
133
                }
134

135
                return false;
×
136
        }
137

138
        /**
139
         * Returns whether the alert has been resolved before.
140
         *
141
         * @return bool Whether the alert has been resolved before.
142
         */
143
        private function has_notification_been_resolved(): bool {
×
144
                return $this->user_helper->get_meta( \get_current_user_id(), self::NOTIFICATION_ID . '_resolved', true ) === '1';
×
145
        }
146

147
        /**
148
         * Build the ping-other-admins notification.
149
         *
150
         * @return Yoast_Notification The ping-other-admins notification.
151
         */
152
        private function get_ping_other_admins_notification(): Yoast_Notification {
×
153
                $message = $this->get_message();
×
154

155
                return new Yoast_Notification(
×
156
                        $message,
×
157
                        [
×
158
                                'id'           => self::NOTIFICATION_ID,
×
159
                                'type'         => Yoast_Notification::WARNING,
×
160
                                'capabilities' => [ 'wpseo_manage_options' ],
×
161
                                'priority'     => 20,
×
162
                        ]
×
163
                );
×
164
        }
165

166
        /**
167
         * Returns the notification as an HTML string.
168
         *
169
         * @return string The HTML string representation of the notification.
170
         */
171
        private function get_message() {
×
172
                $shortlink = $this->short_link_helper->get( 'https://yoa.st/new-admin-newsletter-sign-up/' );
×
173

174
                $message = \sprintf(
×
175
                        /* translators: %1$s and %3$s expands to "Yoast SEO" , %2$s expands to an opening link tag, %4$s expands to a closing link tag. */
176
                        \esc_html__( 'Looks like you’re new here. %1$s makes it easy to optimize your website for search engines. Want to keep your site healthy and easier to find? %2$sSign up for the %3$s newsletter for short, practical weekly tips%4$s.', 'wordpress-seo' ),
×
177
                        'Yoast SEO',
×
178
                        '<a href="' . \esc_url( $shortlink ) . '" target="_blank">',
×
179
                        'Yoast SEO',
×
180
                        '</a>'
×
181
                );
×
182

183
                $notification_text  = '<p>' . $message . '</p>';
×
184
                $notification_text .= '<a class="button wpseo-resolve-alert" href="#" data-alert-id="' . \esc_attr( self::NOTIFICATION_ID ) . '" data-nonce="' . \esc_attr( \wp_create_nonce( 'wpseo-resolve-alert-nonce' ) ) . '">';
×
185
                $notification_text .= \esc_html__( 'Dismiss', 'wordpress-seo' );
×
186
                $notification_text .= '</a>';
×
187

188
                return $notification_text;
×
189
        }
190
}
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