PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | src/integrations/watchers/auto-update-watcher.php +4 -150 18.0 → trunk View file →
@@ -2,12 +2,9 @@
2 2
3 3 namespace Yoast\WP\SEO\Integrations\Watchers;
4 4
5 5 use Yoast\WP\SEO\Conditionals\No_Conditionals;
6 -use Yoast\WP\SEO\Helpers\Notification_Helper;
7 6 use Yoast\WP\SEO\Integrations\Integration_Interface;
8 -use Yoast\WP\SEO\Presenters\Admin\Auto_Update_Notification_Presenter;
9 -use Yoast_Notification;
10 7 use Yoast_Notification_Center;
11 8
12 9 /**
13 10 * Shows a notification for users who have WordPress auto updates enabled but not Yoast SEO auto updates.
@@ -18,9 +15,9 @@
18 15
19 16 /**
20 17 * The notification ID.
21 18 */
22 - const NOTIFICATION_ID = 'wpseo-auto-update';
19 + public const NOTIFICATION_ID = 'wpseo-auto-update';
23 20
24 21 /**
25 22 * The Yoast notification center.
26 23 *
@@ -28,26 +25,14 @@
28 25 */
29 26 protected $notification_center;
30 27
31 28 /**
32 - * The notification helper.
33 - *
34 - * @var Notification_Helper
35 - */
36 - protected $notification_helper;
37 -
38 - /**
39 29 * Auto_Update constructor.
40 30 *
41 31 * @param Yoast_Notification_Center $notification_center The notification center.
42 - * @param Notification_Helper $notification_helper The notification helper.
43 32 */
44 - public function __construct(
45 - Yoast_Notification_Center $notification_center,
46 - Notification_Helper $notification_helper
47 - ) {
33 + public function __construct( Yoast_Notification_Center $notification_center ) {
48 34 $this->notification_center = $notification_center;
49 - $this->notification_helper = $notification_helper;
50 35 }
51 36
52 37 /**
53 38 * Initializes the integration.
@@ -58,147 +43,16 @@
58 43 *
59 44 * @return void
60 45 */
61 46 public function register_hooks() {
62 - \add_action( 'admin_init', [ $this, 'auto_update_notification_not_if_dismissed' ] );
63 - \add_action( 'update_site_option_auto_update_core_major', [ $this, 'auto_update_notification_even_if_dismissed' ] );
64 - \add_action( 'update_site_option_auto_update_plugins', [ $this, 'auto_update_notification_not_if_dismissed' ] );
47 + \add_action( 'admin_init', [ $this, 'remove_notification' ] );
65 48 }
66 49
67 50 /**
68 - * Handles the Yoast SEO auto-update notification when the user toggles the auto-update setting for WordPress Core.
69 - *
70 - * If it should be shown, this will be done even if the notification has been dismissed in the past.
71 - *
72 - * @return void
73 - */
74 - public function auto_update_notification_even_if_dismissed() {
75 - if ( ! $this->should_show_notification() ) {
76 - $this->save_dismissal_status();
77 - $this->maybe_remove_notification();
78 -
79 - return;
80 - }
81 -
82 - $this->maybe_create_notification();
83 - }
84 -
85 - /**
86 - * Handles the Yoast SEO auto-update notification on all admin pages,
87 - * as well as when the user toggles the Yoast SEO auto-update setting.
88 - *
89 - * If it should be shown, this will only be done if the notification has not been dismissed in the past.
90 - *
91 - * @return void
92 - */
93 - public function auto_update_notification_not_if_dismissed() {
94 - if ( ! $this->should_show_notification() ) {
95 - $this->save_dismissal_status();
96 - $this->maybe_remove_notification();
97 -
98 - return;
99 - }
100 -
101 - $this->maybe_create_notification_if_not_dismissed();
102 - }
103 -
104 - /**
105 - * Checks whether the Yoast SEO auto-update notification should be shown.
106 - *
107 - * @return bool Whether the notification should be shown.
108 - */
109 - protected function should_show_notification() {
110 - $core_updates_enabled = \get_site_option( 'auto_update_core_major' ) === 'enabled';
111 - $yoast_updates_enabled = $this->yoast_auto_updates_enabled();
112 -
113 - return $core_updates_enabled && ! $yoast_updates_enabled;
114 - }
115 -
116 - /**
117 - * Saves the dismissal status of the notification in an option in wp_usermeta, if the notification gets dismissed.
118 - *
119 - * @return void
120 - */
121 - protected function save_dismissal_status() {
122 - // This option exists if the notification has been dismissed at some point.
123 - $notification_dismissed = \get_user_option( 'wp_' . self::NOTIFICATION_ID );
124 -
125 - // We wish to have its value in a different option, so we can still access it even when the notification gets removed.
126 - if ( $notification_dismissed && ! \get_user_option( 'wp_' . self::NOTIFICATION_ID . '_dismissed' ) ) {
127 - \update_user_option( \get_current_user_id(), self::NOTIFICATION_ID . '_dismissed', true );
128 - }
129 - }
130 -
131 - /**
132 51 * Removes the notification from the notification center, if it exists.
133 52 *
134 53 * @return void
135 54 */
136 - protected function maybe_remove_notification() {
55 + public function remove_notification() {
137 56 $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID );
138 - }
139 -
140 - /**
141 - * Creates the notification if it doesn't exist already.
142 - *
143 - * @return void
144 - */
145 - protected function maybe_create_notification() {
146 - if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) {
147 - $notification = $this->notification();
148 - $this->notification_helper->restore_notification( $notification );
149 - $this->notification_center->add_notification( $notification );
150 - }
151 - }
152 -
153 - /**
154 - * Creates the notification when Yoast SEO auto-updates are enabled, if it hasn't been dismissed in the past.
155 - *
156 - * @return void
157 - */
158 - protected function maybe_create_notification_if_not_dismissed() {
159 - $notification_dismissed = \get_user_option( 'wp_' . self::NOTIFICATION_ID . '_dismissed' ) === '1';
160 - $yoast_updates_enabled = $this->yoast_auto_updates_enabled();
161 -
162 - if ( $notification_dismissed && ! $yoast_updates_enabled ) {
163 - return;
164 - }
165 -
166 - $this->maybe_create_notification();
167 - }
168 -
169 - /**
170 - * Checks whether auto-updates are enabled for Yoast SEO.
171 - *
172 - * @return bool True if they are enabled, false if not.
173 - */
174 - protected function yoast_auto_updates_enabled() {
175 - $plugins_to_auto_update = \get_site_option( 'auto_update_plugins' );
176 -
177 - // If no plugins are set to be automatically updated, it means that Yoast SEO isn't either.
178 - if ( ! $plugins_to_auto_update ) {
179 - return false;
180 - }
181 -
182 - // Check if the Yoast SEO plugin file is in the array of plugins for which auto-updates are enabled.
183 - return \in_array( 'wordpress-seo/wp-seo.php', $plugins_to_auto_update, true );
184 - }
185 -
186 - /**
187 - * Returns an instance of the notification.
188 - *
189 - * @return Yoast_Notification The notification to show.
190 - */
191 - protected function notification() {
192 - $presenter = new Auto_Update_Notification_Presenter();
193 -
194 - return new Yoast_Notification(
195 - $presenter->present(),
196 - [
197 - 'type' => Yoast_Notification::WARNING,
198 - 'id' => self::NOTIFICATION_ID,
199 - 'capabilities' => 'wpseo_manage_options',
200 - 'priority' => 0.8,
201 - ]
202 - );
203 57 }
204 58 }