[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> upgrade.php (source)

   1  <?php
   2  /**
   3   * WordPress Upgrade API
   4   *
   5   * Most of the functions are pluggable and can be overwritten.
   6   *
   7   * @package WordPress
   8   * @subpackage Administration
   9   */
  10  
  11  /** Include user installation customization script. */
  12  if ( file_exists( WP_CONTENT_DIR . '/install.php' ) ) {
  13      require WP_CONTENT_DIR . '/install.php';
  14  }
  15  
  16  /** WordPress Administration API */
  17  require_once  ABSPATH . 'wp-admin/includes/admin.php';
  18  
  19  /** WordPress Schema API */
  20  require_once  ABSPATH . 'wp-admin/includes/schema.php';
  21  
  22  if ( ! function_exists( 'wp_install' ) ) :
  23      /**
  24       * Installs the site.
  25       *
  26       * Runs the required functions to set up and populate the database,
  27       * including primary admin user and initial options.
  28       *
  29       * @since 2.1.0
  30       *
  31       * @param string $blog_title    Site title.
  32       * @param string $user_name     User's username.
  33       * @param string $user_email    User's email.
  34       * @param bool   $is_public     Whether the site is public.
  35       * @param string $deprecated    Optional. Not used.
  36       * @param string $user_password Optional. User's chosen password. Default empty (random password).
  37       * @param string $language      Optional. Language chosen. Default empty.
  38       * @return array {
  39       *     Data for the newly installed site.
  40       *
  41       *     @type string $url              The URL of the site.
  42       *     @type int    $user_id          The ID of the site owner.
  43       *     @type string $password         The password of the site owner, if their user account didn't already exist.
  44       *     @type string $password_message The explanatory message regarding the password.
  45       * }
  46       */
  47  	function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
  48          if ( ! empty( $deprecated ) ) {
  49              _deprecated_argument( __FUNCTION__, '2.6.0' );
  50          }
  51  
  52          wp_check_mysql_version();
  53          wp_cache_flush();
  54          make_db_current_silent();
  55  
  56          /*
  57           * Ensure update checks are delayed after installation.
  58           *
  59           * This prevents users being presented with a maintenance mode screen
  60           * immediately after installation.
  61           */
  62          wp_unschedule_hook( 'wp_version_check' );
  63          wp_unschedule_hook( 'wp_update_plugins' );
  64          wp_unschedule_hook( 'wp_update_themes' );
  65  
  66          wp_schedule_event( time() + HOUR_IN_SECONDS, 'twicedaily', 'wp_version_check' );
  67          wp_schedule_event( time() + ( 1.5 * HOUR_IN_SECONDS ), 'twicedaily', 'wp_update_plugins' );
  68          wp_schedule_event( time() + ( 2 * HOUR_IN_SECONDS ), 'twicedaily', 'wp_update_themes' );
  69  
  70          populate_options();
  71          populate_roles();
  72  
  73          update_option( 'blogname', $blog_title );
  74          update_option( 'admin_email', $user_email );
  75          update_option( 'blog_public', $is_public );
  76  
  77          // Freshness of site - in the future, this could get more specific about actions taken, perhaps.
  78          update_option( 'fresh_site', 1, false );
  79  
  80          if ( $language ) {
  81              update_option( 'WPLANG', $language );
  82          }
  83  
  84          $guessurl = wp_guess_url();
  85  
  86          update_option( 'siteurl', $guessurl );
  87  
  88          // If not a public site, don't ping.
  89          if ( ! $is_public ) {
  90              update_option( 'default_pingback_flag', 0 );
  91          }
  92  
  93          /*
  94           * Create default user. If the user already exists, the user tables are
  95           * being shared among sites. Just set the role in that case.
  96           */
  97          $user_id        = username_exists( $user_name );
  98          $user_password  = trim( $user_password );
  99          $email_password = false;
 100          $user_created   = false;
 101  
 102          if ( ! $user_id && empty( $user_password ) ) {
 103              $user_password = wp_generate_password( 12, false );
 104              $message       = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
 105              $user_id       = wp_create_user( $user_name, $user_password, $user_email );
 106              update_user_meta( $user_id, 'default_password_nag', true );
 107              $email_password = true;
 108              $user_created   = true;
 109          } elseif ( ! $user_id ) {
 110              // Password has been provided.
 111              $message      = '<em>' . __( 'Your chosen password.' ) . '</em>';
 112              $user_id      = wp_create_user( $user_name, $user_password, $user_email );
 113              $user_created = true;
 114          } else {
 115              $message = __( 'User already exists. Password inherited.' );
 116          }
 117  
 118          $user = new WP_User( $user_id );
 119          $user->set_role( 'administrator' );
 120  
 121          if ( $user_created ) {
 122              $user->user_url = $guessurl;
 123              wp_update_user( $user );
 124          }
 125  
 126          wp_install_defaults( $user_id );
 127  
 128          wp_install_maybe_enable_pretty_permalinks();
 129  
 130          flush_rewrite_rules();
 131  
 132          wp_new_blog_notification( $blog_title, $guessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.' ) ) );
 133  
 134          wp_cache_flush();
 135  
 136          /**
 137           * Fires after a site is fully installed.
 138           *
 139           * @since 3.9.0
 140           *
 141           * @param WP_User $user The site owner.
 142           */
 143          do_action( 'wp_install', $user );
 144  
 145          return array(
 146              'url'              => $guessurl,
 147              'user_id'          => $user_id,
 148              'password'         => $user_password,
 149              'password_message' => $message,
 150          );
 151      }
 152  endif;
 153  
 154  if ( ! function_exists( 'wp_install_defaults' ) ) :
 155      /**
 156       * Creates the initial content for a newly-installed site.
 157       *
 158       * Adds the default "Uncategorized" category, the first post (with comment),
 159       * first page, and default widgets for default theme for the current version.
 160       *
 161       * @since 2.1.0
 162       *
 163       * @global wpdb       $wpdb         WordPress database abstraction object.
 164       * @global WP_Rewrite $wp_rewrite   WordPress rewrite component.
 165       * @global string     $table_prefix The database table prefix.
 166       *
 167       * @param int $user_id User ID.
 168       */
 169  	function wp_install_defaults( $user_id ) {
 170          global $wpdb, $wp_rewrite, $table_prefix;
 171  
 172          // Default category.
 173          $cat_name = __( 'Uncategorized' );
 174          /* translators: Default category slug. */
 175          $cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
 176  
 177          $cat_id = 1;
 178  
 179          $wpdb->insert(
 180              $wpdb->terms,
 181              array(
 182                  'term_id'    => $cat_id,
 183                  'name'       => $cat_name,
 184                  'slug'       => $cat_slug,
 185                  'term_group' => 0,
 186              )
 187          );
 188          $wpdb->insert(
 189              $wpdb->term_taxonomy,
 190              array(
 191                  'term_id'     => $cat_id,
 192                  'taxonomy'    => 'category',
 193                  'description' => '',
 194                  'parent'      => 0,
 195                  'count'       => 1,
 196              )
 197          );
 198          $cat_tt_id = $wpdb->insert_id;
 199  
 200          // First post.
 201          $now             = current_time( 'mysql' );
 202          $now_gmt         = current_time( 'mysql', 1 );
 203          $first_post_guid = get_option( 'home' ) . '/?p=1';
 204  
 205          if ( is_multisite() ) {
 206              $first_post = get_site_option( 'first_post' );
 207  
 208              if ( ! $first_post ) {
 209                  $first_post = "<!-- wp:paragraph -->\n<p>" .
 210                  /* translators: First post content. %s: Site link. */
 211                  __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) .
 212                  "</p>\n<!-- /wp:paragraph -->";
 213              }
 214  
 215              $first_post = sprintf(
 216                  $first_post,
 217                  sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name )
 218              );
 219  
 220              // Back-compat for pre-4.4.
 221              $first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post );
 222              $first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post );
 223          } else {
 224              $first_post = "<!-- wp:paragraph -->\n<p>" .
 225              /* translators: First post content. %s: Site link. */
 226              __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) .
 227              "</p>\n<!-- /wp:paragraph -->";
 228          }
 229  
 230          $wpdb->insert(
 231              $wpdb->posts,
 232              array(
 233                  'post_author'           => $user_id,
 234                  'post_date'             => $now,
 235                  'post_date_gmt'         => $now_gmt,
 236                  'post_content'          => $first_post,
 237                  'post_excerpt'          => '',
 238                  'post_title'            => __( 'Hello world!' ),
 239                  /* translators: Default post slug. */
 240                  'post_name'             => sanitize_title( _x( 'hello-world', 'Default post slug' ) ),
 241                  'post_modified'         => $now,
 242                  'post_modified_gmt'     => $now_gmt,
 243                  'guid'                  => $first_post_guid,
 244                  'comment_count'         => 1,
 245                  'to_ping'               => '',
 246                  'pinged'                => '',
 247                  'post_content_filtered' => '',
 248              )
 249          );
 250  
 251          if ( is_multisite() ) {
 252              update_posts_count();
 253          }
 254  
 255          $wpdb->insert(
 256              $wpdb->term_relationships,
 257              array(
 258                  'term_taxonomy_id' => $cat_tt_id,
 259                  'object_id'        => 1,
 260              )
 261          );
 262  
 263          // Default comment.
 264          if ( is_multisite() ) {
 265              $first_comment_author = get_site_option( 'first_comment_author' );
 266              $first_comment_email  = get_site_option( 'first_comment_email' );
 267              $first_comment_url    = get_site_option( 'first_comment_url', network_home_url() );
 268              $first_comment        = get_site_option( 'first_comment' );
 269          }
 270  
 271          $first_comment_author = ! empty( $first_comment_author ) ? $first_comment_author : __( 'A WordPress Commenter' );
 272          $first_comment_email  = ! empty( $first_comment_email ) ? $first_comment_email : 'wapuu@wordpress.example';
 273          $first_comment_url    = ! empty( $first_comment_url ) ? $first_comment_url : esc_url( __( 'https://wordpress.org/' ) );
 274          $first_comment        = ! empty( $first_comment ) ? $first_comment : sprintf(
 275              /* translators: %s: Gravatar URL. */
 276              __(
 277                  'Hi, this is a comment.
 278  To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
 279  Commenter avatars come from <a href="%s">Gravatar</a>.'
 280              ),
 281              /* translators: The localized Gravatar URL. */
 282              esc_url( __( 'https://gravatar.com/' ) )
 283          );
 284          $wpdb->insert(
 285              $wpdb->comments,
 286              array(
 287                  'comment_post_ID'      => 1,
 288                  'comment_author'       => $first_comment_author,
 289                  'comment_author_email' => $first_comment_email,
 290                  'comment_author_url'   => $first_comment_url,
 291                  'comment_date'         => $now,
 292                  'comment_date_gmt'     => $now_gmt,
 293                  'comment_content'      => $first_comment,
 294                  'comment_type'         => 'comment',
 295              )
 296          );
 297  
 298          // First page.
 299          if ( is_multisite() ) {
 300              $first_page = get_site_option( 'first_page' );
 301          }
 302  
 303          if ( empty( $first_page ) ) {
 304              $first_page = "<!-- wp:paragraph -->\n<p>";
 305              /* translators: First page content. */
 306              $first_page .= __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:" );
 307              $first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
 308  
 309              $first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
 310              /* translators: First page content. */
 311              $first_page .= __( "Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)" );
 312              $first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
 313  
 314              $first_page .= "<!-- wp:paragraph -->\n<p>";
 315              /* translators: First page content. */
 316              $first_page .= __( '...or something like this:' );
 317              $first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
 318  
 319              $first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
 320              /* translators: First page content. */
 321              $first_page .= __( 'The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.' );
 322              $first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
 323  
 324              $first_page .= "<!-- wp:paragraph -->\n<p>";
 325              $first_page .= sprintf(
 326                  /* translators: First page content. %s: Site admin URL. */
 327                  __( 'As a new WordPress user, you should go to <a href="%s">your dashboard</a> to delete this page and create new pages for your content. Have fun!' ),
 328                  admin_url()
 329              );
 330              $first_page .= "</p>\n<!-- /wp:paragraph -->";
 331          }
 332  
 333          $first_post_guid = get_option( 'home' ) . '/?page_id=2';
 334          $wpdb->insert(
 335              $wpdb->posts,
 336              array(
 337                  'post_author'           => $user_id,
 338                  'post_date'             => $now,
 339                  'post_date_gmt'         => $now_gmt,
 340                  'post_content'          => $first_page,
 341                  'post_excerpt'          => '',
 342                  'comment_status'        => 'closed',
 343                  'post_title'            => __( 'Sample Page' ),
 344                  /* translators: Default page slug. */
 345                  'post_name'             => __( 'sample-page' ),
 346                  'post_modified'         => $now,
 347                  'post_modified_gmt'     => $now_gmt,
 348                  'guid'                  => $first_post_guid,
 349                  'post_type'             => 'page',
 350                  'to_ping'               => '',
 351                  'pinged'                => '',
 352                  'post_content_filtered' => '',
 353              )
 354          );
 355          $wpdb->insert(
 356              $wpdb->postmeta,
 357              array(
 358                  'post_id'    => 2,
 359                  'meta_key'   => '_wp_page_template',
 360                  'meta_value' => 'default',
 361              )
 362          );
 363  
 364          // Privacy Policy page.
 365          if ( is_multisite() ) {
 366              // Disable by default unless the suggested content is provided.
 367              $privacy_policy_content = get_site_option( 'default_privacy_policy_content' );
 368          } else {
 369              if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
 370                  require_once  ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
 371              }
 372  
 373              $privacy_policy_content = WP_Privacy_Policy_Content::get_default_content();
 374          }
 375  
 376          if ( ! empty( $privacy_policy_content ) ) {
 377              $privacy_policy_guid = get_option( 'home' ) . '/?page_id=3';
 378  
 379              $wpdb->insert(
 380                  $wpdb->posts,
 381                  array(
 382                      'post_author'           => $user_id,
 383                      'post_date'             => $now,
 384                      'post_date_gmt'         => $now_gmt,
 385                      'post_content'          => $privacy_policy_content,
 386                      'post_excerpt'          => '',
 387                      'comment_status'        => 'closed',
 388                      'post_title'            => __( 'Privacy Policy' ),
 389                      /* translators: Privacy Policy page slug. */
 390                      'post_name'             => __( 'privacy-policy' ),
 391                      'post_modified'         => $now,
 392                      'post_modified_gmt'     => $now_gmt,
 393                      'guid'                  => $privacy_policy_guid,
 394                      'post_type'             => 'page',
 395                      'post_status'           => 'draft',
 396                      'to_ping'               => '',
 397                      'pinged'                => '',
 398                      'post_content_filtered' => '',
 399                  )
 400              );
 401              $wpdb->insert(
 402                  $wpdb->postmeta,
 403                  array(
 404                      'post_id'    => 3,
 405                      'meta_key'   => '_wp_page_template',
 406                      'meta_value' => 'default',
 407                  )
 408              );
 409              update_option( 'wp_page_for_privacy_policy', 3 );
 410          }
 411  
 412          // Set up default widgets for default theme.
 413          update_option(
 414              'widget_block',
 415              array(
 416                  2              => array( 'content' => '<!-- wp:search /-->' ),
 417                  3              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Posts' ) . '</h2><!-- /wp:heading --><!-- wp:latest-posts /--></div><!-- /wp:group -->' ),
 418                  4              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Comments' ) . '</h2><!-- /wp:heading --><!-- wp:latest-comments {"displayAvatar":false,"displayDate":false,"displayExcerpt":false} /--></div><!-- /wp:group -->' ),
 419                  5              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Archives' ) . '</h2><!-- /wp:heading --><!-- wp:archives /--></div><!-- /wp:group -->' ),
 420                  6              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Categories' ) . '</h2><!-- /wp:heading --><!-- wp:categories /--></div><!-- /wp:group -->' ),
 421                  '_multiwidget' => 1,
 422              )
 423          );
 424          update_option(
 425              'sidebars_widgets',
 426              array(
 427                  'wp_inactive_widgets' => array(),
 428                  'sidebar-1'           => array(
 429                      0 => 'block-2',
 430                      1 => 'block-3',
 431                      2 => 'block-4',
 432                  ),
 433                  'sidebar-2'           => array(
 434                      0 => 'block-5',
 435                      1 => 'block-6',
 436                  ),
 437                  'array_version'       => 3,
 438              )
 439          );
 440  
 441          if ( ! is_multisite() ) {
 442              update_user_meta( $user_id, 'show_welcome_panel', 1 );
 443          } elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) {
 444              update_user_meta( $user_id, 'show_welcome_panel', 2 );
 445          }
 446  
 447          if ( is_multisite() ) {
 448              // Flush rules to pick up the new page.
 449              $wp_rewrite->init();
 450              $wp_rewrite->flush_rules();
 451  
 452              $user = new WP_User( $user_id );
 453              $wpdb->update( $wpdb->options, array( 'option_value' => $user->user_email ), array( 'option_name' => 'admin_email' ) );
 454  
 455              // Remove all perms except for the login user.
 456              $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level' ) );
 457              $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities' ) );
 458  
 459              /*
 460               * Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.)
 461               * TODO: Get previous_blog_id.
 462               */
 463              if ( ! is_super_admin( $user_id ) && 1 !== $user_id ) {
 464                  $wpdb->delete(
 465                      $wpdb->usermeta,
 466                      array(
 467                          'user_id'  => $user_id,
 468                          'meta_key' => $wpdb->base_prefix . '1_capabilities',
 469                      )
 470                  );
 471              }
 472          }
 473      }
 474  endif;
 475  
 476  /**
 477   * Maybe enable pretty permalinks on installation.
 478   *
 479   * If after enabling pretty permalinks don't work, fallback to query-string permalinks.
 480   *
 481   * @since 4.2.0
 482   *
 483   * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 484   *
 485   * @return bool Whether pretty permalinks are enabled. False otherwise.
 486   */
 487  function wp_install_maybe_enable_pretty_permalinks() {
 488      global $wp_rewrite;
 489  
 490      // Bail if a permalink structure is already enabled.
 491      if ( get_option( 'permalink_structure' ) ) {
 492          return true;
 493      }
 494  
 495      /*
 496       * The Permalink structures to attempt.
 497       *
 498       * The first is designed for mod_rewrite or nginx rewriting.
 499       *
 500       * The second is PATHINFO-based permalinks for web server configurations
 501       * without a true rewrite module enabled.
 502       */
 503      $permalink_structures = array(
 504          '/%year%/%monthnum%/%day%/%postname%/',
 505          '/index.php/%year%/%monthnum%/%day%/%postname%/',
 506      );
 507  
 508      foreach ( (array) $permalink_structures as $permalink_structure ) {
 509          $wp_rewrite->set_permalink_structure( $permalink_structure );
 510  
 511          /*
 512           * Flush rules with the hard option to force refresh of the web-server's
 513           * rewrite config file (e.g. .htaccess or web.config).
 514           */
 515          $wp_rewrite->flush_rules( true );
 516  
 517          $test_url = '';
 518  
 519          // Test against a real WordPress post.
 520          $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
 521          if ( $first_post ) {
 522              $test_url = get_permalink( $first_post->ID );
 523          }
 524  
 525          /*
 526           * Send a request to the site, and check whether
 527           * the 'X-Pingback' header is returned as expected.
 528           *
 529           * Uses wp_remote_get() instead of wp_remote_head() because web servers
 530           * can block head requests.
 531           */
 532          $response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
 533          $x_pingback_header = wp_remote_retrieve_header( $response, 'X-Pingback' );
 534          $pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;
 535  
 536          if ( $pretty_permalinks ) {
 537              return true;
 538          }
 539      }
 540  
 541      /*
 542       * If it makes it this far, pretty permalinks failed.
 543       * Fallback to query-string permalinks.
 544       */
 545      $wp_rewrite->set_permalink_structure( '' );
 546      $wp_rewrite->flush_rules( true );
 547  
 548      return false;
 549  }
 550  
 551  if ( ! function_exists( 'wp_new_blog_notification' ) ) :
 552      /**
 553       * Notifies the site admin that the installation of WordPress is complete.
 554       *
 555       * Sends an email to the new administrator that the installation is complete
 556       * and provides them with a record of their login credentials.
 557       *
 558       * @since 2.1.0
 559       *
 560       * @param string $blog_title Site title.
 561       * @param string $blog_url   Site URL.
 562       * @param int    $user_id    Administrator's user ID.
 563       * @param string $password   Administrator's password. Note that a placeholder message is
 564       *                           usually passed instead of the actual password.
 565       */
 566  	function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
 567          $user      = new WP_User( $user_id );
 568          $email     = $user->user_email;
 569          $name      = $user->user_login;
 570          $login_url = wp_login_url();
 571  
 572          $message = sprintf(
 573              /* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL. */
 574              __(
 575                  'Your new WordPress site has been successfully set up at:
 576  
 577  %1$s
 578  
 579  You can log in to the administrator account with the following information:
 580  
 581  Username: %2$s
 582  Password: %3$s
 583  Log in here: %4$s
 584  
 585  We hope you enjoy your new site. Thanks!
 586  
 587  --The WordPress Team
 588  https://wordpress.org/
 589  '
 590              ),
 591              $blog_url,
 592              $name,
 593              $password,
 594              $login_url
 595          );
 596  
 597          $installed_email = array(
 598              'to'      => $email,
 599              'subject' => __( 'New WordPress Site' ),
 600              'message' => $message,
 601              'headers' => '',
 602          );
 603  
 604          /**
 605           * Filters the contents of the email sent to the site administrator when WordPress is installed.
 606           *
 607           * @since 5.6.0
 608           *
 609           * @param array $installed_email {
 610           *     Used to build wp_mail().
 611           *
 612           *     @type string $to      The email address of the recipient.
 613           *     @type string $subject The subject of the email.
 614           *     @type string $message The content of the email.
 615           *     @type string $headers Headers.
 616           * }
 617           * @param WP_User $user          The site administrator user object.
 618           * @param string  $blog_title    The site title.
 619           * @param string  $blog_url      The site URL.
 620           * @param string  $password      The site administrator's password. Note that a placeholder message
 621           *                               is usually passed instead of the user's actual password.
 622           */
 623          $installed_email = apply_filters( 'wp_installed_email', $installed_email, $user, $blog_title, $blog_url, $password );
 624  
 625          wp_mail(
 626              $installed_email['to'],
 627              $installed_email['subject'],
 628              $installed_email['message'],
 629              $installed_email['headers']
 630          );
 631      }
 632  endif;
 633  
 634  if ( ! function_exists( 'wp_upgrade' ) ) :
 635      /**
 636       * Runs WordPress Upgrade functions.
 637       *
 638       * Upgrades the database if needed during a site update.
 639       *
 640       * @since 2.1.0
 641       *
 642       * @global int $wp_current_db_version The old (current) database version.
 643       * @global int $wp_db_version         The new database version.
 644       */
 645  	function wp_upgrade() {
 646          global $wp_current_db_version, $wp_db_version;
 647  
 648          $wp_current_db_version = (int) __get_option( 'db_version' );
 649  
 650          // We are up to date. Nothing to do.
 651          if ( $wp_db_version === $wp_current_db_version ) {
 652              return;
 653          }
 654  
 655          if ( ! is_blog_installed() ) {
 656              return;
 657          }
 658  
 659          wp_check_mysql_version();
 660          wp_cache_flush();
 661          pre_schema_upgrade();
 662          make_db_current_silent();
 663          upgrade_all();
 664          if ( is_multisite() && is_main_site() ) {
 665              upgrade_network();
 666          }
 667          wp_cache_flush();
 668  
 669          if ( is_multisite() ) {
 670              update_site_meta( get_current_blog_id(), 'db_version', $wp_db_version );
 671              update_site_meta( get_current_blog_id(), 'db_last_updated', microtime() );
 672          }
 673  
 674          delete_transient( 'wp_core_block_css_files' );
 675  
 676          /**
 677           * Fires after a site is fully upgraded.
 678           *
 679           * @since 3.9.0
 680           *
 681           * @param int $wp_db_version         The new $wp_db_version.
 682           * @param int $wp_current_db_version The old (current) $wp_db_version.
 683           */
 684          do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version );
 685      }
 686  endif;
 687  
 688  /**
 689   * Functions to be called in installation and upgrade scripts.
 690   *
 691   * Contains conditional checks to determine which upgrade scripts to run,
 692   * based on database version and WP version being updated-to.
 693   *
 694   * @ignore
 695   * @since 1.0.1
 696   *
 697   * @global int $wp_current_db_version The old (current) database version.
 698   * @global int $wp_db_version         The new database version.
 699   */
 700  function upgrade_all() {
 701      global $wp_current_db_version, $wp_db_version;
 702  
 703      $wp_current_db_version = (int) __get_option( 'db_version' );
 704  
 705      // We are up to date. Nothing to do.
 706      if ( $wp_db_version === $wp_current_db_version ) {
 707          return;
 708      }
 709  
 710      // If the version is not set in the DB, try to guess the version.
 711      if ( empty( $wp_current_db_version ) ) {
 712          $wp_current_db_version = 0;
 713  
 714          // If the template option exists, we have 1.5.
 715          $template = __get_option( 'template' );
 716          if ( ! empty( $template ) ) {
 717              $wp_current_db_version = 2541;
 718          }
 719      }
 720  
 721      if ( $wp_current_db_version < 6039 ) {
 722          upgrade_230_options_table();
 723      }
 724  
 725      populate_options();
 726  
 727      if ( $wp_current_db_version < 2541 ) {
 728          upgrade_100();
 729          upgrade_101();
 730          upgrade_110();
 731          upgrade_130();
 732      }
 733  
 734      if ( $wp_current_db_version < 3308 ) {
 735          upgrade_160();
 736      }
 737  
 738      if ( $wp_current_db_version < 4772 ) {
 739          upgrade_210();
 740      }
 741  
 742      if ( $wp_current_db_version < 4351 ) {
 743          upgrade_old_slugs();
 744      }
 745  
 746      if ( $wp_current_db_version < 5539 ) {
 747          upgrade_230();
 748      }
 749  
 750      if ( $wp_current_db_version < 6124 ) {
 751          upgrade_230_old_tables();
 752      }
 753  
 754      if ( $wp_current_db_version < 7499 ) {
 755          upgrade_250();
 756      }
 757  
 758      if ( $wp_current_db_version < 7935 ) {
 759          upgrade_252();
 760      }
 761  
 762      if ( $wp_current_db_version < 8201 ) {
 763          upgrade_260();
 764      }
 765  
 766      if ( $wp_current_db_version < 8989 ) {
 767          upgrade_270();
 768      }
 769  
 770      if ( $wp_current_db_version < 10360 ) {
 771          upgrade_280();
 772      }
 773  
 774      if ( $wp_current_db_version < 11958 ) {
 775          upgrade_290();
 776      }
 777  
 778      if ( $wp_current_db_version < 15260 ) {
 779          upgrade_300();
 780      }
 781  
 782      if ( $wp_current_db_version < 19389 ) {
 783          upgrade_330();
 784      }
 785  
 786      if ( $wp_current_db_version < 20080 ) {
 787          upgrade_340();
 788      }
 789  
 790      if ( $wp_current_db_version < 22422 ) {
 791          upgrade_350();
 792      }
 793  
 794      if ( $wp_current_db_version < 25824 ) {
 795          upgrade_370();
 796      }
 797  
 798      if ( $wp_current_db_version < 26148 ) {
 799          upgrade_372();
 800      }
 801  
 802      if ( $wp_current_db_version < 26691 ) {
 803          upgrade_380();
 804      }
 805  
 806      if ( $wp_current_db_version < 29630 ) {
 807          upgrade_400();
 808      }
 809  
 810      if ( $wp_current_db_version < 33055 ) {
 811          upgrade_430();
 812      }
 813  
 814      if ( $wp_current_db_version < 33056 ) {
 815          upgrade_431();
 816      }
 817  
 818      if ( $wp_current_db_version < 35700 ) {
 819          upgrade_440();
 820      }
 821  
 822      if ( $wp_current_db_version < 36686 ) {
 823          upgrade_450();
 824      }
 825  
 826      if ( $wp_current_db_version < 37965 ) {
 827          upgrade_460();
 828      }
 829  
 830      if ( $wp_current_db_version < 44719 ) {
 831          upgrade_510();
 832      }
 833  
 834      if ( $wp_current_db_version < 45744 ) {
 835          upgrade_530();
 836      }
 837  
 838      if ( $wp_current_db_version < 48575 ) {
 839          upgrade_550();
 840      }
 841  
 842      if ( $wp_current_db_version < 49752 ) {
 843          upgrade_560();
 844      }
 845  
 846      if ( $wp_current_db_version < 51917 ) {
 847          upgrade_590();
 848      }
 849  
 850      if ( $wp_current_db_version < 53011 ) {
 851          upgrade_600();
 852      }
 853  
 854      if ( $wp_current_db_version < 55853 ) {
 855          upgrade_630();
 856      }
 857  
 858      if ( $wp_current_db_version < 56657 ) {
 859          upgrade_640();
 860      }
 861  
 862      if ( $wp_current_db_version < 57155 ) {
 863          upgrade_650();
 864      }
 865  
 866      if ( $wp_current_db_version < 58975 ) {
 867          upgrade_670();
 868      }
 869      maybe_disable_link_manager();
 870  
 871      maybe_disable_automattic_widgets();
 872  
 873      update_option( 'db_version', $wp_db_version );
 874      update_option( 'db_upgraded', true );
 875  }
 876  
 877  /**
 878   * Execute changes made in WordPress 1.0.
 879   *
 880   * @ignore
 881   * @since 1.0.0
 882   *
 883   * @global wpdb $wpdb WordPress database abstraction object.
 884   */
 885  function upgrade_100() {
 886      global $wpdb;
 887  
 888      // Get the title and ID of every post, post_name to check if it already has a value.
 889      $posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
 890      if ( $posts ) {
 891          foreach ( $posts as $post ) {
 892              if ( '' === $post->post_name ) {
 893                  $newtitle = sanitize_title( $post->post_title );
 894                  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) );
 895              }
 896          }
 897      }
 898  
 899      $categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" );
 900      foreach ( $categories as $category ) {
 901          if ( '' === $category->category_nicename ) {
 902              $newtitle = sanitize_title( $category->cat_name );
 903              $wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) );
 904          }
 905      }
 906  
 907      $sql = "UPDATE $wpdb->options
 908          SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
 909          WHERE option_name LIKE %s
 910          AND option_value LIKE %s";
 911      $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) );
 912  
 913      $done_ids = $wpdb->get_results( "SELECT DISTINCT post_id FROM $wpdb->post2cat" );
 914      if ( $done_ids ) :
 915          $done_posts = array();
 916          foreach ( $done_ids as $done_id ) :
 917              $done_posts[] = $done_id->post_id;
 918          endforeach;
 919          $catwhere = ' AND ID NOT IN (' . implode( ',', $done_posts ) . ')';
 920      else :
 921          $catwhere = '';
 922      endif;
 923  
 924      $allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
 925      if ( $allposts ) :
 926          foreach ( $allposts as $post ) {
 927              // Check to see if it's already been imported.
 928              $cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
 929              if ( ! $cat && 0 !== (int) $post->post_category ) { // If there's no result.
 930                  $wpdb->insert(
 931                      $wpdb->post2cat,
 932                      array(
 933                          'post_id'     => $post->ID,
 934                          'category_id' => $post->post_category,
 935                      )
 936                  );
 937              }
 938          }
 939      endif;
 940  }
 941  
 942  /**
 943   * Execute changes made in WordPress 1.0.1.
 944   *
 945   * @ignore
 946   * @since 1.0.1
 947   *
 948   * @global wpdb $wpdb WordPress database abstraction object.
 949   */
 950  function upgrade_101() {
 951      global $wpdb;
 952  
 953      // Clean up indices, add a few.
 954      add_clean_index( $wpdb->posts, 'post_name' );
 955      add_clean_index( $wpdb->posts, 'post_status' );
 956      add_clean_index( $wpdb->categories, 'category_nicename' );
 957      add_clean_index( $wpdb->comments, 'comment_approved' );
 958      add_clean_index( $wpdb->comments, 'comment_post_ID' );
 959      add_clean_index( $wpdb->links, 'link_category' );
 960      add_clean_index( $wpdb->links, 'link_visible' );
 961  }
 962  
 963  /**
 964   * Execute changes made in WordPress 1.2.
 965   *
 966   * @ignore
 967   * @since 1.2.0
 968   *
 969   * @global wpdb $wpdb WordPress database abstraction object.
 970   */
 971  function upgrade_110() {
 972      global $wpdb;
 973  
 974      // Set user_nicename.
 975      $users = $wpdb->get_results( "SELECT ID, user_nickname, user_nicename FROM $wpdb->users" );
 976      foreach ( $users as $user ) {
 977          if ( '' === $user->user_nicename ) {
 978              $newname = sanitize_title( $user->user_nickname );
 979              $wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
 980          }
 981      }
 982  
 983      $users = $wpdb->get_results( "SELECT ID, user_pass from $wpdb->users" );
 984      foreach ( $users as $row ) {
 985          if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) {
 986              $wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) );
 987          }
 988      }
 989  
 990      // Get the GMT offset, we'll use that later on.
 991      $all_options = get_alloptions_110();
 992  
 993      $time_difference = $all_options->time_difference;
 994  
 995      $server_time    = time() + gmdate( 'Z' );
 996      $weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS;
 997      $gmt_time       = time();
 998  
 999      $diff_gmt_server       = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
