[ Index ]

WordPress 5.4.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

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


Generated: Tue May 19 15:51:04 2020 Cross-referenced by PHPXref 0.7.1