| @@ -14,9 +14,9 @@ | ||
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Run any database migrations or plugin updates when installing a new version. |
| 17 | 17 | */ |
| 18 | -class Updates extends Static_Instance { | |
| 18 | +class Updates extends Singleton { | |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Plugin Update Routines. |
| 22 | 22 | * |
| @@ -27,9 +27,9 @@ | ||
| 27 | 27 | |
| 28 | 28 | // Get current version. |
| 29 | 29 | $needs_updating = false; |
| 30 | 30 | if ( is_multisite() ) { |
| 31 | - $auth_version = get_blog_option( get_network()->blog_id, 'auth_version' ); | |
| 31 | + $auth_version = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_version' ); | |
| 32 | 32 | } else { |
| 33 | 33 | $auth_version = get_option( 'auth_version' ); |
| 34 | 34 | } |
| 35 | 35 | |
| @@ -61,23 +61,23 @@ | ||
| 61 | 61 | update_option( 'auth_settings', $auth_settings ); |
| 62 | 62 | } |
| 63 | 63 | // Copy multisite user lists to new options (if they exist). |
| 64 | 64 | if ( is_multisite() ) { |
| 65 | - $auth_multisite_settings = get_blog_option( get_network()->blog_id, 'auth_multisite_settings', array() ); | |
| 65 | + $auth_multisite_settings = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', array() ); | |
| 66 | 66 | if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_pending', $auth_multisite_settings ) ) { |
| 67 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings_access_users_pending', $auth_multisite_settings['access_users_pending'] ); | |
| 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 | 68 | unset( $auth_multisite_settings['access_users_pending'] ); |
| 69 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings', $auth_multisite_settings ); | |
| 69 | + update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings ); | |
| 70 | 70 | } |
| 71 | 71 | if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_approved', $auth_multisite_settings ) ) { |
| 72 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings['access_users_approved'] ); | |
| 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 | 73 | unset( $auth_multisite_settings['access_users_approved'] ); |
| 74 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings', $auth_multisite_settings ); | |
| 74 | + update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings ); | |
| 75 | 75 | } |
| 76 | 76 | if ( is_array( $auth_multisite_settings ) && array_key_exists( 'access_users_blocked', $auth_multisite_settings ) ) { |
| 77 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings_access_users_blocked', $auth_multisite_settings['access_users_blocked'] ); | |
| 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 | 78 | unset( $auth_multisite_settings['access_users_blocked'] ); |
| 79 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings', $auth_multisite_settings ); | |
| 79 | + update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings ); | |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | // Update version to reflect this change has been made. |
| 83 | 83 | $auth_version = $update_if_older_than; |
| @@ -148,13 +148,13 @@ | ||
| 148 | 148 | $update_if_older_than = 20170511; |
| 149 | 149 | if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) { |
| 150 | 150 | if ( is_multisite() ) { |
| 151 | 151 | // Reencrypt LDAP password in network (multisite) options. |
| 152 | - $auth_multisite_settings = get_blog_option( get_network()->blog_id, 'auth_multisite_settings', array() ); | |
| 152 | + $auth_multisite_settings = get_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', array() ); | |
| 153 | 153 | if ( array_key_exists( 'ldap_password', $auth_multisite_settings ) && strlen( $auth_multisite_settings['ldap_password'] ) > 0 ) { |
| 154 | 154 | $plaintext_ldap_password = Helper::decrypt( $auth_multisite_settings['ldap_password'], 'mcrypt' ); |
| 155 | 155 | $auth_multisite_settings['ldap_password'] = Helper::encrypt( $plaintext_ldap_password ); |
| 156 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings', $auth_multisite_settings ); | |
| 156 | + update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_multisite_settings', $auth_multisite_settings ); | |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | // Update version to reflect this change has been made. |
| 160 | 160 | $auth_version = $update_if_older_than; |
| @@ -190,9 +190,9 @@ | ||
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | // Remove duplicates from multisite approved user list. |
| 194 | - $auth_multisite_settings_access_users_approved = get_blog_option( get_network()->blog_id, 'auth_multisite_settings_access_users_approved', array() ); | |
| 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 | 195 | if ( is_array( $auth_multisite_settings_access_users_approved ) ) { |
| 196 | 196 | $should_update = false; |
| 197 | 197 | $distinct_emails = array(); |
| 198 | 198 | foreach ( $auth_multisite_settings_access_users_approved as $key => $user ) { |
| @@ -203,9 +203,9 @@ | ||
| 203 | 203 | $distinct_emails[] = $user['email']; |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | if ( $should_update ) { |
| 207 | - update_blog_option( get_network()->blog_id, 'auth_multisite_settings_access_users_approved', $auth_multisite_settings_access_users_approved ); | |
| 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 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | } else { |
| 211 | 211 | // Remove duplicates from single site approved user list. |
| @@ -314,15 +314,234 @@ | ||
| 314 | 314 | $auth_version = $update_if_older_than; |
| 315 | 315 | $needs_updating = true; |
| 316 | 316 | } |
| 317 | 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 ); | |
| 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 | + | |
| 318 | 537 | /* phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
| 319 | 538 | // Update: TEMPLATE |
| 320 | 539 | $update_if_older_than = YYYYMMDD; |
| 321 | - if ( $auth_version === false || intval( $auth_version ) < $update_if_older_than ) { | |
| 540 | + if ( false === $auth_version || intval( $auth_version ) < $update_if_older_than ) { | |
| 322 | 541 | ////// PLACE UPDATE CODE HERE |
| 323 | 542 | // Update version to reflect this change has been made. |
| 324 | - $auth_version = $update_if_older_than; | |
| 543 | + $auth_version = $update_if_older_than; | |
| 325 | 544 | $needs_updating = true; |
| 326 | 545 | } |
| 327 | 546 | */ |
| 328 | 547 | |
| @@ -328,17 +547,11 @@ | ||
| 328 | 547 | |
| 329 | 548 | // Save new version number if we performed any updates. |
| 330 | 549 | if ( $needs_updating ) { |
| 331 | 550 | if ( is_multisite() ) { |
| 332 | - // phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound | |
| 333 | - $sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites( array( 'limit' => PHP_INT_MAX ) ); | |
| 334 | - foreach ( $sites as $site ) { | |
| 335 | - $blog_id = function_exists( 'get_sites' ) ? $site->blog_id : $site['blog_id']; | |
| 336 | - update_blog_option( $blog_id, 'auth_version', $auth_version ); | |
| 337 | - } | |
| 551 | + update_blog_option( get_main_site_id( get_main_network_id() ), 'auth_version', $auth_version ); | |
| 338 | 552 | } else { |
| 339 | 553 | update_option( 'auth_version', $auth_version ); |
| 340 | 554 | } |
| 341 | 555 | } |
| 342 | 556 | } |
| 343 | - | |
| 344 | 557 | } |