1000      $diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
1001      $diff_gmt_weblogger    = $diff_gmt_server - $diff_weblogger_server;
1002      $gmt_offset            = -$diff_gmt_weblogger;
1003  
1004      // Add a gmt_offset option, with value $gmt_offset.
1005      add_option( 'gmt_offset', $gmt_offset );
1006  
1007      /*
1008       * Check if we already set the GMT fields. If we did, then
1009       * MAX(post_date_gmt) can't be '0000-00-00 00:00:00'.
1010       * <michel_v> I just slapped myself silly for not thinking about it earlier.
1011       */
1012      $got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
1013  
1014      if ( ! $got_gmt_fields ) {
1015  
1016          // Add or subtract time to all dates, to get GMT dates.
1017          $add_hours   = (int) $diff_gmt_weblogger;
1018          $add_minutes = (int) ( 60 * ( $diff_gmt_weblogger - $add_hours ) );
1019          $wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1020          $wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
1021          $wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
1022          $wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1023          $wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
1024      }
1025  }
1026  
1027  /**
1028   * Execute changes made in WordPress 1.5.
1029   *
1030   * @ignore
1031   * @since 1.5.0
1032   *
1033   * @global wpdb $wpdb WordPress database abstraction object.
1034   */
1035  function upgrade_130() {
1036      global $wpdb;
1037  
1038      // Remove extraneous backslashes.
1039      $posts = $wpdb->get_results( "SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts" );
1040      if ( $posts ) {
1041          foreach ( $posts as $post ) {
1042              $post_content = addslashes( deslash( $post->post_content ) );
1043              $post_title   = addslashes( deslash( $post->post_title ) );
1044              $post_excerpt = addslashes( deslash( $post->post_excerpt ) );
1045              if ( empty( $post->guid ) ) {
1046                  $guid = get_permalink( $post->ID );
1047              } else {
1048                  $guid = $post->guid;
1049              }
1050  
1051              $wpdb->update( $wpdb->posts, compact( 'post_title', 'post_content', 'post_excerpt', 'guid' ), array( 'ID' => $post->ID ) );
1052  
1053          }
1054      }
1055  
1056      // Remove extraneous backslashes.
1057      $comments = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments" );
1058      if ( $comments ) {
1059          foreach ( $comments as $comment ) {
1060              $comment_content = deslash( $comment->comment_content );
1061              $comment_author  = deslash( $comment->comment_author );
1062  
1063              $wpdb->update( $wpdb->comments, compact( 'comment_content', 'comment_author' ), array( 'comment_ID' => $comment->comment_ID ) );
1064          }
1065      }
1066  
1067      // Remove extraneous backslashes.
1068      $links = $wpdb->get_results( "SELECT link_id, link_name, link_description FROM $wpdb->links" );
1069      if ( $links ) {
1070          foreach ( $links as $link ) {
1071              $link_name        = deslash( $link->link_name );
1072              $link_description = deslash( $link->link_description );
1073  
1074              $wpdb->update( $wpdb->links, compact( 'link_name', 'link_description' ), array( 'link_id' => $link->link_id ) );
1075          }
1076      }
1077  
1078      $active_plugins = __get_option( 'active_plugins' );
1079  
1080      /*
1081       * If plugins are not stored in an array, they're stored in the old
1082       * newline separated format. Convert to new format.
1083       */
1084      if ( ! is_array( $active_plugins ) ) {
1085          $active_plugins = explode( "\n", trim( $active_plugins ) );
1086          update_option( 'active_plugins', $active_plugins );
1087      }
1088  
1089      // Obsolete tables.
1090      $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' );
1091      $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' );
1092      $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups' );
1093      $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' );
1094  
1095      // Update comments table to use comment_type.
1096      $wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" );
1097      $wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
1098  
1099      // Some versions have multiple duplicate option_name rows with the same values.
1100      $options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
1101      foreach ( $options as $option ) {
1102          if ( $option->dupes > 1 ) { // Could this be done in the query?
1103              $limit    = $option->dupes - 1;
1104              $dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
1105              if ( $dupe_ids ) {
1106                  $dupe_ids = implode( ',', $dupe_ids );
1107                  $wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
1108              }
1109          }
1110      }
1111  
1112      make_site_theme();
1113  }
1114  
1115  /**
1116   * Execute changes made in WordPress 2.0.
1117   *
1118   * @ignore
1119   * @since 2.0.0
1120   *
1121   * @global wpdb $wpdb                  WordPress database abstraction object.
1122   * @global int  $wp_current_db_version The old (current) database version.
1123   */
1124  function upgrade_160() {
1125      global $wpdb, $wp_current_db_version;
1126  
1127      populate_roles_160();
1128  
1129      $users = $wpdb->get_results( "SELECT * FROM $wpdb->users" );
1130      foreach ( $users as $user ) :
1131          if ( ! empty( $user->user_firstname ) ) {
1132              update_user_meta( $user->ID, 'first_name', wp_slash( $user->user_firstname ) );
1133          }
1134          if ( ! empty( $user->user_lastname ) ) {
1135              update_user_meta( $user->ID, 'last_name', wp_slash( $user->user_lastname ) );
1136          }
1137          if ( ! empty( $user->user_nickname ) ) {
1138              update_user_meta( $user->ID, 'nickname', wp_slash( $user->user_nickname ) );
1139          }
1140          if ( ! empty( $user->user_level ) ) {
1141              update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
1142          }
1143          if ( ! empty( $user->user_icq ) ) {
1144              update_user_meta( $user->ID, 'icq', wp_slash( $user->user_icq ) );
1145          }
1146          if ( ! empty( $user->user_aim ) ) {
1147              update_user_meta( $user->ID, 'aim', wp_slash( $user->user_aim ) );
1148          }
1149          if ( ! empty( $user->user_msn ) ) {
1150              update_user_meta( $user->ID, 'msn', wp_slash( $user->user_msn ) );
1151          }
1152          if ( ! empty( $user->user_yim ) ) {
1153              update_user_meta( $user->ID, 'yim', wp_slash( $user->user_icq ) );
1154          }
1155          if ( ! empty( $user->user_description ) ) {
1156              update_user_meta( $user->ID, 'description', wp_slash( $user->user_description ) );
1157          }
1158  
1159          if ( isset( $user->user_idmode ) ) :
1160              $idmode = $user->user_idmode;
1161              if ( 'nickname' === $idmode ) {
1162                  $id = $user->user_nickname;
1163              }
1164              if ( 'login' === $idmode ) {
1165                  $id = $user->user_login;
1166              }
1167              if ( 'firstname' === $idmode ) {
1168                  $id = $user->user_firstname;
1169              }
1170              if ( 'lastname' === $idmode ) {
1171                  $id = $user->user_lastname;
1172              }
1173              if ( 'namefl' === $idmode ) {
1174                  $id = $user->user_firstname . ' ' . $user->user_lastname;
1175              }
1176              if ( 'namelf' === $idmode ) {
1177                  $id = $user->user_lastname . ' ' . $user->user_firstname;
1178              }
1179              if ( ! $idmode ) {
1180                  $id = $user->user_nickname;
1181              }
1182              $wpdb->update( $wpdb->users, array( 'display_name' => $id ), array( 'ID' => $user->ID ) );
1183          endif;
1184  
1185          // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
1186          $caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities' );
1187          if ( empty( $caps ) || defined( 'RESET_CAPS' ) ) {
1188              $level = get_user_meta( $user->ID, $wpdb->prefix . 'user_level', true );
1189              $role  = translate_level_to_role( $level );
1190              update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array( $role => true ) );
1191          }
1192  
1193      endforeach;
1194      $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' );
1195      $wpdb->hide_errors();
1196      foreach ( $old_user_fields as $old ) {
1197          $wpdb->query( "ALTER TABLE $wpdb->users DROP $old" );
1198      }
1199      $wpdb->show_errors();
1200  
1201      // Populate comment_count field of posts table.
1202      $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
1203      if ( is_array( $comments ) ) {
1204          foreach ( $comments as $comment ) {
1205              $wpdb->update( $wpdb->posts, array( 'comment_count' => $comment->c ), array( 'ID' => $comment->comment_post_ID ) );
1206          }
1207      }
1208  
1209      /*
1210       * Some alpha versions used a post status of object instead of attachment
1211       * and put the mime type in post_type instead of post_mime_type.
1212       */
1213      if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
1214          $objects = $wpdb->get_results( "SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'" );
1215          foreach ( $objects as $object ) {
1216              $wpdb->update(
1217                  $wpdb->posts,
1218                  array(
1219                      'post_status'    => 'attachment',
1220                      'post_mime_type' => $object->post_type,
1221                      'post_type'      => '',
1222                  ),
1223                  array( 'ID' => $object->ID )
1224              );
1225  
1226              $meta = get_post_meta( $object->ID, 'imagedata', true );
1227              if ( ! empty( $meta['file'] ) ) {
1228                  update_attached_file( $object->ID, $meta['file'] );
1229              }
1230          }
1231      }
1232  }
1233  
1234  /**
1235   * Execute changes made in WordPress 2.1.
1236   *
1237   * @ignore
1238   * @since 2.1.0
1239   *
1240   * @global int  $wp_current_db_version The old (current) database version.
1241   * @global wpdb $wpdb                  WordPress database abstraction object.
1242   */
1243  function upgrade_210() {
1244      global $wp_current_db_version, $wpdb;
1245  
1246      if ( $wp_current_db_version < 3506 ) {
1247          // Update status and type.
1248          $posts = $wpdb->get_results( "SELECT ID, post_status FROM $wpdb->posts" );
1249  
1250          if ( ! empty( $posts ) ) {
1251              foreach ( $posts as $post ) {
1252                  $status = $post->post_status;
1253                  $type   = 'post';
1254  
1255                  if ( 'static' === $status ) {
1256                      $status = 'publish';
1257                      $type   = 'page';
1258                  } elseif ( 'attachment' === $status ) {
1259                      $status = 'inherit';
1260                      $type   = 'attachment';
1261                  }
1262  
1263                  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID ) );
1264              }
1265          }
1266      }
1267  
1268      if ( $wp_current_db_version < 3845 ) {
1269          populate_roles_210();
1270      }
1271  
1272      if ( $wp_current_db_version < 3531 ) {
1273          // Give future posts a post_status of future.
1274          $now = gmdate( 'Y-m-d H:i:59' );
1275          $wpdb->query( "UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'" );
1276  
1277          $posts = $wpdb->get_results( "SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'" );
1278          if ( ! empty( $posts ) ) {
1279              foreach ( $posts as $post ) {
1280                  wp_schedule_single_event( mysql2date( 'U', $post->post_date, false ), 'publish_future_post', array( $post->ID ) );
1281              }
1282          }
1283      }
1284  }
1285  
1286  /**
1287   * Execute changes made in WordPress 2.3.
1288   *
1289   * @ignore
1290   * @since 2.3.0
1291   *
1292   * @global int  $wp_current_db_version The old (current) database version.
1293   * @global wpdb $wpdb                  WordPress database abstraction object.
1294   */
1295  function upgrade_230() {
1296      global $wp_current_db_version, $wpdb;
1297  
1298      if ( $wp_current_db_version < 5200 ) {
1299          populate_roles_230();
1300      }
1301  
1302      // Convert categories to terms.
1303      $tt_ids     = array();
1304      $have_tags  = false;
1305      $categories = $wpdb->get_results( "SELECT * FROM $wpdb->categories ORDER BY cat_ID" );
1306      foreach ( $categories as $category ) {
1307          $term_id     = (int) $category->cat_ID;
1308          $name        = $category->cat_name;
1309          $description = $category->category_description;
1310          $slug        = $category->category_nicename;
1311          $parent      = $category->category_parent;
1312          $term_group  = 0;
1313  
1314          // Associate terms with the same slug in a term group and make slugs unique.
1315          $exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
1316          if ( $exists ) {
1317              $term_group = $exists[0]->term_group;
1318              $id         = $exists[0]->term_id;
1319              $num        = 2;
1320              do {
1321                  $alt_slug = $slug . "-$num";
1322                  ++$num;
1323                  $slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
1324              } while ( $slug_check );
1325  
1326              $slug = $alt_slug;
1327  
1328              if ( empty( $term_group ) ) {
1329                  $term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group" ) + 1;
1330                  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id ) );
1331              }
1332          }
1333  
1334          $wpdb->query(
1335              $wpdb->prepare(
1336                  "INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES
1337          (%d, %s, %s, %d)",
1338                  $term_id,
1339                  $name,
1340                  $slug,
1341                  $term_group
1342              )
1343          );
1344  
1345          $count = 0;
1346          if ( ! empty( $category->category_count ) ) {
1347              $count    = (int) $category->category_count;
1348              $taxonomy = 'category';
1349              $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
1350              $tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1351          }
1352  
1353          if ( ! empty( $category->link_count ) ) {
1354              $count    = (int) $category->link_count;
1355              $taxonomy = 'link_category';
1356              $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count ) );
1357              $tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1358          }
1359  
1360          if ( ! empty( $category->tag_count ) ) {
1361              $have_tags = true;
1362              $count     = (int) $category->tag_count;
1363              $taxonomy  = 'post_tag';
1364              $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
1365              $tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1366          }
1367  
1368          if ( empty( $count ) ) {
1369              $count    = 0;
1370              $taxonomy = 'category';
1371              $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent', 'count' ) );
1372              $tt_ids[ $term_id ][ $taxonomy ] = (int) $wpdb->insert_id;
1373          }
1374      }
1375  
1376      $select = 'post_id, category_id';
1377      if ( $have_tags ) {
1378          $select .= ', rel_type';
1379      }
1380  
1381      $posts = $wpdb->get_results( "SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id" );
1382      foreach ( $posts as $post ) {
1383          $post_id  = (int) $post->post_id;
1384          $term_id  = (int) $post->category_id;
1385          $taxonomy = 'category';
1386          if ( ! empty( $post->rel_type ) && 'tag' === $post->rel_type ) {
1387              $taxonomy = 'tag';
1388          }
1389          $tt_id = $tt_ids[ $term_id ][ $taxonomy ];
1390          if ( empty( $tt_id ) ) {
1391              continue;
1392          }
1393  
1394          $wpdb->insert(
1395              $wpdb->term_relationships,
1396              array(
1397                  'object_id'        => $post_id,
1398                  'term_taxonomy_id' => $tt_id,
1399              )
1400          );
1401      }
1402  
1403      // < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
1404      if ( $wp_current_db_version < 3570 ) {
1405          /*
1406           * Create link_category terms for link categories. Create a map of link
1407           * category IDs to link_category terms.
1408           */
1409          $link_cat_id_map  = array();
1410          $default_link_cat = 0;
1411          $tt_ids           = array();
1412          $link_cats        = $wpdb->get_results( 'SELECT cat_id, cat_name FROM ' . $wpdb->prefix . 'linkcategories' );
1413          foreach ( $link_cats as $category ) {
1414              $cat_id     = (int) $category->cat_id;
1415              $term_id    = 0;
1416              $name       = wp_slash( $category->cat_name );
1417              $slug       = sanitize_title( $name );
1418              $term_group = 0;
1419  
1420              // Associate terms with the same slug in a term group and make slugs unique.
1421              $exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
1422              if ( $exists ) {
1423                  $term_group = $exists[0]->term_group;
1424                  $term_id    = $exists[0]->term_id;
1425              }
1426  
1427              if ( empty( $term_id ) ) {
1428                  $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) );
1429                  $term_id = (int) $wpdb->insert_id;
1430              }
1431  
1432              $link_cat_id_map[ $cat_id ] = $term_id;
1433              $default_link_cat           = $term_id;
1434  
1435              $wpdb->insert(
1436                  $wpdb->term_taxonomy,
1437                  array(
1438                      'term_id'     => $term_id,
1439                      'taxonomy'    => 'link_category',
1440                      'description' => '',
1441                      'parent'      => 0,
1442                      'count'       => 0,
1443                  )
1444              );
1445              $tt_ids[ $term_id ] = (int) $wpdb->insert_id;
1446          }
1447  
1448          // Associate links to categories.
1449          $links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
1450          if ( ! empty( $links ) ) {
1451              foreach ( $links as $link ) {
1452                  if ( 0 === (int) $link->link_category ) {
1453                      continue;
1454                  }
1455                  if ( ! isset( $link_cat_id_map[ $link->link_category ] ) ) {
1456                      continue;
1457                  }
1458                  $term_id = $link_cat_id_map[ $link->link_category ];
1459                  $tt_id   = $tt_ids[ $term_id ];
1460                  if ( empty( $tt_id ) ) {
1461                      continue;
1462                  }
1463  
1464                  $wpdb->insert(
1465                      $wpdb->term_relationships,
1466                      array(
1467                          'object_id'        => $link->link_id,
1468                          'term_taxonomy_id' => $tt_id,
1469                      )
1470                  );
1471              }
1472          }
1473  
1474          // Set default to the last category we grabbed during the upgrade loop.
1475          update_option( 'default_link_category', $default_link_cat );
1476      } else {
1477          $links = $wpdb->get_results( "SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id" );
1478          foreach ( $links as $link ) {
1479              $link_id  = (int) $link->link_id;
1480              $term_id  = (int) $link->category_id;
1481              $taxonomy = 'link_category';
1482              $tt_id    = $tt_ids[ $term_id ][ $taxonomy ];
1483              if ( empty( $tt_id ) ) {
1484                  continue;
1485              }
1486              $wpdb->insert(
1487                  $wpdb->term_relationships,
1488                  array(
1489                      'object_id'        => $link_id,
1490                      'term_taxonomy_id' => $tt_id,
1491                  )
1492              );
1493          }
1494      }
1495  
1496      if ( $wp_current_db_version < 4772 ) {
1497          // Obsolete linkcategories table.
1498          $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' );
1499      }
1500  
1501      // Recalculate all counts.
1502      $terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" );
1503      foreach ( (array) $terms as $term ) {
1504          if ( 'post_tag' === $term->taxonomy || 'category' === $term->taxonomy ) {
1505              $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id ) );
1506          } else {
1507              $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id ) );
1508          }
1509          $wpdb->update( $wpdb->term_taxonomy, array( 'count' => $count ), array( 'term_taxonomy_id' => $term->term_taxonomy_id ) );
1510      }
1511  }
1512  
1513  /**
1514   * Remove old options from the database.
1515   *
1516   * @ignore
1517   * @since 2.3.0
1518   *
1519   * @global wpdb $wpdb WordPress database abstraction object.
1520   */
1521  function upgrade_230_options_table() {
1522      global $wpdb;
1523      $old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' );
1524      $wpdb->hide_errors();
1525      foreach ( $old_options_fields as $old ) {
1526          $wpdb->query( "ALTER TABLE $wpdb->options DROP $old" );
1527      }
1528      $wpdb->show_errors();
1529  }
1530  
1531  /**
1532   * Remove old categories, link2cat, and post2cat database tables.
1533   *
1534   * @ignore
1535   * @since 2.3.0
1536   *
1537   * @global wpdb $wpdb WordPress database abstraction object.
1538   */
1539  function upgrade_230_old_tables() {
1540      global $wpdb;
1541      $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories' );
1542      $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat' );
1543      $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat' );
1544  }
1545  
1546  /**
1547   * Upgrade old slugs made in version 2.2.
1548   *
1549   * @ignore
1550   * @since 2.2.0
1551   *
1552   * @global wpdb $wpdb WordPress database abstraction object.
1553   */
1554  function upgrade_old_slugs() {
1555      // Upgrade people who were using the Redirect Old Slugs plugin.
1556      global $wpdb;
1557      $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'" );
1558  }
1559  
1560  /**
1561   * Execute changes made in WordPress 2.5.0.
1562   *
1563   * @ignore
1564   * @since 2.5.0
1565   *
1566   * @global int $wp_current_db_version The old (current) database version.
1567   */
1568  function upgrade_250() {
1569      global $wp_current_db_version;
1570  
1571      if ( $wp_current_db_version < 6689 ) {
1572          populate_roles_250();
1573      }
1574  }
1575  
1576  /**
1577   * Execute changes made in WordPress 2.5.2.
1578   *
1579   * @ignore
1580   * @since 2.5.2
1581   *
1582   * @global wpdb $wpdb WordPress database abstraction object.
1583   */
1584  function upgrade_252() {
1585      global $wpdb;
1586  
1587      $wpdb->query( "UPDATE $wpdb->users SET user_activation_key = ''" );
1588  }
1589  
1590  /**
1591   * Execute changes made in WordPress 2.6.
1592   *
1593   * @ignore
1594   * @since 2.6.0
1595   *
1596   * @global int $wp_current_db_version The old (current) database version.
1597   */
1598  function upgrade_260() {
1599      global $wp_current_db_version;
1600  
1601      if ( $wp_current_db_version < 8000 ) {
1602          populate_roles_260();
1603      }
1604  }
1605  
1606  /**
1607   * Execute changes made in WordPress 2.7.
1608   *
1609   * @ignore
1610   * @since 2.7.0
1611   *
1612   * @global int  $wp_current_db_version The old (current) database version.
1613   * @global wpdb $wpdb                  WordPress database abstraction object.
1614   */
1615  function upgrade_270() {
1616      global $wp_current_db_version, $wpdb;
1617  
1618      if ( $wp_current_db_version < 8980 ) {
1619          populate_roles_270();
1620      }
1621  
1622      // Update post_date for unpublished posts with empty timestamp.
1623      if ( $wp_current_db_version < 8921 ) {
1624          $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
1625      }
1626  }
1627  
1628  /**
1629   * Execute changes made in WordPress 2.8.
1630   *
1631   * @ignore
1632   * @since 2.8.0
1633   *
1634   * @global int  $wp_current_db_version The old (current) database version.
1635   * @global wpdb $wpdb                  WordPress database abstraction object.
1636   */
1637  function upgrade_280() {
1638      global $wp_current_db_version, $wpdb;
1639  
1640      if ( $wp_current_db_version < 10360 ) {
1641          populate_roles_280();
1642      }
1643      if ( is_multisite() ) {
1644          $start = 0;
1645          while ( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
1646              foreach ( $rows as $row ) {
1647                  $value = maybe_unserialize( $row->option_value );
1648                  if ( $value === $row->option_value ) {
1649                      $value = stripslashes( $value );
1650                  }
1651                  if ( $value !== $row->option_value ) {
1652                      update_option( $row->option_name, $value );
1653                  }
1654              }
1655              $start += 20;
1656          }
1657          clean_blog_cache( get_current_blog_id() );
1658      }
1659  }
1660  
1661  /**
1662   * Execute changes made in WordPress 2.9.
1663   *
1664   * @ignore
1665   * @since 2.9.0
1666   *
1667   * @global int $wp_current_db_version The old (current) database version.
1668   */
1669  function upgrade_290() {
1670      global $wp_current_db_version;
1671  
1672      if ( $wp_current_db_version < 11958 ) {
1673          /*
1674           * Previously, setting depth to 1 would redundantly disable threading,
1675           * but now 2 is the minimum depth to avoid confusion.
1676           */
1677          if ( 1 === (int) get_option( 'thread_comments_depth' ) ) {
1678              update_option( 'thread_comments_depth', 2 );
1679              update_option( 'thread_comments', 0 );
1680          }
1681      }
1682  }
1683  
1684  /**
1685   * Execute changes made in WordPress 3.0.
1686   *
1687   * @ignore
1688   * @since 3.0.0
1689   *
1690   * @global int  $wp_current_db_version The old (current) database version.
1691   * @global wpdb $wpdb                  WordPress database abstraction object.
1692   */
1693  function upgrade_300() {
1694      global $wp_current_db_version, $wpdb;
1695  
1696      if ( $wp_current_db_version < 15093 ) {
1697          populate_roles_300();
1698      }
1699  
1700      if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) {
1701          add_site_option( 'siteurl', '' );
1702      }
1703  
1704      // 3.0 screen options key name changes.
1705      if ( wp_should_upgrade_global_tables() ) {
1706          $sql    = "DELETE FROM $wpdb->usermeta
1707              WHERE meta_key LIKE %s
1708              OR meta_key LIKE %s
1709              OR meta_key LIKE %s
1710              OR meta_key LIKE %s
1711              OR meta_key LIKE %s
1712              OR meta_key LIKE %s
1713              OR meta_key = 'manageedittagscolumnshidden'
1714              OR meta_key = 'managecategoriescolumnshidden'
1715              OR meta_key = 'manageedit-tagscolumnshidden'
1716              OR meta_key = 'manageeditcolumnshidden'
1717              OR meta_key = 'categories_per_page'
1718              OR meta_key = 'edit_tags_per_page'";
1719          $prefix = $wpdb->esc_like( $wpdb->base_prefix );
1720          $wpdb->query(
1721              $wpdb->prepare(
1722                  $sql,
1723                  $prefix . '%' . $wpdb->esc_like( 'meta-box-hidden' ) . '%',
1724                  $prefix . '%' . $wpdb->esc_like( 'closedpostboxes' ) . '%',
1725                  $prefix . '%' . $wpdb->esc_like( 'manage-' ) . '%' . $wpdb->esc_like( '-columns-hidden' ) . '%',
1726                  $prefix . '%' . $wpdb->esc_like( 'meta-box-order' ) . '%',
1727                  $prefix . '%' . $wpdb->esc_like( 'metaboxorder' ) . '%',
1728                  $prefix . '%' . $wpdb->esc_like( 'screen_layout' ) . '%'
1729              )
1730          );
1731      }
1732  }
1733  
1734  /**
1735   * Execute changes made in WordPress 3.3.
1736   *
1737   * @ignore
1738   * @since 3.3.0
1739   *
1740   * @global int   $wp_current_db_version The old (current) database version.
1741   * @global wpdb  $wpdb                  WordPress database abstraction object.
1742   * @global array $wp_registered_widgets
1743   * @global array $sidebars_widgets
1744   */
1745  function upgrade_330() {
1746      global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets;
1747  
1748      if ( $wp_current_db_version < 19061 && wp_should_upgrade_global_tables() ) {
1749          $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" );
1750      }
1751  
1752      if ( $wp_current_db_version >= 11548 ) {
1753          return;
1754      }
1755  
1756      $sidebars_widgets  = get_option( 'sidebars_widgets', array() );
1757      $_sidebars_widgets = array();
1758  
1759      if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) || empty( $sidebars_widgets ) ) {
1760          $sidebars_widgets['array_version'] = 3;
1761      } elseif ( ! isset( $sidebars_widgets['array_version'] ) ) {
1762          $sidebars_widgets['array_version'] = 1;
1763      }
1764  
1765      switch ( $sidebars_widgets['array_version'] ) {
1766          case 1:
1767              foreach ( (array) $sidebars_widgets as $index => $sidebar ) {
1768                  if ( is_array( $sidebar ) ) {
1769                      foreach ( (array) $sidebar as $i => $name ) {
1770                          $id = strtolower( $name );
1771                          if ( isset( $wp_registered_widgets[ $id ] ) ) {
1772                              $_sidebars_widgets[ $index ][ $i ] = $id;
1773                              continue;
1774                          }
1775  
1776                          $id = sanitize_title( $name );
1777                          if ( isset( $wp_registered_widgets[ $id ] ) ) {
1778                              $_sidebars_widgets[ $index ][ $i ] = $id;
1779                              continue;
1780                          }
1781  
1782                          $found = false;
1783  
1784                          foreach ( $wp_registered_widgets as $widget_id => $widget ) {
1785                              if ( strtolower( $widget['name'] ) === strtolower( $name ) ) {
1786                                  $_sidebars_widgets[ $index ][ $i ] = $widget['id'];
1787  
1788                                  $found = true;
1789                                  break;
1790                              } elseif ( sanitize_title( $widget['name'] ) === sanitize_title( $name ) ) {
1791                                  $_sidebars_widgets[ $index ][ $i ] = $widget['id'];
1792  
1793                                  $found = true;
1794                                  break;
1795                              }
1796                          }
1797  
1798                          if ( $found ) {
1799                              continue;
1800                          }
1801  
1802                          unset( $_sidebars_widgets[ $index ][ $i ] );
1803                      }
1804                  }
1805              }
1806              $_sidebars_widgets['array_version'] = 2;
1807              $sidebars_widgets                   = $_sidebars_widgets;
1808              unset( $_sidebars_widgets );
1809  
1810              // Intentional fall-through to upgrade to the next version.
1811          case 2:
1812              $sidebars_widgets                  = retrieve_widgets();
1813              $sidebars_widgets['array_version'] = 3;
1814              update_option( 'sidebars_widgets', $sidebars_widgets );
1815      }
1816  }
1817  
1818  /**
1819   * Execute changes made in WordPress 3.4.
1820   *
1821   * @ignore
1822   * @since 3.4.0
1823   *
1824   * @global int  $wp_current_db_version The old (current) database version.
1825   * @global wpdb $wpdb                  WordPress database abstraction object.
1826   */
1827  function upgrade_340() {
1828      global $wp_current_db_version, $wpdb;
1829  
1830      if ( $wp_current_db_version < 19798 ) {
1831          $wpdb->hide_errors();
1832          $wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" );
1833          $wpdb->show_errors();
1834      }
1835  
1836      if ( $wp_current_db_version < 19799 ) {
1837          $wpdb->hide_errors();
1838          $wpdb->query( "ALTER TABLE $wpdb->comments DROP INDEX comment_approved" );
1839          $wpdb->show_errors();
1840      }
1841  
1842      if ( $wp_current_db_version < 20022 && wp_should_upgrade_global_tables() ) {
1843          $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" );
1844      }
1845  
1846      if ( $wp_current_db_version < 20080 ) {
1847          if ( 'yes' === $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
1848              $uninstall_plugins = get_option( 'uninstall_plugins' );
1849              delete_option( 'uninstall_plugins' );
1850              add_option( 'uninstall_plugins', $uninstall_plugins, null, false );
1851          }
1852      }
1853  }
1854  
1855  /**
1856   * Execute changes made in WordPress 3.5.
1857   *
1858   * @ignore
1859   * @since 3.5.0
1860   *
1861   * @global int  $wp_current_db_version The old (current) database version.
1862   * @global wpdb $wpdb                  WordPress database abstraction object.
1863   */
1864  function upgrade_350() {
1865      global $wp_current_db_version, $wpdb;
1866  
1867      if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
1868          update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options().
1869      }
1870  
1871      if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) {
1872          $meta_keys = array();
1873          foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) {
1874              if ( str_contains( $name, '-' ) ) {
1875                  $meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page';
1876              }
1877          }
1878          if ( $meta_keys ) {
1879              $meta_keys = implode( "', '", $meta_keys );
1880              $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" );
1881          }
1882      }
1883  
1884      if ( $wp_current_db_version < 22422 ) {
1885          $term = get_term_by( 'slug', 'post-format-standard', 'post_format' );
1886          if ( $term ) {
1887              wp_delete_term( $term->term_id, 'post_format' );
1888          }
1889      }
1890  }
1891  
1892  /**
1893   * Execute changes made in WordPress 3.7.
1894   *
1895   * @ignore
1896   * @since 3.7.0
1897   *
1898   * @global int $wp_current_db_version The old (current) database version.
1899   */
1900  function upgrade_370() {
1901      global $wp_current_db_version;
1902  
1903      if ( $wp_current_db_version < 25824 ) {
1904          wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' );
1905      }
1906  }
1907  
1908  /**
1909   * Execute changes made in WordPress 3.7.2.
1910   *
1911   * @ignore
1912   * @since 3.7.2
1913   *
1914   * @global int $wp_current_db_version The old (current) database version.
1915   */
1916  function upgrade_372() {
1917      global $wp_current_db_version;
1918  
1919      if ( $wp_current_db_version < 26148 ) {
1920          wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
1921      }
1922  }
1923  
1924  /**
1925   * Execute changes made in WordPress 3.8.0.
1926   *
1927   * @ignore
1928   * @since 3.8.0
1929   *
1930   * @global int $wp_current_db_version The old (current) database version.
1931   */
1932  function upgrade_380() {
1933      global $wp_current_db_version;
1934  
1935      if ( $wp_current_db_version < 26691 ) {
1936          deactivate_plugins( array( 'mp6/mp6.php' ), true );
1937      }
1938  }
1939  
1940  /**
1941   * Execute changes made in WordPress 4.0.0.
1942   *
1943   * @ignore
1944   * @since 4.0.0
1945   *
1946   * @global int $wp_current_db_version The old (current) database version.
1947   */
1948  function upgrade_400() {
1949      global $wp_current_db_version;
1950  
1951      if ( $wp_current_db_version < 29630 ) {
1952          if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
1953              if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages(), true ) ) {
1954                  update_option( 'WPLANG', WPLANG );
1955              } else {
1956                  update_option( 'WPLANG', '' );
1957              }
1958          }
1959      }
1960  }
1961  
1962  /**
1963   * Execute changes made in WordPress 4.2.0.
1964   *
1965   * @ignore
1966   * @since 4.2.0
1967   */
1968  function upgrade_420() {}
1969  
1970  /**
1971   * Executes changes made in WordPress 4.3.0.
1972   *
1973   * @ignore
1974   * @since 4.3.0
1975   *
1976   * @global int  $wp_current_db_version The old (current) database version.
1977   * @global wpdb $wpdb                  WordPress database abstraction object.
1978   */
1979  function upgrade_430() {
1980      global $wp_current_db_version, $wpdb;
1981  
1982      if ( $wp_current_db_version < 32364 ) {
1983          upgrade_430_fix_comments();
1984      }
1985  
1986      // Shared terms are split in a separate process.
1987      if ( $wp_current_db_version < 32814 ) {
1988          update_option( 'finished_splitting_shared_terms', 0 );
1989          wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' );
1990      }
1991  
1992      if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
1993          if ( is_multisite() ) {
1994              $tables = $wpdb->tables( 'blog' );
1995          } else {
1996              $tables = $wpdb->tables( 'all' );
1997              if ( ! wp_should_upgrade_global_tables() ) {
1998                  $global_tables = $wpdb->tables( 'global' );
1999                  $tables        = array_diff_assoc( $tables, $global_tables );
2000              }
2001          }
2002  
2003          foreach ( $tables as $table ) {
2004              maybe_convert_table_to_utf8mb4( $table );
2005          }
2006      }
2007  }
2008  
2009  /**
2010   * Executes comments changes made in WordPress 4.3.0.
2011   *
2012   * @ignore
2013   * @since 4.3.0
2014   *
2015   * @global wpdb $wpdb WordPress database abstraction object.
2016   */
2017  function upgrade_430_fix_comments() {
2018      global $wpdb;
2019  
2020      $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
2021  
2022      if ( is_wp_error( $content_length ) ) {
2023          return;
2024      }
2025  
2026      if ( false === $content_length ) {
2027          $content_length = array(
2028              'type'   => 'byte',
2029              'length' => 65535,
2030          );
2031      } elseif ( ! is_array( $content_length ) ) {
2032          $length         = (int) $content_length > 0 ? (int) $content_length : 65535;
2033          $content_length = array(
2034              'type'   => 'byte',
2035              'length' => $length,
2036          );
2037      }
2038  
2039      if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
2040          // Sites with malformed DB schemas are on their own.
2041          return;
2042      }
2043  
2044      $allowed_length = (int) $content_length['length'] - 10;
2045  
2046      $comments = $wpdb->get_results(
2047          "SELECT `comment_ID` FROM `{$wpdb->comments}`
2048              WHERE `comment_date_gmt` > '2015-04-26'
2049              AND LENGTH( `comment_content` ) >= {$allowed_length}
2050              AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )"
2051      );
2052  
2053      foreach ( $comments as $comment ) {
2054          wp_delete_comment( $comment->comment_ID, true );
2055      }
2056  }
2057  
2058  /**
2059   * Executes changes made in WordPress 4.3.1.
2060   *
2061   * @ignore
2062   * @since 4.3.1
2063   */
2064  function upgrade_431() {
2065      // Fix incorrect cron entries for term splitting.
2066      $cron_array = _get_cron_array();
2067      if ( isset( $cron_array['wp_batch_split_terms'] ) ) {
2068          unset( $cron_array['wp_batch_split_terms'] );
2069          _set_cron_array( $cron_array );
2070      }
2071  }
2072  
2073  /**
2074   * Executes changes made in WordPress 4.4.0.
2075   *
2076   * @ignore
2077   * @since 4.4.0
2078   *
2079   * @global int  $wp_current_db_version The old (current) database version.
2080   * @global wpdb $wpdb                  WordPress database abstraction object.
2081   */
2082  function upgrade_440() {
2083      global $wp_current_db_version, $wpdb;
2084  
2085      if ( $wp_current_db_version < 34030 ) {
2086          $wpdb->query( "ALTER TABLE {$wpdb->options} MODIFY option_name VARCHAR(191)" );
2087      }
2088  
2089      // Remove the unused 'add_users' role.
2090      $roles = wp_roles();
2091      foreach ( $roles->role_objects as $role ) {
2092          if ( $role->has_cap( 'add_users' ) ) {
2093              $role->remove_cap( 'add_users' );
2094          }
2095      }
2096  }
2097  
2098  /**
2099   * Executes changes made in WordPress 4.5.0.
2100   *
2101   * @ignore
2102   * @since 4.5.0
2103   *
2104   * @global int  $wp_current_db_version The old (current) database version.
2105   * @global wpdb $wpdb                  WordPress database abstraction object.
2106   */
2107  function upgrade_450() {
2108      global $wp_current_db_version, $wpdb;
2109  
2110      if ( $wp_current_db_version < 36180 ) {
2111          wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
2112      }
2113  
2114      // Remove unused email confirmation options, moved to usermeta.
2115      if ( $wp_current_db_version < 36679 && is_multisite() ) {
2116          $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^[0-9]+_new_email$'" );
2117      }
2118  
2119      // Remove unused user setting for wpLink.
2120      delete_user_setting( 'wplink' );
2121  }
2122  
2123  /**
2124   * Executes changes made in WordPress 4.6.0.
2125   *
2126   * @ignore
2127   * @since 4.6.0
2128   *
2129   * @global int $wp_current_db_version The old (current) database version.
2130   */
2131  function upgrade_460() {
2132      global $wp_current_db_version;
2133  
2134      // Remove unused post meta.
2135      if ( $wp_current_db_version < 37854 ) {
2136          delete_post_meta_by_key( '_post_restored_from' );
2137      }
2138  
2139      // Remove plugins with callback as an array object/method as the uninstall hook, see #13786.
2140      if ( $wp_current_db_version < 37965 ) {
2141          $uninstall_plugins = get_option( 'uninstall_plugins', array() );
2142  
2143          if ( ! empty( $uninstall_plugins ) ) {
2144              foreach ( $uninstall_plugins as $basename => $callback ) {
2145                  if ( is_array( $callback ) && is_object( $callback[0] ) ) {
2146                      unset( $uninstall_plugins[ $basename ] );
2147                  }
2148              }
2149  
2150              update_option( 'uninstall_plugins', $uninstall_plugins );
2151          }
2152      }
2153  }
2154  
2155  /**
2156   * Executes changes made in WordPress 5.0.0.
2157   *
2158   * @ignore
2159   * @since 5.0.0
2160   * @deprecated 5.1.0
2161   */
2162  function upgrade_500() {
2163  }
2164  
2165  /**
2166   * Executes changes made in WordPress 5.1.0.
2167   *
2168   * @ignore
2169   * @since 5.1.0
2170   */
2171  function upgrade_510() {
2172      delete_site_option( 'upgrade_500_was_gutenberg_active' );
2173  }
2174  
2175  /**
2176   * Executes changes made in WordPress 5.3.0.
2177   *
2178   * @ignore
2179   * @since 5.3.0
2180   */
2181  function upgrade_530() {
2182      /*
2183       * The `admin_email_lifespan` option may have been set by an admin that just logged in,
2184       * saw the verification screen, clicked on a button there, and is now upgrading the db,
2185       * or by populate_options() that is called earlier in upgrade_all().
2186       * In the second case `admin_email_lifespan` should be reset so the verification screen
2187       * is shown next time an admin logs in.
2188       */
2189      if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) {
2190          update_option( 'admin_email_lifespan', 0 );
2191      }
2192  }
2193  
2194  /**
2195   * Executes changes made in WordPress 5.5.0.
2196   *
2197   * @ignore
2198   * @since 5.5.0
2199   *
2200   * @global int $wp_current_db_version The old (current) database version.
2201   */
2202  function upgrade_550() {
2203      global $wp_current_db_version;
2204  
2205      if ( $wp_current_db_version < 48121 ) {
2206          $comment_previously_approved = get_option( 'comment_whitelist', '' );
2207          update_option( 'comment_previously_approved', $comment_previously_approved );
2208          delete_option( 'comment_whitelist' );
2209      }
2210  
2211      if ( $wp_current_db_version < 48575 ) {
2212          // Use more clear and inclusive language.
2213          $disallowed_list = get_option( 'blacklist_keys' );
2214  
2215          /*
2216           * This option key was briefly renamed `blocklist_keys`.
2217           * Account for sites that have this key present when the original key does not exist.
2218           */
2219          if ( false === $disallowed_list ) {
2220              $disallowed_list = get_option( 'blocklist_keys' );
2221          }
2222  
2223          update_option( 'disallowed_keys', $disallowed_list );
2224          delete_option( 'blacklist_keys' );
2225          delete_option( 'blocklist_keys' );
2226      }
2227  
2228      if ( $wp_current_db_version < 48748 ) {
2229          update_option( 'finished_updating_comment_type', 0 );
2230          wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
2231      }
2232  }
2233  
2234  /**
2235   * Executes changes made in WordPress 5.6.0.
2236   *
2237   * @ignore
2238   * @since 5.6.0
2239   *
2240   * @global int  $wp_current_db_version The old (current) database version.
2241   * @global wpdb $wpdb                  WordPress database abstraction object.
2242   */
2243  function upgrade_560() {
2244      global $wp_current_db_version, $wpdb;
2245  
2246      if ( $wp_current_db_version < 49572 ) {
2247          /*
2248           * Clean up the `post_category` column removed from schema in version 2.8.0.
2249           * Its presence may conflict with `WP_Post::__get()`.
2250           */
2251          $post_category_exists = $wpdb->get_var( "SHOW COLUMNS FROM $wpdb->posts LIKE 'post_category'" );
2252          if ( ! is_null( $post_category_exists ) ) {
2253              $wpdb->query( "ALTER TABLE $wpdb->posts DROP COLUMN `post_category`" );
2254          }
2255  
2256          /*
2257           * When upgrading from WP < 5.6.0 set the core major auto-updates option to `unset` by default.
2258           * This overrides the same option from populate_options() that is intended for new installs.
2259           * See https://core.trac.wordpress.org/ticket/51742.
2260           */
2261          update_option( 'auto_update_core_major', 'unset' );
2262      }
2263  
2264      if ( $wp_current_db_version < 49632 ) {
2265          /*
2266           * Regenerate the .htaccess file to add the `HTTP_AUTHORIZATION` rewrite rule.
2267           * See https://core.trac.wordpress.org/ticket/51723.
2268           */
2269          save_mod_rewrite_rules();
2270      }
2271  
2272      if ( $wp_current_db_version < 49735 ) {
2273          delete_transient( 'dirsize_cache' );
2274      }
2275  
2276      if ( $wp_current_db_version < 49752 ) {
2277          $results = $wpdb->get_results(
2278              $wpdb->prepare(
2279                  "SELECT 1 FROM {$wpdb->usermeta} WHERE meta_key = %s LIMIT 1",
2280                  WP_Application_Passwords::USERMETA_KEY_APPLICATION_PASSWORDS
2281              )
2282          );
2283  
2284          if ( ! empty( $results ) ) {
2285              $network_id = get_main_network_id();
2286              update_network_option( $network_id, WP_Application_Passwords::OPTION_KEY_IN_USE, 1 );
2287          }
2288      }
2289  }
2290  
2291  /**
2292   * Executes changes made in WordPress 5.9.0.
2293   *
2294   * @ignore
2295   * @since 5.9.0
2296   *
2297   * @global int $wp_current_db_version The old (current) database version.
2298   */
2299  function upgrade_590() {
2300      global $wp_current_db_version;
2301  
2302      if ( $wp_current_db_version < 51917 ) {
2303          $crons = _get_cron_array();
2304  
2305          if ( $crons && is_array( $crons ) ) {
2306              // Remove errant `false` values, see #53950, #54906.
2307              $crons = array_filter( $crons );
2308              _set_cron_array( $crons );
2309          }
2310      }
2311  }
2312  
2313  /**
2314   * Executes changes made in WordPress 6.0.0.
2315   *
2316   * @ignore
2317   * @since 6.0.0
2318   *
2319   * @global int $wp_current_db_version The old (current) database version.
2320   */
2321  function upgrade_600() {
2322      global $wp_current_db_version;
2323  
2324      if ( $wp_current_db_version < 53011 ) {
2325          wp_update_user_counts();
2326      }
2327  }
2328  
2329  /**
2330   * Executes changes made in WordPress 6.3.0.
2331   *
2332   * @ignore
2333   * @since 6.3.0
2334   *
2335   * @global int $wp_current_db_version The old (current) database version.
2336   */
2337  function upgrade_630() {
2338      global $wp_current_db_version;
2339  
2340      if ( $wp_current_db_version < 55853 ) {
2341          if ( ! is_multisite() ) {
2342              // Replace non-autoload option can_compress_scripts with autoload option, see #55270
2343              $can_compress_scripts = get_option( 'can_compress_scripts', false );
2344              if ( false !== $can_compress_scripts ) {
2345                  delete_option( 'can_compress_scripts' );
2346                  add_option( 'can_compress_scripts', $can_compress_scripts, '', true );
2347              }
2348          }
2349      }
2350  }
2351  
2352  /**
2353   * Executes changes made in WordPress 6.4.0.
2354   *
2355   * @ignore
2356   * @since 6.4.0
2357   *
2358   * @global int $wp_current_db_version The old (current) database version.
2359   */
2360  function upgrade_640() {
2361      global $wp_current_db_version;
2362  
2363      if ( $wp_current_db_version < 56657 ) {
2364          // Enable attachment pages.
2365          update_option( 'wp_attachment_pages_enabled', 1 );
2366  
2367          // Remove the wp_https_detection cron. Https status is checked directly in an async Site Health check.
2368          $scheduled = wp_get_scheduled_event( 'wp_https_detection' );
2369          if ( $scheduled ) {
2370              wp_clear_scheduled_hook( 'wp_https_detection' );
2371          }
2372      }
2373  }
2374  
2375  /**
2376   * Executes changes made in WordPress 6.5.0.
2377   *
2378   * @ignore
2379   * @since 6.5.0
2380   *
2381   * @global int  $wp_current_db_version The old (current) database version.
2382   * @global wpdb $wpdb                  WordPress database abstraction object.
2383   */
2384  function upgrade_650() {
2385      global $wp_current_db_version, $wpdb;
2386  
2387      if ( $wp_current_db_version < 57155 ) {
2388          $stylesheet = get_stylesheet();
2389  
2390          // Set autoload=no for all themes except the current one.
2391          $theme_mods_options = $wpdb->get_col(
2392              $wpdb->prepare(
2393                  "SELECT option_name FROM $wpdb->options WHERE autoload = 'yes' AND option_name != %s AND option_name LIKE %s",
2394                  "theme_mods_$stylesheet",
2395                  $wpdb->esc_like( 'theme_mods_' ) . '%'
2396              )
2397          );
2398  
2399          $autoload = array_fill_keys( $theme_mods_options, false );
2400          wp_set_option_autoload_values( $autoload );
2401      }
2402  }
2403  /**
2404   * Executes changes made in WordPress 6.7.0.
2405   *
2406   * @ignore
2407   * @since 6.7.0
2408   *
2409   * @global int  $wp_current_db_version The old (current) database version.
2410   */
2411  function upgrade_670() {
2412      global $wp_current_db_version;
2413  
2414      if ( $wp_current_db_version < 58975 ) {
2415          $options = array(
2416              'recently_activated',
2417              '_wp_suggested_policy_text_has_changed',
2418              'dashboard_widget_options',
2419              'ftp_credentials',
2420              'adminhash',
2421              'nav_menu_options',
2422              'wp_force_deactivated_plugins',
2423              'delete_blog_hash',
2424              'allowedthemes',
2425              'recovery_keys',
2426              'https_detection_errors',
2427              'fresh_site',
2428          );
2429  
2430          wp_set_options_autoload( $options, false );
2431      }
2432  }
2433  /**
2434   * Executes network-level upgrade routines.
2435   *
2436   * @since 3.0.0
2437   *
2438   * @global int  $wp_current_db_version The old (current) database version.
2439   * @global wpdb $wpdb                  WordPress database abstraction object.
2440   */
2441  function upgrade_network() {
2442      global $wp_current_db_version, $wpdb;
2443  
2444      // Always clear expired transients.
2445      delete_expired_transients( true );
2446  
2447      // 2.8.0
2448      if ( $wp_current_db_version < 11549 ) {
2449          $wpmu_sitewide_plugins   = get_site_option( 'wpmu_sitewide_plugins' );
2450          $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
2451          if ( $wpmu_sitewide_plugins ) {
2452              if ( ! $active_sitewide_plugins ) {
2453                  $sitewide_plugins = (array) $wpmu_sitewide_plugins;
2454              } else {
2455                  $sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins );
2456              }
2457  
2458              update_site_option( 'active_sitewide_plugins', $sitewide_plugins );
2459          }
2460          delete_site_option( 'wpmu_sitewide_plugins' );
2461          delete_site_option( 'deactivated_sitewide_plugins' );
2462  
2463          $start = 0;
2464          while ( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) {
2465              foreach ( $rows as $row ) {
2466                  $value = $row->meta_value;
2467                  if ( ! @unserialize( $value ) ) {
2468                      $value = stripslashes( $value );
2469                  }
2470                  if ( $value !== $row->meta_value ) {
2471                      update_site_option( $row->meta_key, $value );
2472                  }
2473              }
2474              $start += 20;
2475          }
2476      }
2477  
2478      // 3.0.0
2479      if ( $wp_current_db_version < 13576 ) {
2480          update_site_option( 'global_terms_enabled', '1' );
2481      }
2482  
2483      // 3.3.0
2484      if ( $wp_current_db_version < 19390 ) {
2485          update_site_option( 'initial_db_version', $wp_current_db_version );
2486      }
2487  
2488      if ( $wp_current_db_version < 19470 ) {
2489          if ( false === get_site_option( 'active_sitewide_plugins' ) ) {
2490              update_site_option( 'active_sitewide_plugins', array() );
2491          }
2492      }
2493  
2494      // 3.4.0
2495      if ( $wp_current_db_version < 20148 ) {
2496          // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
2497          $allowedthemes  = get_site_option( 'allowedthemes' );
2498          $allowed_themes = get_site_option( 'allowed_themes' );
2499          if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) {
2500              $converted = array();
2501              $themes    = wp_get_themes();
2502              foreach ( $themes as $stylesheet => $theme_data ) {
2503                  if ( isset( $allowed_themes[ $theme_data->get( 'Name' ) ] ) ) {
2504                      $converted[ $stylesheet ] = true;
2505                  }
2506              }
2507              update_site_option( 'allowedthemes', $converted );
2508              delete_site_option( 'allowed_themes' );
2509          }
2510      }
2511  
2512      // 3.5.0
2513      if ( $wp_current_db_version < 21823 ) {
2514          update_site_option( 'ms_files_rewriting', '1' );
2515      }
2516  
2517      // 3.5.2
2518      if ( $wp_current_db_version < 24448 ) {
2519          $illegal_names = get_site_option( 'illegal_names' );
2520          if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) {
2521              $illegal_name  = reset( $illegal_names );
2522              $illegal_names = explode( ' ', $illegal_name );
2523              update_site_option( 'illegal_names', $illegal_names );
2524          }
2525      }
2526  
2527      // 4.2.0
2528      if ( $wp_current_db_version < 31351 && 'utf8mb4' === $wpdb->charset ) {
2529          if ( wp_should_upgrade_global_tables() ) {
2530              $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2531              $wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
2532              $wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2533              $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
2534  
2535              $tables = $wpdb->tables( 'global' );
2536  
2537              // sitecategories may not exist.
2538              if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) {
2539                  unset( $tables['sitecategories'] );
2540              }
2541  
2542              foreach ( $tables as $table ) {
2543                  maybe_convert_table_to_utf8mb4( $table );
2544              }
2545          }
2546      }
2547  
2548      // 4.3.0
2549      if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
2550          if ( wp_should_upgrade_global_tables() ) {
2551              $upgrade = false;
2552              $indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" );
2553              foreach ( $indexes as $index ) {
2554                  if ( 'domain_path' === $index->Key_name && 'domain' === $index->Column_name && '140' !== $index->Sub_part ) {
2555                      $upgrade = true;
2556                      break;
2557                  }
2558              }
2559  
2560              if ( $upgrade ) {
2561                  $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
2562              }
2563  
2564              $tables = $wpdb->tables( 'global' );
2565  
2566              // sitecategories may not exist.
2567              if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) {
2568                  unset( $tables['sitecategories'] );
2569              }
2570  
2571              foreach ( $tables as $table ) {
2572                  maybe_convert_table_to_utf8mb4( $table );
2573              }
2574          }
2575      }
2576  
2577      // 5.1.0
2578      if ( $wp_current_db_version < 44467 ) {
2579          $network_id = get_main_network_id();
2580          delete_network_option( $network_id, 'site_meta_supported' );
2581          is_site_meta_supported();
2582      }
2583  }
2584  
2585  //
2586  // General functions we use to actually do stuff.
2587  //
2588  
2589  /**
2590   * Creates a table in the database, if it doesn't already exist.
2591   *
2592   * This method checks for an existing database table and creates a new one if it's not
2593   * already present. It doesn't rely on MySQL's "IF NOT EXISTS" statement, but chooses
2594   * to query all tables first and then run the SQL statement creating the table.
2595   *
2596   * @since 1.0.0
2597   *
2598   * @global wpdb $wpdb WordPress database abstraction object.
2599   *
2600   * @param string $table_name Database table name.
2601   * @param string $create_ddl SQL statement to create table.
2602   * @return bool True on success or if the table already exists. False on failure.
2603   */
2604  function maybe_create_table( $table_name, $create_ddl ) {
2605      global $wpdb;
2606  
2607      $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
2608  
2609      if ( $wpdb->get_var( $query ) === $table_name ) {
2610          return true;
2611      }
2612  
2613      // Didn't find it, so try to create it.
2614      $wpdb->query( $create_ddl );
2615  
2616      // We cannot directly tell that whether this succeeded!
2617      if ( $wpdb->get_var( $query ) === $table_name ) {
2618          return true;
2619      }
2620  
2621      return false;
2622  }
2623  
2624  /**
2625   * Drops a specified index from a table.
2626   *
2627   * @since 1.0.1
2628   *
2629   * @global wpdb $wpdb WordPress database abstraction object.
2630   *
2631   * @param string $table Database table name.
2632   * @param string $index Index name to drop.
2633   * @return true True, when finished.
2634   */
2635  function drop_index( $table, $index ) {
2636      global $wpdb;
2637  
2638      $wpdb->hide_errors();
2639  
2640      $wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" );
2641  
2642      // Now we need to take out all the extra ones we may have created.
2643      for ( $i = 0; $i < 25; $i++ ) {
2644          $wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" );
2645      }
2646  
2647      $wpdb->show_errors();
2648  
2649      return true;
2650  }
2651  
2652  /**
2653   * Adds an index to a specified table.
2654   *
2655   * @since 1.0.1
2656   *
2657   * @global wpdb $wpdb WordPress database abstraction object.
2658   *
2659   * @param string $table Database table name.
2660   * @param string $index Database table index column.
2661   * @return true True, when done with execution.
2662   */
2663  function add_clean_index( $table, $index ) {
2664      global $wpdb;
2665  
2666      drop_index( $table, $index );
2667      $wpdb->query( "ALTER TABLE `$table` ADD INDEX ( `$index` )" );
2668  
2669      return true;
2670  }
2671  
2672  /**
2673   * Adds column to a database table, if it doesn't already exist.
2674   *
2675   * @since 1.3.0
2676   *
2677   * @global wpdb $wpdb WordPress database abstraction object.
2678   *
2679   * @param string $table_name  Database table name.
2680   * @param string $column_name Table column name.
2681   * @param string $create_ddl  SQL statement to add column.
2682   * @return bool True on success or if the column already exists. False on failure.
2683   */
2684  function maybe_add_column( $table_name, $column_name, $create_ddl ) {
2685      global $wpdb;
2686  
2687      foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
2688          if ( $column === $column_name ) {
2689              return true;
2690          }
2691      }
2692  
2693      // Didn't find it, so try to create it.
2694      $wpdb->query( $create_ddl );
2695  
2696      // We cannot directly tell that whether this succeeded!
2697      foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
2698          if ( $column === $column_name ) {
2699              return true;
2700          }
2701      }
2702  
2703      return false;
2704  }
2705  
2706  /**
2707   * If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4.
2708   *
2709   * @since 4.2.0
2710   *
2711   * @global wpdb $wpdb WordPress database abstraction object.
2712   *
2713   * @param string $table The table to convert.
2714   * @return bool True if the table was converted, false if it wasn't.
2715   */
2716  function maybe_convert_table_to_utf8mb4( $table ) {
2717      global $wpdb;
2718  
2719      $results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" );
2720      if ( ! $results ) {
2721          return false;
2722      }
2723  
2724      foreach ( $results as $column ) {
2725          if ( $column->Collation ) {
2726              list( $charset ) = explode( '_', $column->Collation );
2727              $charset         = strtolower( $charset );
2728              if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
2729                  // Don't upgrade tables that have non-utf8 columns.
2730                  return false;
2731              }
2732          }
2733      }
2734  
2735      $table_details = $wpdb->get_row( "SHOW TABLE STATUS LIKE '$table'" );
2736      if ( ! $table_details ) {
2737          return false;
2738      }
2739  
2740      list( $table_charset ) = explode( '_', $table_details->Collation );
2741      $table_charset         = strtolower( $table_charset );
2742      if ( 'utf8mb4' === $table_charset ) {
2743          return true;
2744      }
2745  
2746      return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
2747  }
2748  
2749  /**
2750   * Retrieve all options as it was for 1.2.
2751   *
2752   * @since 1.2.0
2753   *
2754   * @global wpdb $wpdb WordPress database abstraction object.
2755   *
2756   * @return stdClass List of options.
2757   */
2758  function get_alloptions_110() {
2759      global $wpdb;
2760      $all_options = new stdClass();
2761      $options     = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
2762      if ( $options ) {
2763          foreach ( $options as $option ) {
2764              if ( 'siteurl' === $option->option_name || 'home' === $option->option_name || 'category_base' === $option->option_name ) {
2765                  $option->option_value = untrailingslashit( $option->option_value );
2766              }
2767              $all_options->{$option->option_name} = stripslashes( $option->option_value );
2768          }
2769      }
2770      return $all_options;
2771  }
2772  
2773  /**
2774   * Utility version of get_option that is private to installation/upgrade.
2775   *
2776   * @ignore
2777   * @since 1.5.1
2778   * @access private
2779   *
2780   * @global wpdb $wpdb WordPress database abstraction object.
2781   *
2782   * @param string $setting Option name.
2783   * @return mixed
2784   */
2785  function __get_option( $setting ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
2786      global $wpdb;
2787  
2788      if ( 'home' === $setting && defined( 'WP_HOME' ) ) {
2789          return untrailingslashit( WP_HOME );
2790      }
2791  
2792      if ( 'siteurl' === $setting && defined( 'WP_SITEURL' ) ) {
2793          return untrailingslashit( WP_SITEURL );
2794      }
2795  
2796      $option = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) );
2797  
2798      if ( 'home' === $setting && ! $option ) {
2799          return __get_option( 'siteurl' );
2800      }
2801  
2802      if ( in_array( $setting, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
2803          $option = untrailingslashit( $option );
2804      }
2805  
2806      return maybe_unserialize( $option );
2807  }
2808  
2809  /**
2810   * Filters for content to remove unnecessary slashes.
2811   *
2812   * @since 1.5.0
2813   *
2814   * @param string $content The content to modify.
2815   * @return string The de-slashed content.
2816   */
2817  function deslash( $content ) {
2818      // Note: \\\ inside a regex denotes a single backslash.
2819  
2820      /*
2821       * Replace one or more backslashes followed by a single quote with
2822       * a single quote.
2823       */
2824      $content = preg_replace( "/\\\+'/", "'", $content );
2825  
2826      /*
2827       * Replace one or more backslashes followed by a double quote with
2828       * a double quote.
2829       */
2830      $content = preg_replace( '/\\\+"/', '"', $content );
2831  
2832      // Replace one or more backslashes with one backslash.
2833      $content = preg_replace( '/\\\+/', '\\', $content );
2834  
2835      return $content;
2836  }
2837  
2838  /**
2839   * Modifies the database based on specified SQL statements.
2840   *
2841   * Useful for creating new tables and updating existing tables to a new structure.
2842   *
2843   * @since 1.5.0
2844   * @since 6.1.0 Ignores display width for integer data types on MySQL 8.0.17 or later,
2845   *              to match MySQL behavior. Note: This does not affect MariaDB.
2846   *
2847   * @global wpdb $wpdb WordPress database abstraction object.
2848   *
2849   * @param string[]|string $queries Optional. The query to run. Can be multiple queries
2850   *                                 in an array, or a string of queries separated by
2851   *                                 semicolons. Default empty string.
2852   * @param bool            $execute Optional. Whether or not to execute the query right away.
2853   *                                 Default true.
2854   * @return array Strings containing the results of the various update queries.
2855   */
2856  function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
2857      global $wpdb;
2858  
2859      if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) {
2860          $queries = wp_get_db_schema( $queries );
2861      }
2862  
2863      // Separate individual queries into an array.
2864      if ( ! is_array( $queries ) ) {
2865          $queries = explode( ';', $queries );
2866          $queries = array_filter( $queries );
2867      }
2868  
2869      /**
2870       * Filters the dbDelta SQL queries.
2871       *
2872       * @since 3.3.0
2873       *
2874       * @param string[] $queries An array of dbDelta SQL queries.
2875       */
2876      $queries = apply_filters( 'dbdelta_queries', $queries );
2877  
2878      $cqueries   = array(); // Creation queries.
2879      $iqueries   = array(); // Insertion queries.
2880      $for_update = array();
2881  
2882      // Create a tablename index for an array ($cqueries) of recognized query types.
2883      foreach ( $queries as $qry ) {
2884          if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
2885              $cqueries[ trim( $matches[1], '`' ) ] = $qry;
2886              $for_update[ $matches[1] ]            = 'Created table ' . $matches[1];
2887              continue;
2888          }
2889  
2890          if ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) {
2891              array_unshift( $cqueries, $qry );
2892              continue;
2893          }
2894  
2895          if ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) {
2896              $iqueries[] = $qry;
2897              continue;
2898          }
2899  
2900          if ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
2901              $iqueries[] = $qry;
2902              continue;
2903          }
2904      }
2905  
2906      /**
2907       * Filters the dbDelta SQL queries for creating tables and/or databases.
2908       *
2909       * Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
2910       *
2911       * @since 3.3.0
2912       *
2913       * @param string[] $cqueries An array of dbDelta create SQL queries.
2914       */
2915      $cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
2916  
2917      /**
2918       * Filters the dbDelta SQL queries for inserting or updating.
2919       *
2920       * Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
2921       *
2922       * @since 3.3.0
2923       *
2924       * @param string[] $iqueries An array of dbDelta insert or update SQL queries.
2925       */
2926      $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
2927  
2928      $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' );
2929      $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' );
2930      $int_fields  = array( 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint' );
2931  
2932      $global_tables  = $wpdb->tables( 'global' );
2933      $db_version     = $wpdb->db_version();
2934      $db_server_info = $wpdb->db_server_info();
2935  
2936      foreach ( $cqueries as $table => $qry ) {
2937          // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
2938          if ( in_array( $table, $global_tables, true ) && ! wp_should_upgrade_global_tables() ) {
2939              unset( $cqueries[ $table ], $for_update[ $table ] );
2940              continue;
2941          }
2942  
2943          // Fetch the table column structure from the database.
2944          $suppress    = $wpdb->suppress_errors();
2945          $tablefields = $wpdb->get_results( "DESCRIBE {$table};" );
2946          $wpdb->suppress_errors( $suppress );
2947  
2948          if ( ! $tablefields ) {
2949              continue;
2950          }
2951  
2952          // Clear the field and index arrays.
2953          $cfields                  = array();
2954          $indices                  = array();
2955          $indices_without_subparts = array();
2956  
2957          // Get all of the field names in the query from between the parentheses.
2958          preg_match( '|\((.*)\)|ms', $qry, $match2 );
2959          $qryline = trim( $match2[1] );
2960  
2961          // Separate field lines into an array.
2962          $flds = explode( "\n", $qryline );
2963  
2964          // For every field line specified in the query.
2965          foreach ( $flds as $fld ) {
2966              $fld = trim( $fld, " \t\n\r\0\x0B," ); // Default trim characters, plus ','.
2967  
2968              // Extract the field name.
2969              preg_match( '|^([^ ]*)|', $fld, $fvals );
2970              $fieldname            = trim( $fvals[1], '`' );
2971              $fieldname_lowercased = strtolower( $fieldname );
2972  
2973              // Verify the found field name.
2974              $validfield = true;
2975              switch ( $fieldname_lowercased ) {
2976                  case '':
2977                  case 'primary':
2978                  case 'index':
2979                  case 'fulltext':
2980                  case 'unique':
2981                  case 'key':
2982                  case 'spatial':
2983                      $validfield = false;
2984  
2985                      /*
2986                       * Normalize the index definition.
2987                       *
2988                       * This is done so the definition can be compared against the result of a
2989                       * `SHOW INDEX FROM $table_name` query which returns the current table
2990                       * index information.
2991                       */
2992  
2993                      // Extract type, name and columns from the definition.
2994                      preg_match(
2995                          '/^
2996                              (?P<index_type>             # 1) Type of the index.
2997                                  PRIMARY\s+KEY|(?:UNIQUE|FULLTEXT|SPATIAL)\s+(?:KEY|INDEX)|KEY|INDEX
2998                              )
2999                              \s+                         # Followed by at least one white space character.
3000                              (?:                         # Name of the index. Optional if type is PRIMARY KEY.
3001                                  `?                      # Name can be escaped with a backtick.
3002                                      (?P<index_name>     # 2) Name of the index.
3003                                          (?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+
3004                                      )
3005                                  `?                      # Name can be escaped with a backtick.
3006                                  \s+                     # Followed by at least one white space character.
3007                              )*
3008                              \(                          # Opening bracket for the columns.
3009                                  (?P<index_columns>
3010                                      .+?                 # 3) Column names, index prefixes, and orders.
3011                                  )
3012                              \)                          # Closing bracket for the columns.
3013                          $/imx',
3014                          $fld,
3015                          $index_matches
3016                      );
3017  
3018                      // Uppercase the index type and normalize space characters.
3019                      $index_type = strtoupper( preg_replace( '/\s+/', ' ', trim( $index_matches['index_type'] ) ) );
3020  
3021                      // 'INDEX' is a synonym for 'KEY', standardize on 'KEY'.
3022                      $index_type = str_replace( 'INDEX', 'KEY', $index_type );
3023  
3024                      // Escape the index name with backticks. An index for a primary key has no name.
3025                      $index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . strtolower( $index_matches['index_name'] ) . '`';
3026  
3027                      // Parse the columns. Multiple columns are separated by a comma.
3028                      $index_columns                  = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) );
3029                      $index_columns_without_subparts = $index_columns;
3030  
3031                      // Normalize columns.
3032                      foreach ( $index_columns as $id => &$index_column ) {
3033                          // Extract column name and number of indexed characters (sub_part).
3034                          preg_match(
3035                              '/
3036                                  `?                      # Name can be escaped with a backtick.
3037                                      (?P<column_name>    # 1) Name of the column.
3038                                          (?:[0-9a-zA-Z$_-]|[\xC2-\xDF][\x80-\xBF])+
3039                                      )
3040                                  `?                      # Name can be escaped with a backtick.
3041                                  (?:                     # Optional sub part.
3042                                      \s*                 # Optional white space character between name and opening bracket.
3043                                      \(                  # Opening bracket for the sub part.
3044                                          \s*             # Optional white space character after opening bracket.
3045                                          (?P<sub_part>
3046                                              \d+         # 2) Number of indexed characters.
3047                                          )
3048                                          \s*             # Optional white space character before closing bracket.
3049                                      \)                  # Closing bracket for the sub part.
3050                                  )?
3051                              /x',
3052                              $index_column,
3053                              $index_column_matches
3054                          );
3055  
3056                          // Escape the column name with backticks.
3057                          $index_column = '`' . $index_column_matches['column_name'] . '`';
3058  
3059                          // We don't need to add the subpart to $index_columns_without_subparts
3060                          $index_columns_without_subparts[ $id ] = $index_column;
3061  
3062                          // Append the optional sup part with the number of indexed characters.
3063                          if ( isset( $index_column_matches['sub_part'] ) ) {
3064                              $index_column .= '(' . $index_column_matches['sub_part'] . ')';
3065                          }
3066                      }
3067  
3068                      // Build the normalized index definition and add it to the list of indices.
3069                      $indices[]                  = "{$index_type} {$index_name} (" . implode( ',', $index_columns ) . ')';
3070                      $indices_without_subparts[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns_without_subparts ) . ')';
3071  
3072                      // Destroy no longer needed variables.
3073                      unset( $index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns, $index_columns_without_subparts );
3074  
3075                      break;
3076              }
3077  
3078              // If it's a valid field, add it to the field array.
3079              if ( $validfield ) {
3080                  $cfields[ $fieldname_lowercased ] = $fld;
3081              }
3082          }
3083  
3084          // For every field in the table.
3085          foreach ( $tablefields as $tablefield ) {
3086              $tablefield_field_lowercased = strtolower( $tablefield->Field );
3087              $tablefield_type_lowercased  = strtolower( $tablefield->Type );
3088  
3089              $tablefield_type_without_parentheses = preg_replace(
3090                  '/'
3091                  . '(.+)'       // Field type, e.g. `int`.
3092                  . '\(\d*\)'    // Display width.
3093                  . '(.*)'       // Optional attributes, e.g. `unsigned`.
3094                  . '/',
3095                  '$1$2',
3096                  $tablefield_type_lowercased
3097              );
3098  
3099              // Get the type without attributes, e.g. `int`.
3100              $tablefield_type_base = strtok( $tablefield_type_without_parentheses, ' ' );
3101  
3102              // If the table field exists in the field array...
3103              if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
3104  
3105                  // Get the field type from the query.
3106                  preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
3107                  $fieldtype            = $matches[1];
3108                  $fieldtype_lowercased = strtolower( $fieldtype );
3109  
3110                  $fieldtype_without_parentheses = preg_replace(
3111                      '/'
3112                      . '(.+)'       // Field type, e.g. `int`.
3113                      . '\(\d*\)'    // Display width.
3114                      . '(.*)'       // Optional attributes, e.g. `unsigned`.
3115                      . '/',
3116                      '$1$2',
3117                      $fieldtype_lowercased
3118                  );
3119  
3120                  // Get the type without attributes, e.g. `int`.
3121                  $fieldtype_base = strtok( $fieldtype_without_parentheses, ' ' );
3122  
3123                  // Is actual field type different from the field type in query?
3124                  if ( $tablefield->Type !== $fieldtype ) {
3125                      $do_change = true;
3126                      if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
3127                          if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {
3128                              $do_change = false;
3129                          }
3130                      }
3131  
3132                      if ( in_array( $fieldtype_lowercased, $blob_fields, true ) && in_array( $tablefield_type_lowercased, $blob_fields, true ) ) {
3133                          if ( array_search( $fieldtype_lowercased, $blob_fields, true ) < array_search( $tablefield_type_lowercased, $blob_fields, true ) ) {
3134                              $do_change = false;
3135                          }
3136                      }
3137  
3138                      if ( in_array( $fieldtype_base, $int_fields, true ) && in_array( $tablefield_type_base, $int_fields, true )
3139                          && $fieldtype_without_parentheses === $tablefield_type_without_parentheses
3140                      ) {
3141                          /*
3142                           * MySQL 8.0.17 or later does not support display width for integer data types,
3143                           * so if display width is the only difference, it can be safely ignored.
3144                           * Note: This is specific to MySQL and does not affect MariaDB.
3145                           */
3146                          if ( version_compare( $db_version, '8.0.17', '>=' )
3147                              && ! str_contains( $db_server_info, 'MariaDB' )
3148                          ) {
3149                              $do_change = false;
3150                          }
3151                      }
3152  
3153                      if ( $do_change ) {
3154                          // Add a query to change the column type.
3155                          $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
3156  
3157                          $for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
3158                      }
3159                  }
3160  
3161                  // Get the default value from the array.
3162                  if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) {
3163                      $default_value = $matches[1];
3164                      if ( $tablefield->Default !== $default_value ) {
3165                          // Add a query to change the column's default value
3166                          $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
3167  
3168                          $for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
3169                      }
3170                  }
3171  
3172                  // Remove the field from the array (so it's not added).
3173                  unset( $cfields[ $tablefield_field_lowercased ] );
3174              } else {
3175                  // This field exists in the table, but not in the creation queries?
3176              }
3177          }
3178  
3179          // For every remaining field specified for the table.
3180          foreach ( $cfields as $fieldname => $fielddef ) {
3181              // Push a query line into $cqueries that adds the field to that table.
3182              $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
3183  
3184              $for_update[ $table . '.' . $fieldname ] = 'Added column ' . $table . '.' . $fieldname;
3185          }
3186  
3187          // Index stuff goes here. Fetch the table index structure from the database.
3188          $tableindices = $wpdb->get_results( "SHOW INDEX FROM {$table};" );
3189  
3190          if ( $tableindices ) {
3191              // Clear the index array.
3192              $index_ary = array();
3193  
3194              // For every index in the table.
3195              foreach ( $tableindices as $tableindex ) {
3196                  $keyname = strtolower( $tableindex->Key_name );
3197  
3198                  // Add the index to the index data array.
3199                  $index_ary[ $keyname ]['columns'][]  = array(
3200                      'fieldname' => $tableindex->Column_name,
3201                      'subpart'   => $tableindex->Sub_part,
3202                  );
3203                  $index_ary[ $keyname ]['unique']     = ( '0' === $tableindex->Non_unique ) ? true : false;
3204                  $index_ary[ $keyname ]['index_type'] = $tableindex->Index_type;
3205              }
3206  
3207              // For each actual index in the index array.
3208              foreach ( $index_ary as $index_name => $index_data ) {
3209  
3210                  // Build a create string to compare to the query.
3211                  $index_string = '';
3212                  if ( 'primary' === $index_name ) {
3213                      $index_string .= 'PRIMARY ';
3214                  } elseif ( $index_data['unique'] ) {
3215                      $index_string .= 'UNIQUE ';
3216                  }
3217  
3218                  if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) {
3219                      $index_string .= 'FULLTEXT ';
3220                  }
3221  
3222                  if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) {
3223                      $index_string .= 'SPATIAL ';
3224                  }
3225  
3226                  $index_string .= 'KEY ';
3227                  if ( 'primary' !== $index_name ) {
3228                      $index_string .= '`' . $index_name . '`';
3229                  }
3230  
3231                  $index_columns = '';
3232  
3233                  // For each column in the index.
3234                  foreach ( $index_data['columns'] as $column_data ) {
3235                      if ( '' !== $index_columns ) {
3236                          $index_columns .= ',';
3237                      }
3238  
3239                      // Add the field to the column list string.
3240                      $index_columns .= '`' . $column_data['fieldname'] . '`';
3241                  }
3242  
3243                  // Add the column list to the index create string.
3244                  $index_string .= " ($index_columns)";
3245  
3246                  // Check if the index definition exists, ignoring subparts.
3247                  $aindex = array_search( $index_string, $indices_without_subparts, true );
3248                  if ( false !== $aindex ) {
3249                      // If the index already exists (even with different subparts), we don't need to create it.
3250                      unset( $indices_without_subparts[ $aindex ] );
3251                      unset( $indices[ $aindex ] );
3252                  }
3253              }
3254          }
3255  
3256          // For every remaining index specified for the table.
3257          foreach ( (array) $indices as $index ) {
3258              // Push a query line into $cqueries that adds the index to that table.
3259              $cqueries[] = "ALTER TABLE {$table} ADD $index";
3260  
3261              $for_update[] = 'Added index ' . $table . ' ' . $index;
3262          }
3263  
3264          // Remove the original table creation query from processing.
3265          unset( $cqueries[ $table ], $for_update[ $table ] );
3266      }
3267  
3268      $allqueries = array_merge( $cqueries, $iqueries );
3269      if ( $execute ) {
3270          foreach ( $allqueries as $query ) {
3271              $wpdb->query( $query );
3272          }
3273      }
3274  
3275      return $for_update;
3276  }
3277  
3278  /**
3279   * Updates the database tables to a new schema.
3280   *
3281   * By default, updates all the tables to use the latest defined schema, but can also
3282   * be used to update a specific set of tables in wp_get_db_schema().
3283   *
3284   * @since 1.5.0
3285   *
3286   * @uses dbDelta
3287   *
3288   * @param string $tables Optional. Which set of tables to update. Default is 'all'.
3289   */
3290  function make_db_current( $tables = 'all' ) {
3291      $alterations = dbDelta( $tables );
3292      echo "<ol>\n";
3293      foreach ( $alterations as $alteration ) {
3294          echo "<li>$alteration</li>\n";
3295      }
3296      echo "</ol>\n";
3297  }
3298  
3299  /**
3300   * Updates the database tables to a new schema, but without displaying results.
3301   *
3302   * By default, updates all the tables to use the latest defined schema, but can
3303   * also be used to update a specific set of tables in wp_get_db_schema().
3304   *
3305   * @since 1.5.0
3306   *
3307   * @see make_db_current()
3308   *
3309   * @param string $tables Optional. Which set of tables to update. Default is 'all'.
3310   */
3311  function make_db_current_silent( $tables = 'all' ) {
3312      dbDelta( $tables );
3313  }
3314  
3315  /**
3316   * Creates a site theme from an existing theme.
3317   *
3318   * {@internal Missing Long Description}}
3319   *
3320   * @since 1.5.0
3321   *
3322   * @param string $theme_name The name of the theme.
3323   * @param string $template   The directory name of the theme.
3324   * @return bool
3325   */
3326  function make_site_theme_from_oldschool( $theme_name, $template ) {
3327      $home_path   = get_home_path();
3328      $site_dir    = WP_CONTENT_DIR . "/themes/$template";
3329      $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
3330  
3331      if ( ! file_exists( "$home_path/index.php" ) ) {
3332          return false;
3333      }
3334  
3335      /*
3336       * Copy files from the old locations to the site theme.
3337       * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
3338       */
3339      $files = array(
3340          'index.php'             => 'index.php',
3341          'wp-layout.css'         => 'style.css',
3342          'wp-comments.php'       => 'comments.php',
3343          'wp-comments-popup.php' => 'comments-popup.php',
3344      );
3345  
3346      foreach ( $files as $oldfile => $newfile ) {
3347          if ( 'index.php' === $oldfile ) {
3348              $oldpath = $home_path;
3349          } else {
3350              $oldpath = ABSPATH;
3351          }
3352  
3353          // Check to make sure it's not a new index.
3354          if ( 'index.php' === $oldfile ) {
3355              $index = implode( '', file( "$oldpath/$oldfile" ) );
3356              if ( str_contains( $index, 'WP_USE_THEMES' ) ) {
3357                  if ( ! copy( "$default_dir/$oldfile", "$site_dir/$newfile" ) ) {
3358                      return false;
3359                  }
3360  
3361                  // Don't copy anything.
3362                  continue;
3363              }
3364          }
3365  
3366          if ( ! copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) {
3367              return false;
3368          }
3369  
3370          chmod( "$site_dir/$newfile", 0777 );
3371  
3372          // Update the blog header include in each file.
3373          $lines = explode( "\n", implode( '', file( "$site_dir/$newfile" ) ) );
3374          if ( $lines ) {
3375              $f = fopen( "$site_dir/$newfile", 'w' );
3376  
3377              foreach ( $lines as $line ) {
3378                  if ( preg_match( '/require.*wp-blog-header/', $line ) ) {
3379                      $line = '//' . $line;
3380                  }
3381  
3382                  // Update stylesheet references.
3383                  $line = str_replace(
3384                      "<?php echo __get_option('siteurl'); ?>/wp-layout.css",
3385                      "<?php bloginfo('stylesheet_url'); ?>",
3386                      $line
3387                  );
3388  
3389                  // Update comments template inclusion.
3390                  $line = str_replace(
3391                      "<?php include(ABSPATH . 'wp-comments.php'); ?>",
3392                      '<?php comments_template(); ?>',
3393                      $line
3394                  );
3395  
3396                  fwrite( $f, "{$line}\n" );
3397              }
3398              fclose( $f );
3399          }
3400      }
3401  
3402      // Add a theme header.
3403      $header = "/*\n" .
3404          "Theme Name: $theme_name\n" .
3405          'Theme URI: ' . __get_option( 'siteurl' ) . "\n" .
3406          "Description: A theme automatically created by the update.\n" .
3407          "Version: 1.0\n" .
3408          "Author: Moi\n" .
3409          "*/\n";
3410  
3411      $stylelines = file_get_contents( "$site_dir/style.css" );
3412      if ( $stylelines ) {
3413          $f = fopen( "$site_dir/style.css", 'w' );
3414  
3415          fwrite( $f, $header );
3416          fwrite( $f, $stylelines );
3417          fclose( $f );
3418      }
3419  
3420      return true;
3421  }
3422  
3423  /**
3424   * Creates a site theme from the default theme.
3425   *
3426   * {@internal Missing Long Description}}
3427   *
3428   * @since 1.5.0
3429   *
3430   * @param string $theme_name The name of the theme.
3431   * @param string $template   The directory name of the theme.
3432   * @return void|false
3433   */
3434  function make_site_theme_from_default( $theme_name, $template ) {
3435      $site_dir    = WP_CONTENT_DIR . "/themes/$template";
3436      $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
3437  
3438      /*
3439       * Copy files from the default theme to the site theme.
3440       * $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' );
3441       */
3442  
3443      $theme_dir = @opendir( $default_dir );
3444      if ( $theme_dir ) {
3445          while ( ( $theme_file = readdir( $theme_dir ) ) !== false ) {
3446              if ( is_dir( "$default_dir/$theme_file" ) ) {
3447                  continue;
3448              }
3449  
3450              if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
3451                  return;
3452              }
3453  
3454              chmod( "$site_dir/$theme_file", 0777 );
3455          }
3456  
3457          closedir( $theme_dir );
3458      }
3459  
3460      // Rewrite the theme header.
3461      $stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) );
3462      if ( $stylelines ) {
3463          $f = fopen( "$site_dir/style.css", 'w' );
3464  
3465          $headers = array(
3466              'Theme Name:'  => $theme_name,
3467              'Theme URI:'   => __get_option( 'url' ),
3468              'Description:' => 'Your theme.',
3469              'Version:'     => '1',
3470              'Author:'      => 'You',
3471          );
3472  
3473          foreach ( $stylelines as $line ) {
3474              foreach ( $headers as $header => $value ) {
3475                  if ( str_contains( $line, $header ) ) {
3476                      $line = $header . ' ' . $value;
3477                      break;
3478                  }
3479              }
3480  
3481              fwrite( $f, $line . "\n" );
3482          }
3483  
3484          fclose( $f );
3485      }
3486  
3487      // Copy the images.
3488      umask( 0 );
3489      if ( ! mkdir( "$site_dir/images", 0777 ) ) {
3490          return false;
3491      }
3492  
3493      $images_dir = @opendir( "$default_dir/images" );
3494      if ( $images_dir ) {
3495          while ( ( $image = readdir( $images_dir ) ) !== false ) {
3496              if ( is_dir( "$default_dir/images/$image" ) ) {
3497                  continue;
3498              }
3499  
3500              if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
3501                  return;
3502              }
3503  
3504              chmod( "$site_dir/images/$image", 0777 );
3505          }
3506  
3507          closedir( $images_dir );
3508      }
3509  }
3510  
3511  /**
3512   * Creates a site theme.
3513   *
3514   * {@internal Missing Long Description}}
3515   *
3516   * @since 1.5.0
3517   *
3518   * @return string|false
3519   */
3520  function make_site_theme() {
3521      // Name the theme after the blog.
3522      $theme_name = __get_option( 'blogname' );
3523      $template   = sanitize_title( $theme_name );
3524      $site_dir   = WP_CONTENT_DIR . "/themes/$template";
3525  
3526      // If the theme already exists, nothing to do.
3527      if ( is_dir( $site_dir ) ) {
3528          return false;
3529      }
3530  
3531      // We must be able to write to the themes dir.
3532      if ( ! is_writable( WP_CONTENT_DIR . '/themes' ) ) {
3533          return false;
3534      }
3535  
3536      umask( 0 );
3537      if ( ! mkdir( $site_dir, 0777 ) ) {
3538          return false;
3539      }
3540  
3541      if ( file_exists( ABSPATH . 'wp-layout.css' ) ) {
3542          if ( ! make_site_theme_from_oldschool( $theme_name, $template ) ) {
3543              // TODO: rm -rf the site theme directory.
3544              return false;
3545          }
3546      } else {
3547          if ( ! make_site_theme_from_default( $theme_name, $template ) ) {
3548              // TODO: rm -rf the site theme directory.
3549              return false;
3550          }
3551      }
3552  
3553      // Make the new site theme active.
3554      $current_template = __get_option( 'template' );
3555      if ( WP_DEFAULT_THEME === $current_template ) {
3556          update_option( 'template', $template );
3557          update_option( 'stylesheet', $template );
3558      }
3559      return $template;
3560  }
3561  
3562  /**
3563   * Translate user level to user role name.
3564   *
3565   * @since 2.0.0
3566   *
3567   * @param int $level User level.
3568   * @return string User role name.
3569   */
3570  function translate_level_to_role( $level ) {
3571      switch ( $level ) {
3572          case 10:
3573          case 9:
3574          case 8:
3575              return 'administrator';
3576          case 7:
3577          case 6:
3578          case 5:
3579              return 'editor';
3580          case 4:
3581          case 3:
3582          case 2:
3583              return 'author';
3584          case 1:
3585              return 'contributor';
3586          case 0:
3587          default:
3588              return 'subscriber';
3589      }
3590  }
3591  
3592  /**
3593   * Checks the version of the installed MySQL binary.
3594   *
3595   * @since 2.1.0
3596   *
3597   * @global wpdb $wpdb WordPress database abstraction object.
3598   */
3599  function wp_check_mysql_version() {
3600      global $wpdb;
3601      $result = $wpdb->check_database_version();
3602      if ( is_wp_error( $result ) ) {
3603          wp_die( $result );
3604      }
3605  }
3606  
3607  /**
3608   * Disables the Automattic widgets plugin, which was merged into core.
3609   *
3610   * @since 2.2.0
3611   */
3612  function maybe_disable_automattic_widgets() {
3613      $plugins = __get_option( 'active_plugins' );
3614  
3615      foreach ( (array) $plugins as $plugin ) {
3616          if ( 'widgets.php' === basename( $plugin ) ) {
3617              array_splice( $plugins, array_search( $plugin, $plugins, true ), 1 );
3618              update_option( 'active_plugins', $plugins );
3619              break;
3620          }
3621      }
3622  }
3623  
3624  /**
3625   * Disables the Link Manager on upgrade if, at the time of upgrade, no links exist in the DB.
3626   *
3627   * @since 3.5.0
3628   *
3629   * @global int  $wp_current_db_version The old (current) database version.
3630   * @global wpdb $wpdb                  WordPress database abstraction object.
3631   */
3632  function maybe_disable_link_manager() {
3633      global $wp_current_db_version, $wpdb;
3634  
3635      if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
3636          update_option( 'link_manager_enabled', 0 );
3637      }
3638  }
3639  
3640  /**
3641   * Runs before the schema is upgraded.
3642   *
3643   * @since 2.9.0
3644   *
3645   * @global int  $wp_current_db_version The old (current) database version.
3646   * @global wpdb $wpdb                  WordPress database abstraction object.
3647   */
3648  function pre_schema_upgrade() {
3649      global $wp_current_db_version, $wpdb;
3650  
3651      // Upgrade versions prior to 2.9.
3652      if ( $wp_current_db_version < 11557 ) {
3653          // Delete duplicate options. Keep the option with the highest option_id.
3654          $wpdb->query( "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id" );
3655  
3656          // Drop the old primary key and add the new.
3657          $wpdb->query( "ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)" );
3658  
3659          // Drop the old option_name index. dbDelta() doesn't do the drop.
3660          $wpdb->query( "ALTER TABLE $wpdb->options DROP INDEX option_name" );
3661      }
3662  
3663      // Multisite schema upgrades.
3664      if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) {
3665  
3666          // Upgrade versions prior to 3.7.
3667          if ( $wp_current_db_version < 25179 ) {
3668              // New primary key for signups.
3669              $wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
3670              $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" );
3671          }
3672  
3673          if ( $wp_current_db_version < 25448 ) {
3674              // Convert archived from enum to tinyint.
3675              $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" );
3676              $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" );
3677          }
3678      }
3679  
3680      // Upgrade versions prior to 4.2.
3681      if ( $wp_current_db_version < 31351 ) {
3682          if ( ! is_multisite() && wp_should_upgrade_global_tables() ) {
3683              $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3684          }
3685          $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
3686          $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
3687          $wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3688          $wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3689          $wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );
3690      }
3691  
3692      // Upgrade versions prior to 4.4.
3693      if ( $wp_current_db_version < 34978 ) {
3694          // If compatible termmeta table is found, use it, but enforce a proper index and update collation.
3695          if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->termmeta}'" ) && $wpdb->get_results( "SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'" ) ) {
3696              $wpdb->query( "ALTER TABLE $wpdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
3697              maybe_convert_table_to_utf8mb4( $wpdb->termmeta );
3698          }
3699      }
3700  }
3701  
3702  /**
3703   * Determine if global tables should be upgraded.
3704   *
3705   * This function performs a series of checks to ensure the environment allows
3706   * for the safe upgrading of global WordPress database tables. It is necessary
3707   * because global tables will commonly grow to millions of rows on large
3708   * installations, and the ability to control their upgrade routines can be
3709   * critical to the operation of large networks.
3710   *
3711   * In a future iteration, this function may use `wp_is_large_network()` to more-
3712   * intelligently prevent global table upgrades. Until then, we make sure
3713   * WordPress is on the main site of the main network, to avoid running queries
3714   * more than once in multi-site or multi-network environments.
3715   *
3716   * @since 4.3.0
3717   *
3718   * @return bool Whether to run the upgrade routines on global tables.
3719   */
3720  function wp_should_upgrade_global_tables() {
3721  
3722      // Return false early if explicitly not upgrading.
3723      if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
3724          return false;
3725      }
3726  
3727      // Assume global tables should be upgraded.
3728      $should_upgrade = true;
3729  
3730      // Set to false if not on main network (does not matter if not multi-network).
3731      if ( ! is_main_network() ) {
3732          $should_upgrade = false;
3733      }
3734  
3735      // Set to false if not on main site of current network (does not matter if not multi-site).
3736      if ( ! is_main_site() ) {
3737          $should_upgrade = false;
3738      }
3739  
3740      /**
3741       * Filters if upgrade routines should be run on global tables.
3742       *
3743       * @since 4.3.0
3744       *
3745       * @param bool $should_upgrade Whether to run the upgrade routines on global tables.
3746       */
3747      return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade );
3748  }


Generated : Thu Oct 24 08:20:01 2024 Cross-referenced by PHPXref