PluginProbe
Authorizer / 3.15.3
Authorizer v3.15.3
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
authorizer / src / authorizer / class-updates.php

class-updates.php in Authorizer 3.15.3, at src/authorizer/class-updates.php

558 lines 25.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Authorizer
4 *
5 * @license GPL-2.0+
6 * @link https://github.com/uhm-coe/authorizer
7 * @package authorizer
8 */
9
10 namespace Authorizer;
11
12 use Authorizer\Helper;
13 use Authorizer\Options;
14
15 /**
16 * Run any database migrations or plugin updates when installing a new version.
17 */
18 class Updates extends Singleton {
19
20 /**
21 * Plugin Update Routines.
22 *
23 * Action: plugins_loaded
24 */
25 public function auth_update_check() {
26 $options = Options::get_instance();
27
28 // Get current version.
29 $needs_updating = false;
30 if ( is_multisite() ) {
31 $auth_version = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_version' );
32 } else {
33 $auth_version = get_option( 'auth_version' );
34 }
35
36 // Update: migrate user lists to own options (addresses concurrency
37 // when saving plugin options, since user lists are changed often
38 // and we don't want to overwrite changes to the lists when an
39 // admin saves all of the plugin options.)
40 // Note: Pending user list is changed whenever a new user tries to
41 // log in; approved and blocked lists are changed whenever an admin
42 // changes them from the multisite panel, the dashboard widget, or
43 // the plugin options page.
44 $update_if_older_than = 20140709;
45 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
46 // Copy single site user lists to new options (if they exist).
47 $auth_settings = get_option( 'auth_settings' );
48 if ( is_array( $auth_settings ) && array_key_exists( 'access_users_pending', $auth_settings ) ) {
49 update_option( 'auth_settings_access_users_pending', $auth_settings['access_users_pending'], false );
50 unset( $auth_settings['access_users_pending'] );
51 update_option( 'auth_settings', $auth_settings, true );
52 }
53 if ( is_array( $auth_settings ) && array_key_exists( 'access_users_approved', $auth_settings ) ) {
54 update_option( 'auth_settings_access_users_approved', $auth_settings['access_users_approved'], false );
55 unset( $auth_settings['access_users_approved'] );
56 update_option( 'auth_settings', $auth_settings, true );
57 }
58 if ( is_array( $auth_settings ) && array_key_exists( 'access_users_blocked', $auth_settings ) ) {
59 update_option( 'auth_settings_access_users_blocked', $auth_settings['access_users_blocked'], false );
60 unset( $auth_settings['access_users_blocked'] );
61 update_option( 'auth_settings', $auth_settings, true );
62 }
63 // Copy multisite user lists to new options (if they exist).
64 if ( is_multisite() ) {
65 $auth_multisite_settings = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', array() );
66 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_pending', $auth_multisite_settings ) ) {
67 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings_access_users_pending', $auth_multisite_settings['access_users_pending'] );
68 unset( $auth_multisite_settings['access_users_pending'] );
69 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings );
70 }
71 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_approved', $auth_multisite_settings ) ) {
72 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings_access_users_approved', $auth_multisite_settings['access_users_approved'] );
73 unset( $auth_multisite_settings['access_users_approved'] );
74 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings );
75 }
76 if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_blocked', $auth_multisite_settings ) ) {
77 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings_access_users_blocked', $auth_multisite_settings['access_users_blocked'] );
78 unset( $auth_multisite_settings['access_users_blocked'] );
79 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings );
80 }
81 }
82 // Update version to reflect this change has been made.
83 $auth_version = $update_if_older_than;
84 $needs_updating = true;
85 }
86
87 // Update: Set default values for newly added options (forgot to do
88 // this, so some users are getting debug log notices about undefined
89 // indexes in $auth_settings).
90 $update_if_older_than = 20160831;
91 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
92 // Provide default values for any $auth_settings options that don't exist.
93 if ( is_multisite() ) {
94 // Get all blog ids.
95 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
96 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
97 foreach ( $sites as $site ) {
98 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
99 switch_to_blog( $blog_id );
100 // Set meaningful defaults for other sites in the network.
101 $options->set_default_options();
102 // Switch back to original blog.
103 restore_current_blog();
104 }
105 } else {
106 // Set meaningful defaults for this site.
107 $options->set_default_options();
108 }
109 // Update version to reflect this change has been made.
110 $auth_version = $update_if_older_than;
111 $needs_updating = true;
112 }
113
114 // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
115 // deprecated as of PHP 7.1. Use openssl library instead.
116 $update_if_older_than = 20170510;
117 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
118 if ( is_multisite() ) {
119 // Reencrypt LDAP passwords in each site in the network.
120 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
121 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
122 foreach ( $sites as $site ) {
123 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
124 $auth_settings = get_blog_option( $blog_id, 'auth_settings', array() );
125 if ( array_key_exists( 'ldap_password', $auth_settings ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
126 $plaintext_ldap_password = Helper::decrypt( $auth_settings['ldap_password'], 'mcrypt' );
127 $auth_settings['ldap_password'] = Helper::encrypt( $plaintext_ldap_password );
128 update_blog_option( $blog_id, 'auth_settings', $auth_settings );
129 }
130 }
131 } else {
132 // Reencrypt LDAP password on this single-site install.
133 $auth_settings = get_option( 'auth_settings', array() );
134 if ( array_key_exists( 'ldap_password', $auth_settings ) && strlen( $auth_settings['ldap_password'] ) > 0 ) {
135 $plaintext_ldap_password = Helper::decrypt( $auth_settings['ldap_password'], 'mcrypt' );
136 $auth_settings['ldap_password'] = Helper::encrypt( $plaintext_ldap_password );
137 update_option( 'auth_settings', $auth_settings, true );
138 }
139 }
140 // Update version to reflect this change has been made.
141 $auth_version = $update_if_older_than;
142 $needs_updating = true;
143 }
144
145 // Update: Migrate LDAP passwords encrypted with mcrypt since mcrypt is
146 // deprecated as of PHP 7.1. Use openssl library instead.
147 // Note: Forgot to update the auth_multisite_settings ldap password! Do it here.
148 $update_if_older_than = 20170511;
149 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
150 if ( is_multisite() ) {
151 // Reencrypt LDAP password in network (multisite) options.
152 $auth_multisite_settings = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', array() );
153 if ( array_key_exists( 'ldap_password', $auth_multisite_settings ) && strlen( $auth_multisite_settings['ldap_password'] ) > 0 ) {
154 $plaintext_ldap_password = Helper::decrypt( $auth_multisite_settings['ldap_password'], 'mcrypt' );
155 $auth_multisite_settings['ldap_password'] = Helper::encrypt( $plaintext_ldap_password );
156 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings );
157 }
158 }
159 // Update version to reflect this change has been made.
160 $auth_version = $update_if_older_than;
161 $needs_updating = true;
162 }
163
164 // Update: Remove duplicates from approved list caused by authorizer_automatically_approve_login
165 // filter not respecting users who are already in the approved list
166 // (causing them to get re-added each time they logged in).
167 $update_if_older_than = 20170711;
168 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
169 // Remove duplicates from approved user lists.
170 if ( is_multisite() ) {
171 // Remove duplicates from each site in the multisite.
172 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
173 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
174 foreach ( $sites as $site ) {
175 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
176 $auth_settings_access_users_approved = get_blog_option( $blog_id, 'auth_settings_access_users_approved', array() );
177 if ( is_array( $auth_settings_access_users_approved ) ) {
178 $should_update = false;
179 $distinct_emails = array();
180 foreach ( $auth_settings_access_users_approved as $key => $user ) {
181 if ( in_array( $user['email'], $distinct_emails, true ) ) {
182 $should_update = true;
183 unset( $auth_settings_access_users_approved[ $key ] );
184 } else {
185 $distinct_emails[] = $user['email'];
186 }
187 }
188 if ( $should_update ) {
189 update_blog_option( $blog_id, 'auth_settings_access_users_approved', $auth_settings_access_users_approved );
190 }
191 }
192 }
193 // Remove duplicates from multisite approved user list.
194 $auth_multisite_settings_access_users_approved = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings_access_users_approved', array() );
195 if ( is_array( $auth_multisite_settings_access_users_approved ) ) {
196 $should_update = false;
197 $distinct_emails = array();
198 foreach ( $auth_multisite_settings_access_users_approved as $key => $user ) {
199 if ( in_array( $user['email'], $distinct_emails, true ) ) {
200 $should_update = true;
201 unset( $auth_multisite_settings_access_users_approved[ $key ] );
202 } else {
203 $distinct_emails[] = $user['email'];
204 }
205 }
206 if ( $should_update ) {
207 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved );
208 }
209 }
210 } else {
211 // Remove duplicates from single site approved user list.
212 $auth_settings_access_users_approved = get_option( 'auth_settings_access_users_approved' );
213 if ( is_array( $auth_settings_access_users_approved ) ) {
214 $should_update = false;
215 $distinct_emails = array();
216 foreach ( $auth_settings_access_users_approved as $key => $user ) {
217 if ( in_array( $user['email'], $distinct_emails, true ) ) {
218 $should_update = true;
219 unset( $auth_settings_access_users_approved[ $key ] );
220 } else {
221 $distinct_emails[] = $user['email'];
222 }
223 }
224 if ( $should_update ) {
225 update_option( 'auth_settings_access_users_approved', $auth_settings_access_users_approved, false );
226 }
227 }
228 }
229 // Update version to reflect this change has been made.
230 $auth_version = $update_if_older_than;
231 $needs_updating = true;
232 }
233
234 // Update: Set default value for newly added option advanced_widget_enabled.
235 $update_if_older_than = 20171023;
236 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
237 // Provide default values for any $auth_settings options that don't exist.
238 if ( is_multisite() ) {
239 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
240 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
241 foreach ( $sites as $site ) {
242 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
243 switch_to_blog( $blog_id );
244 $options->set_default_options();
245 restore_current_blog();
246 }
247 } else {
248 $options->set_default_options();
249 }
250 // Update version to reflect this change has been made.
251 $auth_version = $update_if_older_than;
252 $needs_updating = true;
253 }
254
255 // Update: Set default value for newly added option advanced_users_per_page.
256 $update_if_older_than = 20171215;
257 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
258 // Provide default values for any $auth_settings options that don't exist.
259 if ( is_multisite() ) {
260 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
261 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
262 foreach ( $sites as $site ) {
263 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
264 switch_to_blog( $blog_id );
265 $options->set_default_options();
266 restore_current_blog();
267 }
268 } else {
269 $options->set_default_options();
270 }
271 // Update version to reflect this change has been made.
272 $auth_version = $update_if_older_than;
273 $needs_updating = true;
274 }
275
276 // Update: Set default value for newly added options advanced_users_sort_by and advanced_users_sort_order.
277 $update_if_older_than = 20171219;
278 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
279 // Provide default values for any $auth_settings options that don't exist.
280 if ( is_multisite() ) {
281 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
282 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
283 foreach ( $sites as $site ) {
284 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
285 switch_to_blog( $blog_id );
286 $options->set_default_options();
287 restore_current_blog();
288 }
289 } else {
290 $options->set_default_options();
291 }
292 // Update version to reflect this change has been made.
293 $auth_version = $update_if_older_than;
294 $needs_updating = true;
295 }
296
297 // Update: Set default value for newly added option cas_link_on_username.
298 $update_if_older_than = 20190227;
299 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
300 // Provide default values for any $auth_settings options that don't exist.
301 if ( is_multisite() ) {
302 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
303 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
304 foreach ( $sites as $site ) {
305 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
306 switch_to_blog( $blog_id );
307 $options->set_default_options();
308 restore_current_blog();
309 }
310 } else {
311 $options->set_default_options();
312 }
313 // Update version to reflect this change has been made.
314 $auth_version = $update_if_older_than;
315 $needs_updating = true;
316 }
317
318 // Update: Set default value for newly added option advanced_disable_wp_login.
319 $update_if_older_than = 20200331;
320 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
321 // Provide default values for any $auth_settings options that don't exist.
322 if ( is_multisite() ) {
323 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
324 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
325 foreach ( $sites as $site ) {
326 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
327 switch_to_blog( $blog_id );
328 $options->set_default_options();
329 restore_current_blog();
330 }
331 } else {
332 $options->set_default_options();
333 }
334 // Update version to reflect this change has been made.
335 $auth_version = $update_if_older_than;
336 $needs_updating = true;
337 }
338
339 // Update: Set default values for newly added oauth2 options.
340 $update_if_older_than = 20201217;
341 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
342 // Provide default values for any $auth_settings options that don't exist.
343 if ( is_multisite() ) {
344 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
345 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
346 foreach ( $sites as $site ) {
347 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
348 switch_to_blog( $blog_id );
349 $options->set_default_options();
350 restore_current_blog();
351 }
352 } else {
353 $options->set_default_options();
354 }
355 // Update version to reflect this change has been made.
356 $auth_version = $update_if_older_than;
357 $needs_updating = true;
358 }
359
360 // Update: Set default values for newly added oauth2_hosteddomain option.
361 $update_if_older_than = 20210624;
362 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
363 // Provide default values for any $auth_settings options that don't exist.
364 if ( is_multisite() ) {
365 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
366 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
367 foreach ( $sites as $site ) {
368 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
369 switch_to_blog( $blog_id );
370 $options->set_default_options();
371 restore_current_blog();
372 }
373 } else {
374 $options->set_default_options();
375 }
376 // Update version to reflect this change has been made.
377 $auth_version = $update_if_older_than;
378 $needs_updating = true;
379 }
380
381 // Update: Set default values for newly added ldap_search_filter option.
382 $update_if_older_than = 20210924;
383 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
384 // Provide default values for any $auth_settings options that don't exist.
385 if ( is_multisite() ) {
386 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
387 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
388 foreach ( $sites as $site ) {
389 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
390 switch_to_blog( $blog_id );
391 $options->set_default_options();
392 restore_current_blog();
393 }
394 } else {
395 $options->set_default_options();
396 }
397 // Update version to reflect this change has been made.
398 $auth_version = $update_if_older_than;
399 $needs_updating = true;
400 }
401
402 // Update: Set default values for newly added ldap_test_user option.
403 $update_if_older_than = 20220222;
404 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
405 // Provide default values for any $auth_settings options that don't exist.
406 if ( is_multisite() ) {
407 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
408 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
409 foreach ( $sites as $site ) {
410 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
411 switch_to_blog( $blog_id );
412 $options->set_default_options();
413 restore_current_blog();
414 }
415 } else {
416 $options->set_default_options();
417 }
418 // Update version to reflect this change has been made.
419 $auth_version = $update_if_older_than;
420 $needs_updating = true;
421 }
422
423 // Update: Remove any cached LDAP test password.
424 $update_if_older_than = 20220426;
425 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
426 if ( is_multisite() ) {
427 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
428 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
429 foreach ( $sites as $site ) {
430 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
431 $auth_settings = get_blog_option( $blog_id, 'auth_settings', array() );
432 if ( array_key_exists( 'ldap_test_pass', $auth_settings ) && strlen( $auth_settings['ldap_test_pass'] ) > 0 ) {
433 unset( $auth_settings['ldap_test_pass'] );
434 update_blog_option( $blog_id, 'auth_settings', $auth_settings );
435 }
436 }
437 } else {
438 $auth_settings = get_option( 'auth_settings', array() );
439 if ( array_key_exists( 'ldap_test_pass', $auth_settings ) && strlen( $auth_settings['ldap_test_pass'] ) > 0 ) {
440 unset( $auth_settings['ldap_test_pass'] );
441 update_option( 'auth_settings', $auth_settings, true );
442 }
443 }
444 // Update version to reflect this change has been made.
445 $auth_version = $update_if_older_than;
446 $needs_updating = true;
447 }
448
449 // Update: Set default values for newly added prevent_override_multisite option.
450 $update_if_older_than = 20220506;
451 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
452 // Provide default values for any $auth_settings options that don't exist.
453 if ( is_multisite() ) {
454 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
455 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
456 foreach ( $sites as $site ) {
457 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
458 switch_to_blog( $blog_id );
459 $options->set_default_options();
460 restore_current_blog();
461 }
462 } else {
463 $options->set_default_options();
464 }
465 // Update version to reflect this change has been made.
466 $auth_version = $update_if_older_than;
467 $needs_updating = true;
468 }
469
470 // Update: Set default values for newly added cas_method option.
471 $update_if_older_than = 20220818;
472 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
473 // Provide default values for any $auth_settings options that don't exist.
474 if ( is_multisite() ) {
475 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
476 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
477 foreach ( $sites as $site ) {
478 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
479 switch_to_blog( $blog_id );
480 $options->set_default_options();
481 restore_current_blog();
482 }
483 } else {
484 $options->set_default_options();
485 }
486 // Update version to reflect this change has been made.
487 $auth_version = $update_if_older_than;
488 $needs_updating = true;
489 }
490
491 // Update: Set default values for missed multisite option ldap_test_user.
492 $update_if_older_than = 20221101;
493 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
494 // Provide default values for any $auth_settings options that don't exist.
495 $options->set_default_options();
496 if ( is_multisite() ) {
497 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
498 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
499 foreach ( $sites as $site ) {
500 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
501 switch_to_blog( $blog_id );
502 $options->set_default_options( array( 'set_multisite_options' => false ) );
503 restore_current_blog();
504 }
505 }
506 // Update version to reflect this change has been made.
507 $auth_version = $update_if_older_than;
508 $needs_updating = true;
509 }
510
511 // Update: Only save one auth_version in the database on multisite (instead
512 // of a version for each subsite, which was unnecessary because the plugin
513 // is updated once at the network level). Remove extra auth_version options.
514 $update_if_older_than = 20230222;
515 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
516 if ( is_multisite() ) {
517 $network_blog_id = get_main_site_id( get_main_network_id() );
518 // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound
519 $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) );
520 foreach ( $sites as $site ) {
521 $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id'];
522 // Don't delete auth_version on the main site in the network.
523 if ( $network_blog_id === $blog_id ) {
524 continue;
525 }
526 // Remove auth_version on subsites.
527 switch_to_blog( $blog_id );
528 delete_option( 'auth_version' );
529 restore_current_blog();
530 }
531 }
532 // Update version to reflect this change has been made.
533 $auth_version = $update_if_older_than;
534 $needs_updating = true;
535 }
536
537 /* phpcs:ignore Squiz.PHP.CommentedOutCode.Found
538 // Update: TEMPLATE
539 $update_if_older_than = YYYYMMDD;
540 if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) {
541 ////// PLACE UPDATE CODE HERE
542 // Update version to reflect this change has been made.
543 $auth_version = $update_if_older_than;
544 $needs_updating = true;
545 }
546 */
547
548 // Save new version number if we performed any updates.
549 if ( $needs_updating ) {
550 if ( is_multisite() ) {
551 update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_version', $auth_version );
552 } else {
553 update_option( 'auth_version', $auth_version, true );
554 }
555 }
556 }
557 }
558