[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * WordPress Administration Scheme API
   4   *
   5   * Here we keep the DB structure and option values.
   6   *
   7   * @package WordPress
   8   * @subpackage Administration
   9   */
  10  
  11  /**
  12   * Declare these as global in case schema.php is included from a function.
  13   *
  14   * @global wpdb   $wpdb            WordPress database abstraction object.
  15   * @global array  $wp_queries
  16   * @global string $charset_collate
  17   */
  18  global $wpdb, $wp_queries, $charset_collate;
  19  
  20  /**
  21   * The database character collate.
  22   */
  23  $charset_collate = $wpdb->get_charset_collate();
  24  
  25  /**
  26   * Retrieve the SQL for creating database tables.
  27   *
  28   * @since 3.3.0
  29   *
  30   * @global wpdb $wpdb WordPress database abstraction object.
  31   *
  32   * @param string $scope Optional. The tables for which to retrieve SQL. Can be all, global, ms_global, or blog tables. Defaults to all.
  33   * @param int $blog_id Optional. The site ID for which to retrieve SQL. Default is the current site ID.
  34   * @return string The SQL needed to create the requested tables.
  35   */
  36  function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
  37      global $wpdb;
  38  
  39      $charset_collate = $wpdb->get_charset_collate();
  40  
  41      if ( $blog_id && $blog_id != $wpdb->blogid ) {
  42          $old_blog_id = $wpdb->set_blog_id( $blog_id );
  43      }
  44  
  45      // Engage multisite if in the middle of turning it on from network.php.
  46      $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK );
  47  
  48      /*
  49       * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
  50       * As of 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which
  51       * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
  52       */
  53      $max_index_length = 191;
  54  
  55      // Blog specific tables.
  56      $blog_tables = "CREATE TABLE $wpdb->termmeta (
  57      meta_id bigint(20) unsigned NOT NULL auto_increment,
  58      term_id bigint(20) unsigned NOT NULL default '0',
  59      meta_key varchar(255) default NULL,
  60      meta_value longtext,
  61      PRIMARY KEY  (meta_id),
  62      KEY term_id (term_id),
  63      KEY meta_key (meta_key($max_index_length))
  64  ) $charset_collate;
  65  CREATE TABLE $wpdb->terms (
  66   term_id bigint(20) unsigned NOT NULL auto_increment,
  67   name varchar(200) NOT NULL default '',
  68   slug varchar(200) NOT NULL default '',
  69   term_group bigint(10) NOT NULL default 0,
  70   PRIMARY KEY  (term_id),
  71   KEY slug (slug($max_index_length)),
  72   KEY name (name($max_index_length))
  73  ) $charset_collate;
  74  CREATE TABLE $wpdb->term_taxonomy (
  75   term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment,
  76   term_id bigint(20) unsigned NOT NULL default 0,
  77   taxonomy varchar(32) NOT NULL default '',
  78   description longtext NOT NULL,
  79   parent bigint(20) unsigned NOT NULL default 0,
  80   count bigint(20) NOT NULL default 0,
  81   PRIMARY KEY  (term_taxonomy_id),
  82   UNIQUE KEY term_id_taxonomy (term_id,taxonomy),
  83   KEY taxonomy (taxonomy)
  84  ) $charset_collate;
  85  CREATE TABLE $wpdb->term_relationships (
  86   object_id bigint(20) unsigned NOT NULL default 0,
  87   term_taxonomy_id bigint(20) unsigned NOT NULL default 0,
  88   term_order int(11) NOT NULL default 0,
  89   PRIMARY KEY  (object_id,term_taxonomy_id),
  90   KEY term_taxonomy_id (term_taxonomy_id)
  91  ) $charset_collate;
  92  CREATE TABLE $wpdb->commentmeta (
  93      meta_id bigint(20) unsigned NOT NULL auto_increment,
  94      comment_id bigint(20) unsigned NOT NULL default '0',
  95      meta_key varchar(255) default NULL,
  96      meta_value longtext,
  97      PRIMARY KEY  (meta_id),
  98      KEY comment_id (comment_id),
  99      KEY meta_key (meta_key($max_index_length))
 100  ) $charset_collate;
 101  CREATE TABLE $wpdb->comments (
 102      comment_ID bigint(20) unsigned NOT NULL auto_increment,
 103      comment_post_ID bigint(20) unsigned NOT NULL default '0',
 104      comment_author tinytext NOT NULL,
 105      comment_author_email varchar(100) NOT NULL default '',
 106      comment_author_url varchar(200) NOT NULL default '',
 107      comment_author_IP varchar(100) NOT NULL default '',
 108      comment_date datetime NOT NULL default '0000-00-00 00:00:00',
 109      comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
 110      comment_content text NOT NULL,
 111      comment_karma int(11) NOT NULL default '0',
 112      comment_approved varchar(20) NOT NULL default '1',
 113      comment_agent varchar(255) NOT NULL default '',
 114      comment_type varchar(20) NOT NULL default '',
 115      comment_parent bigint(20) unsigned NOT NULL default '0',
 116      user_id bigint(20) unsigned NOT NULL default '0',
 117      PRIMARY KEY  (comment_ID),
 118      KEY comment_post_ID (comment_post_ID),
 119      KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
 120      KEY comment_date_gmt (comment_date_gmt),
 121      KEY comment_parent (comment_parent),
 122      KEY comment_author_email (comment_author_email(10))
 123  ) $charset_collate;
 124  CREATE TABLE $wpdb->links (
 125      link_id bigint(20) unsigned NOT NULL auto_increment,
 126      link_url varchar(255) NOT NULL default '',
 127      link_name varchar(255) NOT NULL default '',
 128      link_image varchar(255) NOT NULL default '',
 129      link_target varchar(25) NOT NULL default '',
 130      link_description varchar(255) NOT NULL default '',
 131      link_visible varchar(20) NOT NULL default 'Y',
 132      link_owner bigint(20) unsigned NOT NULL default '1',
 133      link_rating int(11) NOT NULL default '0',
 134      link_updated datetime NOT NULL default '0000-00-00 00:00:00',
 135      link_rel varchar(255) NOT NULL default '',
 136      link_notes mediumtext NOT NULL,
 137      link_rss varchar(255) NOT NULL default '',
 138      PRIMARY KEY  (link_id),
 139      KEY link_visible (link_visible)
 140  ) $charset_collate;
 141  CREATE TABLE $wpdb->options (
 142      option_id bigint(20) unsigned NOT NULL auto_increment,
 143      option_name varchar(191) NOT NULL default '',
 144      option_value longtext NOT NULL,
 145      autoload varchar(20) NOT NULL default 'yes',
 146      PRIMARY KEY  (option_id),
 147      UNIQUE KEY option_name (option_name),
 148      KEY autoload (autoload)
 149  ) $charset_collate;
 150  CREATE TABLE $wpdb->postmeta (
 151      meta_id bigint(20) unsigned NOT NULL auto_increment,
 152      post_id bigint(20) unsigned NOT NULL default '0',
 153      meta_key varchar(255) default NULL,
 154      meta_value longtext,
 155      PRIMARY KEY  (meta_id),
 156      KEY post_id (post_id),
 157      KEY meta_key (meta_key($max_index_length))
 158  ) $charset_collate;
 159  CREATE TABLE $wpdb->posts (
 160      ID bigint(20) unsigned NOT NULL auto_increment,
 161      post_author bigint(20) unsigned NOT NULL default '0',
 162      post_date datetime NOT NULL default '0000-00-00 00:00:00',
 163      post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
 164      post_content longtext NOT NULL,
 165      post_title text NOT NULL,
 166      post_excerpt text NOT NULL,
 167      post_status varchar(20) NOT NULL default 'publish',
 168      comment_status varchar(20) NOT NULL default 'open',
 169      ping_status varchar(20) NOT NULL default 'open',
 170      post_password varchar(255) NOT NULL default '',
 171      post_name varchar(200) NOT NULL default '',
 172      to_ping text NOT NULL,
 173      pinged text NOT NULL,
 174      post_modified datetime NOT NULL default '0000-00-00 00:00:00',
 175      post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
 176      post_content_filtered longtext NOT NULL,
 177      post_parent bigint(20) unsigned NOT NULL default '0',
 178      guid varchar(255) NOT NULL default '',
 179      menu_order int(11) NOT NULL default '0',
 180      post_type varchar(20) NOT NULL default 'post',
 181      post_mime_type varchar(100) NOT NULL default '',
 182      comment_count bigint(20) NOT NULL default '0',
 183      PRIMARY KEY  (ID),
 184      KEY post_name (post_name($max_index_length)),
 185      KEY type_status_date (post_type,post_status,post_date,ID),
 186      KEY post_parent (post_parent),
 187      KEY post_author (post_author)
 188  ) $charset_collate;\n";
 189  
 190      // Single site users table. The multisite flavor of the users table is handled below.
 191      $users_single_table = "CREATE TABLE $wpdb->users (
 192      ID bigint(20) unsigned NOT NULL auto_increment,
 193      user_login varchar(60) NOT NULL default '',
 194      user_pass varchar(255) NOT NULL default '',
 195      user_nicename varchar(50) NOT NULL default '',
 196      user_email varchar(100) NOT NULL default '',
 197      user_url varchar(100) NOT NULL default '',
 198      user_registered datetime NOT NULL default '0000-00-00 00:00:00',
 199      user_activation_key varchar(255) NOT NULL default '',
 200      user_status int(11) NOT NULL default '0',
 201      display_name varchar(250) NOT NULL default '',
 202      PRIMARY KEY  (ID),
 203      KEY user_login_key (user_login),
 204      KEY user_nicename (user_nicename),
 205      KEY user_email (user_email)
 206  ) $charset_collate;\n";
 207  
 208      // Multisite users table
 209      $users_multi_table = "CREATE TABLE $wpdb->users (
 210      ID bigint(20) unsigned NOT NULL auto_increment,
 211      user_login varchar(60) NOT NULL default '',
 212      user_pass varchar(255) NOT NULL default '',
 213      user_nicename varchar(50) NOT NULL default '',
 214      user_email varchar(100) NOT NULL default '',
 215      user_url varchar(100) NOT NULL default '',
 216      user_registered datetime NOT NULL default '0000-00-00 00:00:00',
 217      user_activation_key varchar(255) NOT NULL default '',
 218      user_status int(11) NOT NULL default '0',
 219      display_name varchar(250) NOT NULL default '',
 220      spam tinyint(2) NOT NULL default '0',
 221      deleted tinyint(2) NOT NULL default '0',
 222      PRIMARY KEY  (ID),
 223      KEY user_login_key (user_login),
 224      KEY user_nicename (user_nicename),
 225      KEY user_email (user_email)
 226  ) $charset_collate;\n";
 227  
 228      // Usermeta.
 229      $usermeta_table = "CREATE TABLE $wpdb->usermeta (
 230      umeta_id bigint(20) unsigned NOT NULL auto_increment,
 231      user_id bigint(20) unsigned NOT NULL default '0',
 232      meta_key varchar(255) default NULL,
 233      meta_value longtext,
 234      PRIMARY KEY  (umeta_id),
 235      KEY user_id (user_id),
 236      KEY meta_key (meta_key($max_index_length))
 237  ) $charset_collate;\n";
 238  
 239      // Global tables
 240      if ( $is_multisite ) {
 241          $global_tables = $users_multi_table . $usermeta_table;
 242      } else {
 243          $global_tables = $users_single_table . $usermeta_table;
 244      }
 245  
 246      // Multisite global tables.
 247      $ms_global_tables = "CREATE TABLE $wpdb->blogs (
 248      blog_id bigint(20) NOT NULL auto_increment,
 249      site_id bigint(20) NOT NULL default '0',
 250      domain varchar(200) NOT NULL default '',
 251      path varchar(100) NOT NULL default '',
 252      registered datetime NOT NULL default '0000-00-00 00:00:00',
 253      last_updated datetime NOT NULL default '0000-00-00 00:00:00',
 254      public tinyint(2) NOT NULL default '1',
 255      archived tinyint(2) NOT NULL default '0',
 256      mature tinyint(2) NOT NULL default '0',
 257      spam tinyint(2) NOT NULL default '0',
 258      deleted tinyint(2) NOT NULL default '0',
 259      lang_id int(11) NOT NULL default '0',
 260      PRIMARY KEY  (blog_id),
 261      KEY domain (domain(50),path(5)),
 262      KEY lang_id (lang_id)
 263  ) $charset_collate;
 264  CREATE TABLE $wpdb->blog_versions (
 265      blog_id bigint(20) NOT NULL default '0',
 266      db_version varchar(20) NOT NULL default '',
 267      last_updated datetime NOT NULL default '0000-00-00 00:00:00',
 268      PRIMARY KEY  (blog_id),
 269      KEY db_version (db_version)
 270  ) $charset_collate;
 271  CREATE TABLE $wpdb->blogmeta (
 272      meta_id bigint(20) unsigned NOT NULL auto_increment,
 273      blog_id bigint(20) NOT NULL default '0',
 274      meta_key varchar(255) default NULL,
 275      meta_value longtext,
 276      PRIMARY KEY  (meta_id),
 277      KEY meta_key (meta_key($max_index_length)),
 278      KEY blog_id (blog_id)
 279  ) $charset_collate;
 280  CREATE TABLE $wpdb->registration_log (
 281      ID bigint(20) NOT NULL auto_increment,
 282      email varchar(255) NOT NULL default '',
 283      IP varchar(30) NOT NULL default '',
 284      blog_id bigint(20) NOT NULL default '0',
 285      date_registered datetime NOT NULL default '0000-00-00 00:00:00',
 286      PRIMARY KEY  (ID),
 287      KEY IP (IP)
 288  ) $charset_collate;
 289  CREATE TABLE $wpdb->site (
 290      id bigint(20) NOT NULL auto_increment,
 291      domain varchar(200) NOT NULL default '',
 292      path varchar(100) NOT NULL default '',
 293      PRIMARY KEY  (id),
 294      KEY domain (domain(140),path(51))
 295  ) $charset_collate;
 296  CREATE TABLE $wpdb->sitemeta (
 297      meta_id bigint(20) NOT NULL auto_increment,
 298      site_id bigint(20) NOT NULL default '0',
 299      meta_key varchar(255) default NULL,
 300      meta_value longtext,
 301      PRIMARY KEY  (meta_id),
 302      KEY meta_key (meta_key($max_index_length)),
 303      KEY site_id (site_id)
 304  ) $charset_collate;
 305  CREATE TABLE $wpdb->signups (
 306      signup_id bigint(20) NOT NULL auto_increment,
 307      domain varchar(200) NOT NULL default '',
 308      path varchar(100) NOT NULL default '',
 309      title longtext NOT NULL,
 310      user_login varchar(60) NOT NULL default '',
 311      user_email varchar(100) NOT NULL default '',
 312      registered datetime NOT NULL default '0000-00-00 00:00:00',
 313      activated datetime NOT NULL default '0000-00-00 00:00:00',
 314      active tinyint(1) NOT NULL default '0',
 315      activation_key varchar(50) NOT NULL default '',
 316      meta longtext,
 317      PRIMARY KEY  (signup_id),
 318      KEY activation_key (activation_key),
 319      KEY user_email (user_email),
 320      KEY user_login_email (user_login,user_email),
 321      KEY domain_path (domain(140),path(51))
 322  ) $charset_collate;";
 323  
 324      switch ( $scope ) {
 325          case 'blog':
 326              $queries = $blog_tables;
 327              break;
 328          case 'global':
 329              $queries = $global_tables;
 330              if ( $is_multisite ) {
 331                  $queries .= $ms_global_tables;
 332              }
 333              break;
 334          case 'ms_global':
 335              $queries = $ms_global_tables;
 336              break;
 337          case 'all':
 338          default:
 339              $queries = $global_tables . $blog_tables;
 340              if ( $is_multisite ) {
 341                  $queries .= $ms_global_tables;
 342              }
 343              break;
 344      }
 345  
 346      if ( isset( $old_blog_id ) ) {
 347          $wpdb->set_blog_id( $old_blog_id );
 348      }
 349  
 350      return $queries;
 351  }
 352  
 353  // Populate for back compat.
 354  $wp_queries = wp_get_db_schema( 'all' );
 355  
 356  /**
 357   * Create WordPress options and set the default values.
 358   *
 359   * @since 1.5.0
 360   * @since 5.1.0 The $options parameter has been added.
 361   *
 362   * @global wpdb $wpdb                  WordPress database abstraction object.
 363   * @global int  $wp_db_version         WordPress database version.
 364   * @global int  $wp_current_db_version The old (current) database version.
 365   *
 366   * @param array $options Optional. Custom option $key => $value pairs to use. Default empty array.
 367   */
 368  function populate_options( array $options = array() ) {
 369      global $wpdb, $wp_db_version, $wp_current_db_version;
 370  
 371      $guessurl = wp_guess_url();
 372      /**
 373       * Fires before creating WordPress options and populating their default values.
 374       *
 375       * @since 2.6.0
 376       */
 377      do_action( 'populate_options' );
 378  
 379      if ( ini_get( 'safe_mode' ) ) {
 380          // Safe mode can break mkdir() so use a flat structure by default.
 381          $uploads_use_yearmonth_folders = 0;
 382      } else {
 383          $uploads_use_yearmonth_folders = 1;
 384      }
 385  
 386      // If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
 387      $stylesheet = WP_DEFAULT_THEME;
 388      $template   = WP_DEFAULT_THEME;
 389      $theme      = wp_get_theme( WP_DEFAULT_THEME );
 390      if ( ! $theme->exists() ) {
 391          $theme = WP_Theme::get_core_default_theme();
 392      }
 393  
 394      // If we can't find a core default theme, WP_DEFAULT_THEME is the best we can do.
 395      if ( $theme ) {
 396          $stylesheet = $theme->get_stylesheet();
 397          $template   = $theme->get_template();
 398      }
 399  
 400      $timezone_string = '';
 401      $gmt_offset      = 0;
 402      /*
 403       * translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
 404       * or a valid timezone string (America/New_York). See https://secure.php.net/manual/en/timezones.php
 405       * for all timezone strings supported by PHP.
 406       */
 407      $offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings
 408      if ( is_numeric( $offset_or_tz ) ) {
 409          $gmt_offset = $offset_or_tz;
 410      } elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) ) {
 411              $timezone_string = $offset_or_tz;
 412      }
 413  
 414      $defaults = array(
 415          'siteurl'                         => $guessurl,
 416          'home'                            => $guessurl,
 417          'blogname'                        => __( 'My Site' ),
 418          /* translators: Site tagline. */
 419          'blogdescription'                 => __( 'Just another WordPress site' ),
 420          'users_can_register'              => 0,
 421          'admin_email'                     => 'you@example.com',
 422          /* translators: Default start of the week. 0 = Sunday, 1 = Monday. */
 423          'start_of_week'                   => _x( '1', 'start of week' ),
 424          'use_balanceTags'                 => 0,
 425          'use_smilies'                     => 1,
 426          'require_name_email'              => 1,
 427          'comments_notify'                 => 1,
 428          'posts_per_rss'                   => 10,
 429          'rss_use_excerpt'                 => 0,
 430          'mailserver_url'                  => 'mail.example.com',
 431          'mailserver_login'                => 'login@example.com',
 432          'mailserver_pass'                 => 'password',
 433          'mailserver_port'                 => 110,
 434          'default_category'                => 1,
 435          'default_comment_status'          => 'open',
 436          'default_ping_status'             => 'open',
 437          'default_pingback_flag'           => 1,
 438          'posts_per_page'                  => 10,
 439          /* translators: Default date format, see https://secure.php.net/date */
 440          'date_format'                     => __( 'F j, Y' ),
 441          /* translators: Default time format, see https://secure.php.net/date */
 442          'time_format'                     => __( 'g:i a' ),
 443          /* translators: Links last updated date format, see https://secure.php.net/date */
 444          'links_updated_date_format'       => __( 'F j, Y g:i a' ),
 445          'comment_moderation'              => 0,
 446          'moderation_notify'               => 1,
 447          'permalink_structure'             => '',
 448          'rewrite_rules'                   => '',
 449          'hack_file'                       => 0,
 450          'blog_charset'                    => 'UTF-8',
 451          'moderation_keys'                 => '',
 452          'active_plugins'                  => array(),
 453          'category_base'                   => '',
 454          'ping_sites'                      => 'http://rpc.pingomatic.com/',
 455          'comment_max_links'               => 2,
 456          'gmt_offset'                      => $gmt_offset,
 457  
 458          // 1.5
 459          'default_email_category'          => 1,
 460          'recently_edited'                 => '',
 461          'template'                        => $template,
 462          'stylesheet'                      => $stylesheet,
 463          'comment_whitelist'               => 1,
 464          'blacklist_keys'                  => '',
 465          'comment_registration'            => 0,
 466          'html_type'                       => 'text/html',
 467  
 468          // 1.5.1
 469          'use_trackback'                   => 0,
 470  
 471          // 2.0
 472          'default_role'                    => 'subscriber',
 473          'db_version'                      => $wp_db_version,
 474  
 475          // 2.0.1
 476          'uploads_use_yearmonth_folders'   => $uploads_use_yearmonth_folders,
 477          'upload_path'                     => '',
 478  
 479          // 2.1
 480          'blog_public'                     => '1',
 481          'default_link_category'           => 2,
 482          'show_on_front'                   => 'posts',
 483  
 484          // 2.2
 485          'tag_base'                        => '',
 486  
 487          // 2.5
 488          'show_avatars'                    => '1',
 489          'avatar_rating'                   => 'G',
 490          'upload_url_path'                 => '',
 491          'thumbnail_size_w'                => 150,
 492          'thumbnail_size_h'                => 150,
 493          'thumbnail_crop'                  => 1,
 494          'medium_size_w'                   => 300,
 495          'medium_size_h'                   => 300,
 496  
 497          // 2.6
 498          'avatar_default'                  => 'mystery',
 499  
 500          // 2.7
 501          'large_size_w'                    => 1024,
 502          'large_size_h'                    => 1024,
 503          'image_default_link_type'         => 'none',
 504          'image_default_size'              => '',
 505          'image_default_align'             => '',
 506          'close_comments_for_old_posts'    => 0,
 507          'close_comments_days_old'         => 14,
 508          'thread_comments'                 => 1,
 509          'thread_comments_depth'           => 5,
 510          'page_comments'                   => 0,
 511          'comments_per_page'               => 50,
 512          'default_comments_page'           => 'newest',
 513          'comment_order'                   => 'asc',
 514          'sticky_posts'                    => array(),
 515          'widget_categories'               => array(),
 516          'widget_text'                     => array(),
 517          'widget_rss'                      => array(),
 518          'uninstall_plugins'               => array(),
 519  
 520          // 2.8
 521          'timezone_string'                 => $timezone_string,
 522  
 523          // 3.0
 524          'page_for_posts'                  => 0,
 525          'page_on_front'                   => 0,
 526  
 527          // 3.1
 528          'default_post_format'             => 0,
 529  
 530          // 3.5
 531          'link_manager_enabled'            => 0,
 532  
 533          // 4.3.0
 534          'finished_splitting_shared_terms' => 1,
 535          'site_icon'                       => 0,
 536  
 537          // 4.4.0
 538          'medium_large_size_w'             => 768,
 539          'medium_large_size_h'             => 0,
 540  
 541          // 4.9.6
 542          'wp_page_for_privacy_policy'      => 0,
 543  
 544          // 4.9.8
 545          'show_comments_cookies_opt_in'    => 1,
 546  
 547          // 5.3.0
 548          'admin_email_lifespan'            => ( time() + 6 * MONTH_IN_SECONDS ),
 549      );
 550  
 551      // 3.3
 552      if ( ! is_multisite() ) {
 553          $defaults['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version
 554              ? $wp_current_db_version : $wp_db_version;
 555      }
 556  
 557      // 3.0 multisite
 558      if ( is_multisite() ) {
 559          /* translators: %s: Network title. */
 560          $defaults['blogdescription']     = sprintf( __( 'Just another %s site' ), get_network()->site_name );
 561          $defaults['permalink_structure'] = '/%year%/%monthnum%/%day%/%postname%/';
 562      }
 563  
 564      $options = wp_parse_args( $options, $defaults );
 565  
 566      // Set autoload to no for these options
 567      $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' );
 568  
 569      $keys             = "'" . implode( "', '", array_keys( $options ) ) . "'";
 570      $existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
 571  
 572      $insert = '';
 573      foreach ( $options as $option => $value ) {
 574          if ( in_array( $option, $existing_options ) ) {
 575              continue;
 576          }
 577          if ( in_array( $option, $fat_options ) ) {
 578              $autoload = 'no';
 579          } else {
 580              $autoload = 'yes';
 581          }
 582  
 583          if ( is_array( $value ) ) {
 584              $value = serialize( $value );
 585          }
 586          if ( ! empty( $insert ) ) {
 587              $insert .= ', ';
 588          }
 589          $insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload );
 590      }
 591  
 592      if ( ! empty( $insert ) ) {
 593          $wpdb->query( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
 594      }
 595  
 596      // In case it is set, but blank, update "home".
 597      if ( ! __get_option( 'home' ) ) {
 598          update_option( 'home', $guessurl );
 599      }
 600  
 601      // Delete unused options.
 602      $unusedoptions = array(
 603          'blodotgsping_url',
 604          'bodyterminator',
 605          'emailtestonly',
 606          'phoneemail_separator',
 607          'smilies_directory',
 608          'subjectprefix',
 609          'use_bbcode',
 610          'use_blodotgsping',
 611          'use_phoneemail',
 612          'use_quicktags',
 613          'use_weblogsping',
 614          'weblogs_cache_file',
 615          'use_preview',
 616          'use_htmltrans',
 617          'smilies_directory',
 618          'fileupload_allowedusers',
 619          'use_phoneemail',
 620          'default_post_status',
 621          'default_post_category',
 622          'archive_mode',
 623          'time_difference',
 624          'links_minadminlevel',
 625          'links_use_adminlevels',
 626          'links_rating_type',
 627          'links_rating_char',
 628          'links_rating_ignore_zero',
 629          'links_rating_single_image',
 630          'links_rating_image0',
 631          'links_rating_image1',
 632          'links_rating_image2',
 633          'links_rating_image3',
 634          'links_rating_image4',
 635          'links_rating_image5',
 636          'links_rating_image6',
 637          'links_rating_image7',
 638          'links_rating_image8',
 639          'links_rating_image9',
 640          'links_recently_updated_time',
 641          'links_recently_updated_prepend',
 642          'links_recently_updated_append',
 643          'weblogs_cacheminutes',
 644          'comment_allowed_tags',
 645          'search_engine_friendly_urls',
 646          'default_geourl_lat',
 647          'default_geourl_lon',
 648          'use_default_geourl',
 649          'weblogs_xml_url',
 650          'new_users_can_blog',
 651          '_wpnonce',
 652          '_wp_http_referer',
 653          'Update',
 654          'action',
 655          'rich_editing',
 656          'autosave_interval',
 657          'deactivated_plugins',
 658          'can_compress_scripts',
 659          'page_uris',
 660          'update_core',
 661          'update_plugins',
 662          'update_themes',
 663          'doing_cron',
 664          'random_seed',
 665          'rss_excerpt_length',
 666          'secret',
 667          'use_linksupdate',
 668          'default_comment_status_page',
 669          'wporg_popular_tags',
 670          'what_to_show',
 671          'rss_language',
 672          'language',
 673          'enable_xmlrpc',
 674          'enable_app',
 675          'embed_autourls',
 676          'default_post_edit_rows',
 677          'gzipcompression',
 678          'advanced_edit',
 679      );
 680      foreach ( $unusedoptions as $option ) {
 681          delete_option( $option );
 682      }
 683  
 684      // Delete obsolete magpie stuff.
 685      $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'" );
 686  
 687      // Clear expired transients
 688      delete_expired_transients( true );
 689  }
 690  
 691  /**
 692   * Execute WordPress role creation for the various WordPress versions.
 693   *
 694   * @since 2.0.0
 695   */
 696  function populate_roles() {
 697      populate_roles_160();
 698      populate_roles_210();
 699      populate_roles_230();
 700      populate_roles_250();
 701      populate_roles_260();
 702      populate_roles_270();
 703      populate_roles_280();
 704      populate_roles_300();
 705  }
 706  
 707  /**
 708   * Create the roles for WordPress 2.0
 709   *
 710   * @since 2.0.0
 711   */
 712  function populate_roles_160() {
 713      // Add roles
 714  
 715      add_role( 'administrator', 'Administrator' );
 716      add_role( 'editor', 'Editor' );
 717      add_role( 'author', 'Author' );
 718      add_role( 'contributor', 'Contributor' );
 719      add_role( 'subscriber', 'Subscriber' );
 720  
 721      // Add caps for Administrator role
 722      $role = get_role( 'administrator' );
 723      $role->add_cap( 'switch_themes' );
 724      $role->add_cap( 'edit_themes' );
 725      $role->add_cap( 'activate_plugins' );
 726      $role->add_cap( 'edit_plugins' );
 727      $role->add_cap( 'edit_users' );
 728      $role->add_cap( 'edit_files' );
 729      $role->add_cap( 'manage_options' );
 730      $role->add_cap( 'moderate_comments' );
 731      $role->add_cap( 'manage_categories' );
 732      $role->add_cap( 'manage_links' );
 733      $role->add_cap( 'upload_files' );
 734      $role->add_cap( 'import' );
 735      $role->add_cap( 'unfiltered_html' );
 736      $role->add_cap( 'edit_posts' );
 737      $role->add_cap( 'edit_others_posts' );
 738      $role->add_cap( 'edit_published_posts' );
 739      $role->add_cap( 'publish_posts' );
 740      $role->add_cap( 'edit_pages' );
 741      $role->add_cap( 'read' );
 742      $role->add_cap( 'level_10' );
 743      $role->add_cap( 'level_9' );
 744      $role->add_cap( 'level_8' );
 745      $role->add_cap( 'level_7' );
 746      $role->add_cap( 'level_6' );
 747      $role->add_cap( 'level_5' );
 748      $role->add_cap( 'level_4' );
 749      $role->add_cap( 'level_3' );
 750      $role->add_cap( 'level_2' );
 751      $role->add_cap( 'level_1' );
 752      $role->add_cap( 'level_0' );
 753  
 754      // Add caps for Editor role
 755      $role = get_role( 'editor' );
 756      $role->add_cap( 'moderate_comments' );
 757      $role->add_cap( 'manage_categories' );
 758      $role->add_cap( 'manage_links' );
 759      $role->add_cap( 'upload_files' );
 760      $role->add_cap( 'unfiltered_html' );
 761      $role->add_cap( 'edit_posts' );
 762      $role->add_cap( 'edit_others_posts' );
 763      $role->add_cap( 'edit_published_posts' );
 764      $role->add_cap( 'publish_posts' );
 765      $role->add_cap( 'edit_pages' );
 766      $role->add_cap( 'read' );
 767      $role->add_cap( 'level_7' );
 768      $role->add_cap( 'level_6' );
 769      $role->add_cap( 'level_5' );
 770      $role->add_cap( 'level_4' );
 771      $role->add_cap( 'level_3' );
 772      $role->add_cap( 'level_2' );
 773      $role->add_cap( 'level_1' );
 774      $role->add_cap( 'level_0' );
 775  
 776      // Add caps for Author role
 777      $role = get_role( 'author' );
 778      $role->add_cap( 'upload_files' );
 779      $role->add_cap( 'edit_posts' );
 780      $role->add_cap( 'edit_published_posts' );
 781      $role->add_cap( 'publish_posts' );
 782      $role->add_cap( 'read' );
 783      $role->add_cap( 'level_2' );
 784      $role->add_cap( 'level_1' );
 785      $role->add_cap( 'level_0' );
 786  
 787      // Add caps for Contributor role
 788      $role = get_role( 'contributor' );
 789      $role->add_cap( 'edit_posts' );
 790      $role->add_cap( 'read' );
 791      $role->add_cap( 'level_1' );
 792      $role->add_cap( 'level_0' );
 793  
 794      // Add caps for Subscriber role
 795      $role = get_role( 'subscriber' );
 796      $role->add_cap( 'read' );
 797      $role->add_cap( 'level_0' );
 798  }
 799  
 800  /**
 801   * Create and modify WordPress roles for WordPress 2.1.
 802   *
 803   * @since 2.1.0
 804   */
 805  function populate_roles_210() {
 806      $roles = array( 'administrator', 'editor' );
 807      foreach ( $roles as $role ) {
 808          $role = get_role( $role );
 809          if ( empty( $role ) ) {
 810              continue;
 811          }
 812  
 813          $role->add_cap( 'edit_others_pages' );
 814          $role->add_cap( 'edit_published_pages' );
 815          $role->add_cap( 'publish_pages' );
 816          $role->add_cap( 'delete_pages' );
 817          $role->add_cap( 'delete_others_pages' );
 818          $role->add_cap( 'delete_published_pages' );
 819          $role->add_cap( 'delete_posts' );
 820          $role->add_cap( 'delete_others_posts' );
 821          $role->add_cap( 'delete_published_posts' );
 822          $role->add_cap( 'delete_private_posts' );
 823          $role->add_cap( 'edit_private_posts' );
 824          $role->add_cap( 'read_private_posts' );
 825          $role->add_cap( 'delete_private_pages' );
 826          $role->add_cap( 'edit_private_pages' );
 827          $role->add_cap( 'read_private_pages' );
 828      }
 829  
 830      $role = get_role( 'administrator' );
 831      if ( ! empty( $role ) ) {
 832          $role->add_cap( 'delete_users' );
 833          $role->add_cap( 'create_users' );
 834      }
 835  
 836      $role = get_role( 'author' );
 837      if ( ! empty( $role ) ) {
 838          $role->add_cap( 'delete_posts' );
 839          $role->add_cap( 'delete_published_posts' );
 840      }
 841  
 842      $role = get_role( 'contributor' );
 843      if ( ! empty( $role ) ) {
 844          $role->add_cap( 'delete_posts' );
 845      }
 846  }
 847  
 848  /**
 849   * Create and modify WordPress roles for WordPress 2.3.
 850   *
 851   * @since 2.3.0
 852   */
 853  function populate_roles_230() {
 854      $role = get_role( 'administrator' );
 855  
 856      if ( ! empty( $role ) ) {
 857          $role->add_cap( 'unfiltered_upload' );
 858      }
 859  }
 860  
 861  /**
 862   * Create and modify WordPress roles for WordPress 2.5.
 863   *
 864   * @since 2.5.0
 865   */
 866  function populate_roles_250() {
 867      $role = get_role( 'administrator' );
 868  
 869      if ( ! empty( $role ) ) {
 870          $role->add_cap( 'edit_dashboard' );
 871      }
 872  }
 873  
 874  /**
 875   * Create and modify WordPress roles for WordPress 2.6.
 876   *
 877   * @since 2.6.0
 878   */
 879  function populate_roles_260() {
 880      $role = get_role( 'administrator' );
 881  
 882      if ( ! empty( $role ) ) {
 883          $role->add_cap( 'update_plugins' );
 884          $role->add_cap( 'delete_plugins' );
 885      }
 886  }
 887  
 888  /**
 889   * Create and modify WordPress roles for WordPress 2.7.
 890   *
 891   * @since 2.7.0
 892   */
 893  function populate_roles_270() {
 894      $role = get_role( 'administrator' );
 895  
 896      if ( ! empty( $role ) ) {
 897          $role->add_cap( 'install_plugins' );
 898          $role->add_cap( 'update_themes' );
 899      }
 900  }
 901  
 902  /**
 903   * Create and modify WordPress roles for WordPress 2.8.
 904   *
 905   * @since 2.8.0
 906   */
 907  function populate_roles_280() {
 908      $role = get_role( 'administrator' );
 909  
 910      if ( ! empty( $role ) ) {
 911          $role->add_cap( 'install_themes' );
 912      }
 913  }
 914  
 915  /**
 916   * Create and modify WordPress roles for WordPress 3.0.
 917   *
 918   * @since 3.0.0
 919   */
 920  function populate_roles_300() {
 921      $role = get_role( 'administrator' );
 922  
 923      if ( ! empty( $role ) ) {
 924          $role->add_cap( 'update_core' );
 925          $role->add_cap( 'list_users' );
 926          $role->add_cap( 'remove_users' );
 927          $role->add_cap( 'promote_users' );
 928          $role->add_cap( 'edit_theme_options' );
 929          $role->add_cap( 'delete_themes' );
 930          $role->add_cap( 'export' );
 931      }
 932  }
 933  
 934  if ( ! function_exists( 'install_network' ) ) :
 935      /**
 936       * Install Network.
 937       *
 938       * @since 3.0.0
 939       */
 940  	function install_network() {
 941          if ( ! defined( 'WP_INSTALLING_NETWORK' ) ) {
 942              define( 'WP_INSTALLING_NETWORK', true );
 943          }
 944  
 945          dbDelta( wp_get_db_schema( 'global' ) );
 946      }
 947  endif;
 948  
 949  /**
 950   * Populate network settings.
 951   *
 952   * @since 3.0.0
 953   *
 954   * @global wpdb       $wpdb         WordPress database abstraction object.
 955   * @global object     $current_site
 956   * @global WP_Rewrite $wp_rewrite   WordPress rewrite component.
 957   *
 958   * @param int    $network_id        ID of network to populate.
 959   * @param string $domain            The domain name for the network (eg. "example.com").
 960   * @param string $email             Email address for the network administrator.
 961   * @param string $site_name         The name of the network.
 962   * @param string $path              Optional. The path to append to the network's domain name. Default '/'.
 963   * @param bool   $subdomain_install Optional. Whether the network is a subdomain installation or a subdirectory installation.
 964   *                                  Default false, meaning the network is a subdirectory installation.
 965   * @return bool|WP_Error True on success, or WP_Error on warning (with the installation otherwise successful,
 966   *                       so the error code must be checked) or failure.
 967   */
 968  function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
 969      global $wpdb, $current_site, $wp_rewrite;
 970  
 971      $errors = new WP_Error();
 972      if ( '' == $domain ) {
 973          $errors->add( 'empty_domain', __( 'You must provide a domain name.' ) );
 974      }
 975      if ( '' == $site_name ) {
 976          $errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) );
 977      }
 978  
 979      // Check for network collision.
 980      $network_exists = false;
 981      if ( is_multisite() ) {
 982          if ( get_network( (int) $network_id ) ) {
 983              $errors->add( 'siteid_exists', __( 'The network already exists.' ) );
 984          }
 985      } else {
 986          if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) {
 987              $errors->add( 'siteid_exists', __( 'The network already exists.' ) );
 988          }
 989      }
 990  
 991      if ( ! is_email( $email ) ) {
 992          $errors->add( 'invalid_email', __( 'You must provide a valid email address.' ) );
 993      }
 994  
 995      if ( $errors->has_errors() ) {
 996          return $errors;
 997      }
 998  
 999      if ( 1 == $network_id ) {
1000          $wpdb->insert(
1001              $wpdb->site,
1002              array(
1003                  'domain' => $domain,
1004                  'path'   => $path,
1005              )
1006          );
1007          $network_id = $wpdb->insert_id;
1008      } else {
1009          $wpdb->insert(
1010              $wpdb->site,
1011              array(
1012                  'domain' => $domain,
1013                  'path'   => $path,
1014                  'id'     => $network_id,
1015              )
1016          );
1017      }
1018  
1019      populate_network_meta(
1020          $network_id,
1021          array(
1022              'admin_email'       => $email,
1023              'site_name'         => $site_name,
1024              'subdomain_install' => $subdomain_install,
1025          )
1026      );
1027  
1028      $site_user = get_userdata( (int) $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", 'admin_user_id', $network_id ) ) );
1029  
1030      /*
1031       * When upgrading from single to multisite, assume the current site will
1032       * become the main site of the network. When using populate_network()
1033       * to create another network in an existing multisite environment, skip
1034       * these steps since the main site of the new network has not yet been
1035       * created.
1036       */
1037      if ( ! is_multisite() ) {
1038          $current_site            = new stdClass;
1039          $current_site->domain    = $domain;
1040          $current_site->path      = $path;
1041          $current_site->site_name = ucfirst( $domain );
1042          $wpdb->insert(
1043              $wpdb->blogs,
1044              array(
1045                  'site_id'    => $network_id,
1046                  'blog_id'    => 1,
1047                  'domain'     => $domain,
1048                  'path'       => $path,
1049                  'registered' => current_time( 'mysql' ),
1050              )
1051          );
1052          $current_site->blog_id = $wpdb->insert_id;
1053          update_user_meta( $site_user->ID, 'source_domain', $domain );
1054          update_user_meta( $site_user->ID, 'primary_blog', $current_site->blog_id );
1055  
1056          if ( $subdomain_install ) {
1057              $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
1058          } else {
1059              $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' );
1060          }
1061  
1062          flush_rewrite_rules();
1063  
1064          if ( ! $subdomain_install ) {
1065              return true;
1066          }
1067  
1068          $vhost_ok = false;
1069          $errstr   = '';
1070          $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname!
1071          $page     = wp_remote_get(
1072              'http://' . $hostname,
1073              array(
1074                  'timeout'     => 5,
1075                  'httpversion' => '1.1',
1076              )
1077          );
1078          if ( is_wp_error( $page ) ) {
1079              $errstr = $page->get_error_message();
1080          } elseif ( 200 == wp_remote_retrieve_response_code( $page ) ) {
1081                  $vhost_ok = true;
1082          }
1083  
1084          if ( ! $vhost_ok ) {
1085              $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
1086  
1087              $msg .= '<p>' . sprintf(
1088                  /* translators: %s: Host name. */
1089                  __( 'The installer attempted to contact a random hostname (%s) on your domain.' ),
1090                  '<code>' . $hostname . '</code>'
1091              );
1092              if ( ! empty( $errstr ) ) {
1093                  /* translators: %s: Error message. */
1094                  $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
1095              }
1096              $msg .= '</p>';
1097  
1098              $msg .= '<p>' . sprintf(
1099                  /* translators: %s: Asterisk symbol (*). */
1100                  __( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a %s hostname record pointing at your web server in your DNS configuration tool.' ),
1101                  '<code>*</code>'
1102              ) . '</p>';
1103  
1104              $msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '</p>';
1105  
1106              return new WP_Error( 'no_wildcard_dns', $msg );
1107          }
1108      }
1109  
1110      return true;
1111  }
1112  
1113  /**
1114   * Creates WordPress network meta and sets the default values.
1115   *
1116   * @since 5.1.0
1117   *
1118   * @global wpdb $wpdb          WordPress database abstraction object.
1119   * @global int  $wp_db_version WordPress database version.
1120   *
1121   * @param int   $network_id Network ID to populate meta for.
1122   * @param array $meta       Optional. Custom meta $key => $value pairs to use. Default empty array.
1123   */
1124  function populate_network_meta( $network_id, array $meta = array() ) {
1125      global $wpdb, $wp_db_version;
1126  
1127      $network_id = (int) $network_id;
1128  
1129      $email             = ! empty( $meta['admin_email'] ) ? $meta['admin_email'] : '';
1130      $subdomain_install = isset( $meta['subdomain_install'] ) ? (int) $meta['subdomain_install'] : 0;
1131  
1132      // If a user with the provided email does not exist, default to the current user as the new network admin.
1133      $site_user = ! empty( $email ) ? get_user_by( 'email', $email ) : false;
1134      if ( false === $site_user ) {
1135          $site_user = wp_get_current_user();
1136      }
1137  
1138      if ( empty( $email ) ) {
1139          $email = $site_user->user_email;
1140      }
1141  
1142      $template       = get_option( 'template' );
1143      $stylesheet     = get_option( 'stylesheet' );
1144      $allowed_themes = array( $stylesheet => true );
1145  
1146      if ( $template != $stylesheet ) {
1147          $allowed_themes[ $template ] = true;
1148      }
1149  
1150      if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) {
1151          $allowed_themes[ WP_DEFAULT_THEME ] = true;
1152      }
1153  
1154      // If WP_DEFAULT_THEME doesn't exist, also whitelist the latest core default theme.
1155      if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) {
1156          $core_default = WP_Theme::get_core_default_theme();
1157          if ( $core_default ) {
1158              $allowed_themes[ $core_default->get_stylesheet() ] = true;
1159          }
1160      }
1161  
1162      if ( function_exists( 'clean_network_cache' ) ) {
1163          clean_network_cache( $network_id );
1164      } else {
1165          wp_cache_delete( $network_id, 'networks' );
1166      }
1167  
1168      wp_cache_delete( 'networks_have_paths', 'site-options' );
1169  
1170      if ( ! is_multisite() ) {
1171          $site_admins = array( $site_user->user_login );
1172          $users       = get_users(
1173              array(
1174                  'fields' => array( 'user_login' ),
1175                  'role'   => 'administrator',
1176              )
1177          );
1178          if ( $users ) {
1179              foreach ( $users as $user ) {
1180                  $site_admins[] = $user->user_login;
1181              }
1182  
1183              $site_admins = array_unique( $site_admins );
1184          }
1185      } else {
1186          $site_admins = get_site_option( 'site_admins' );
1187      }
1188  
1189      /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */
1190      $welcome_email = __(
1191          'Howdy USERNAME,
1192  
1193  Your new SITE_NAME site has been successfully set up at:
1194  BLOG_URL
1195  
1196  You can log in to the administrator account with the following information:
1197  
1198  Username: USERNAME
1199  Password: PASSWORD
1200  Log in here: BLOG_URLwp-login.php
1201  
1202  We hope you enjoy your new site. Thanks!
1203  
1204  --The Team @ SITE_NAME'
1205      );
1206  
1207      $misc_exts        = array(
1208          // Images.
1209          'jpg',
1210          'jpeg',
1211          'png',
1212          'gif',
1213          // Video.
1214          'mov',
1215          'avi',
1216          'mpg',
1217          '3gp',
1218          '3g2',
1219          // "audio".
1220          'midi',
1221          'mid',
1222          // Miscellaneous.
1223          'pdf',
1224          'doc',
1225          'ppt',
1226          'odt',
1227          'pptx',
1228          'docx',
1229          'pps',
1230          'ppsx',
1231          'xls',
1232          'xlsx',
1233          'key',
1234      );
1235      $audio_exts       = wp_get_audio_extensions();
1236      $video_exts       = wp_get_video_extensions();
1237      $upload_filetypes = array_unique( array_merge( $misc_exts, $audio_exts, $video_exts ) );
1238  
1239      $sitemeta = array(
1240          'site_name'                   => __( 'My Network' ),
1241          'admin_email'                 => $email,
1242          'admin_user_id'               => $site_user->ID,
1243          'registration'                => 'none',
1244          'upload_filetypes'            => implode( ' ', $upload_filetypes ),
1245          'blog_upload_space'           => 100,
1246          'fileupload_maxk'             => 1500,
1247          'site_admins'                 => $site_admins,
1248          'allowedthemes'               => $allowed_themes,
1249          'illegal_names'               => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ),
1250          'wpmu_upgrade_site'           => $wp_db_version,
1251          'welcome_email'               => $welcome_email,
1252          /* translators: %s: Site link. */
1253          'first_post'                  => __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ),
1254          // @todo - network admins should have a method of editing the network siteurl (used for cookie hash)
1255          'siteurl'                     => get_option( 'siteurl' ) . '/',
1256          'add_new_users'               => '0',
1257          'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
1258          'subdomain_install'           => $subdomain_install,
1259          'global_terms_enabled'        => global_terms_enabled() ? '1' : '0',
1260          'ms_files_rewriting'          => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
1261          'initial_db_version'          => get_option( 'initial_db_version' ),
1262          'active_sitewide_plugins'     => array(),
1263          'WPLANG'                      => get_locale(),
1264      );
1265      if ( ! $subdomain_install ) {
1266          $sitemeta['illegal_names'][] = 'blog';
1267      }
1268  
1269      $sitemeta = wp_parse_args( $meta, $sitemeta );
1270  
1271      /**
1272       * Filters meta for a network on creation.
1273       *
1274       * @since 3.7.0
1275       *
1276       * @param array $sitemeta   Associative array of network meta keys and values to be inserted.
1277       * @param int   $network_id ID of network to populate.
1278       */
1279      $sitemeta = apply_filters( 'populate_network_meta', $sitemeta, $network_id );
1280  
1281      $insert = '';
1282      foreach ( $sitemeta as $meta_key => $meta_value ) {
1283          if ( is_array( $meta_value ) ) {
1284              $meta_value = serialize( $meta_value );
1285          }
1286          if ( ! empty( $insert ) ) {
1287              $insert .= ', ';
1288          }
1289          $insert .= $wpdb->prepare( '( %d, %s, %s)', $network_id, $meta_key, $meta_value );
1290      }
1291      $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
1292  }
1293  
1294  /**
1295   * Creates WordPress site meta and sets the default values.
1296   *
1297   * @since 5.1.0
1298   *
1299   * @global wpdb $wpdb WordPress database abstraction object.
1300   *
1301   * @param int   $site_id Site ID to populate meta for.
1302   * @param array $meta    Optional. Custom meta $key => $value pairs to use. Default empty array.
1303   */
1304  function populate_site_meta( $site_id, array $meta = array() ) {
1305      global $wpdb;
1306  
1307      $site_id = (int) $site_id;
1308  
1309      if ( ! is_site_meta_supported() ) {
1310          return;
1311      }
1312  
1313      if ( empty( $meta ) ) {
1314          return;
1315      }
1316  
1317      /**
1318       * Filters meta for a site on creation.
1319       *
1320       * @since 5.2.0
1321       *
1322       * @param array $meta    Associative array of site meta keys and values to be inserted.
1323       * @param int   $site_id ID of site to populate.
1324       */
1325      $site_meta = apply_filters( 'populate_site_meta', $meta, $site_id );
1326  
1327      $insert = '';
1328      foreach ( $site_meta as $meta_key => $meta_value ) {
1329          if ( is_array( $meta_value ) ) {
1330              $meta_value = serialize( $meta_value );
1331          }
1332          if ( ! empty( $insert ) ) {
1333              $insert .= ', ';
1334          }
1335          $insert .= $wpdb->prepare( '( %d, %s, %s)', $site_id, $meta_key, $meta_value );
1336      }
1337  
1338      $wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
1339  
1340      wp_cache_delete( $site_id, 'blog_meta' );
1341      wp_cache_set_sites_last_changed();
1342  }


Generated: Thu Sep 19 01:00:03 2019 Cross-referenced by PHPXref 0.7.1