upgrade_network

Executes network-level upgrade routines.

Description

upgrade_network(); 

Usage

  1. if ( !function_exists( 'upgrade_network' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = upgrade_network(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/upgrade.php  
  1. function upgrade_network() { 
  2. global $wp_current_db_version, $wpdb; 
  3.  
  4. // Always. 
  5. if ( is_main_network() ) { 
  6. /** 
  7. * Deletes all expired transients. The multi-table delete syntax is used 
  8. * to delete the transient record from table a, and the corresponding 
  9. * transient_timeout record from table b. 
  10. */ 
  11. $time = time(); 
  12. $sql = "DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b 
  13. WHERE a.meta_key LIKE %s 
  14. AND a.meta_key NOT LIKE %s 
  15. AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) ) 
  16. AND b.meta_value < %d"; 
  17. $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like ( '_site_transient_timeout_' ) . '%', $time ) ); 
  18.  
  19. // 2.8. 
  20. if ( $wp_current_db_version < 11549 ) { 
  21. $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); 
  22. $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); 
  23. if ( $wpmu_sitewide_plugins ) { 
  24. if ( !$active_sitewide_plugins ) 
  25. $sitewide_plugins = (array) $wpmu_sitewide_plugins; 
  26. else 
  27. $sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins ); 
  28.  
  29. update_site_option( 'active_sitewide_plugins', $sitewide_plugins ); 
  30. delete_site_option( 'wpmu_sitewide_plugins' ); 
  31. delete_site_option( 'deactivated_sitewide_plugins' ); 
  32.  
  33. $start = 0; 
  34. while( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) { 
  35. foreach ( $rows as $row ) { 
  36. $value = $row->meta_value; 
  37. if ( !@unserialize( $value ) ) 
  38. $value = stripslashes( $value ); 
  39. if ( $value !== $row->meta_value ) { 
  40. update_site_option( $row->meta_key, $value ); 
  41. $start += 20; 
  42.  
  43. // 3.0 
  44. if ( $wp_current_db_version < 13576 ) 
  45.  
  46. // 3.3 
  47. if ( $wp_current_db_version < 19390 ) 
  48. update_site_option( 'initial_db_version', $wp_current_db_version ); 
  49.  
  50. if ( $wp_current_db_version < 19470 ) { 
  51. if ( false === get_site_option( 'active_sitewide_plugins' ) ) 
  52. update_site_option( 'active_sitewide_plugins', array() ); 
  53.  
  54. // 3.4 
  55. if ( $wp_current_db_version < 20148 ) { 
  56. // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. 
  57. $allowedthemes = get_site_option( 'allowedthemes' ); 
  58. $allowed_themes = get_site_option( 'allowed_themes' ); 
  59. if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) { 
  60. $converted = array(); 
  61. $themes = wp_get_themes(); 
  62. foreach ( $themes as $stylesheet => $theme_data ) { 
  63. if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) ) 
  64. $converted[ $stylesheet ] = true; 
  65. update_site_option( 'allowedthemes', $converted ); 
  66. delete_site_option( 'allowed_themes' ); 
  67.  
  68. // 3.5 
  69. if ( $wp_current_db_version < 21823 ) 
  70. update_site_option( 'ms_files_rewriting', '1' ); 
  71.  
  72. // 3.5.2 
  73. if ( $wp_current_db_version < 24448 ) { 
  74. $illegal_names = get_site_option( 'illegal_names' ); 
  75. if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) { 
  76. $illegal_name = reset( $illegal_names ); 
  77. $illegal_names = explode( ' ', $illegal_name ); 
  78. update_site_option( 'illegal_names', $illegal_names ); 
  79.  
  80. // 4.2 
  81. if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) { 
  82. $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 
  83. $wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140), path(51))" ); 
  84. $wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 
  85. $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140), path(51))" ); 
  86.  
  87. $tables = $wpdb->tables( 'global' ); 
  88.  
  89. // sitecategories may not exist. 
  90. if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) { 
  91. unset( $tables['sitecategories'] ); 
  92.  
  93. foreach ( $tables as $table ) { 
  94.  
  95. // 4.3 
  96. if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) { 
  97. $upgrade = false; 
  98. $indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" ); 
  99. foreach ( $indexes as $index ) { 
  100. if ( 'domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part ) { 
  101. $upgrade = true; 
  102. break; 
  103.  
  104. if ( $upgrade ) { 
  105. $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140), path(51))" ); 
  106.  
  107. $tables = $wpdb->tables( 'global' ); 
  108.  
  109. // sitecategories may not exist. 
  110. if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) { 
  111. unset( $tables['sitecategories'] ); 
  112.  
  113. foreach ( $tables as $table ) {