wp/wp-admin/includes/schema.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     9  */
     9  */
    10 
    10 
    11 /**
    11 /**
    12  * Declare these as global in case schema.php is included from a function.
    12  * Declare these as global in case schema.php is included from a function.
    13  *
    13  *
    14  * @global wpdb   $wpdb
    14  * @global wpdb   $wpdb            WordPress database abstraction object.
    15  * @global array  $wp_queries
    15  * @global array  $wp_queries
    16  * @global string $charset_collate
    16  * @global string $charset_collate
    17  */
    17  */
    18 global $wpdb, $wp_queries, $charset_collate;
    18 global $wpdb, $wp_queries, $charset_collate;
    19 
    19 
    27  *
    27  *
    28  * @since 3.3.0
    28  * @since 3.3.0
    29  *
    29  *
    30  * @global wpdb $wpdb WordPress database abstraction object.
    30  * @global wpdb $wpdb WordPress database abstraction object.
    31  *
    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.
    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.
    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.
    34  * @return string The SQL needed to create the requested tables.
    35  */
    35  */
    36 function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
    36 function wp_get_db_schema( $scope = 'all', $blog_id = null ) {
    37 	global $wpdb;
    37 	global $wpdb;
    38 
    38 
    50 	 * As of 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which
    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.
    51 	 * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
    52 	 */
    52 	 */
    53 	$max_index_length = 191;
    53 	$max_index_length = 191;
    54 
    54 
    55 	// Blog specific tables.
    55 	// Blog-specific tables.
    56 	$blog_tables = "CREATE TABLE $wpdb->termmeta (
    56 	$blog_tables = "CREATE TABLE $wpdb->termmeta (
    57 	meta_id bigint(20) unsigned NOT NULL auto_increment,
    57 	meta_id bigint(20) unsigned NOT NULL auto_increment,
    58 	term_id bigint(20) unsigned NOT NULL default '0',
    58 	term_id bigint(20) unsigned NOT NULL default '0',
    59 	meta_key varchar(255) default NULL,
    59 	meta_key varchar(255) default NULL,
    60 	meta_value longtext,
    60 	meta_value longtext,
   109 	comment_date_gmt 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,
   110 	comment_content text NOT NULL,
   111 	comment_karma int(11) NOT NULL default '0',
   111 	comment_karma int(11) NOT NULL default '0',
   112 	comment_approved varchar(20) NOT NULL default '1',
   112 	comment_approved varchar(20) NOT NULL default '1',
   113 	comment_agent varchar(255) NOT NULL default '',
   113 	comment_agent varchar(255) NOT NULL default '',
   114 	comment_type varchar(20) NOT NULL default '',
   114 	comment_type varchar(20) NOT NULL default 'comment',
   115 	comment_parent bigint(20) unsigned NOT NULL default '0',
   115 	comment_parent bigint(20) unsigned NOT NULL default '0',
   116 	user_id bigint(20) unsigned NOT NULL default '0',
   116 	user_id bigint(20) unsigned NOT NULL default '0',
   117 	PRIMARY KEY  (comment_ID),
   117 	PRIMARY KEY  (comment_ID),
   118 	KEY comment_post_ID (comment_post_ID),
   118 	KEY comment_post_ID (comment_post_ID),
   119 	KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
   119 	KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
   142 	option_id bigint(20) unsigned NOT NULL auto_increment,
   142 	option_id bigint(20) unsigned NOT NULL auto_increment,
   143 	option_name varchar(191) NOT NULL default '',
   143 	option_name varchar(191) NOT NULL default '',
   144 	option_value longtext NOT NULL,
   144 	option_value longtext NOT NULL,
   145 	autoload varchar(20) NOT NULL default 'yes',
   145 	autoload varchar(20) NOT NULL default 'yes',
   146 	PRIMARY KEY  (option_id),
   146 	PRIMARY KEY  (option_id),
   147 	UNIQUE KEY option_name (option_name)
   147 	UNIQUE KEY option_name (option_name),
       
   148 	KEY autoload (autoload)
   148 ) $charset_collate;
   149 ) $charset_collate;
   149 CREATE TABLE $wpdb->postmeta (
   150 CREATE TABLE $wpdb->postmeta (
   150 	meta_id bigint(20) unsigned NOT NULL auto_increment,
   151 	meta_id bigint(20) unsigned NOT NULL auto_increment,
   151 	post_id bigint(20) unsigned NOT NULL default '0',
   152 	post_id bigint(20) unsigned NOT NULL default '0',
   152 	meta_key varchar(255) default NULL,
   153 	meta_key varchar(255) default NULL,
   202 	KEY user_login_key (user_login),
   203 	KEY user_login_key (user_login),
   203 	KEY user_nicename (user_nicename),
   204 	KEY user_nicename (user_nicename),
   204 	KEY user_email (user_email)
   205 	KEY user_email (user_email)
   205 ) $charset_collate;\n";
   206 ) $charset_collate;\n";
   206 
   207 
   207 	// Multisite users table
   208 	// Multisite users table.
   208 	$users_multi_table = "CREATE TABLE $wpdb->users (
   209 	$users_multi_table = "CREATE TABLE $wpdb->users (
   209 	ID bigint(20) unsigned NOT NULL auto_increment,
   210 	ID bigint(20) unsigned NOT NULL auto_increment,
   210 	user_login varchar(60) NOT NULL default '',
   211 	user_login varchar(60) NOT NULL default '',
   211 	user_pass varchar(255) NOT NULL default '',
   212 	user_pass varchar(255) NOT NULL default '',
   212 	user_nicename varchar(50) NOT NULL default '',
   213 	user_nicename varchar(50) NOT NULL default '',
   233 	PRIMARY KEY  (umeta_id),
   234 	PRIMARY KEY  (umeta_id),
   234 	KEY user_id (user_id),
   235 	KEY user_id (user_id),
   235 	KEY meta_key (meta_key($max_index_length))
   236 	KEY meta_key (meta_key($max_index_length))
   236 ) $charset_collate;\n";
   237 ) $charset_collate;\n";
   237 
   238 
   238 	// Global tables
   239 	// Global tables.
   239 	if ( $is_multisite ) {
   240 	if ( $is_multisite ) {
   240 		$global_tables = $users_multi_table . $usermeta_table;
   241 		$global_tables = $users_multi_table . $usermeta_table;
   241 	} else {
   242 	} else {
   242 		$global_tables = $users_single_table . $usermeta_table;
   243 		$global_tables = $users_single_table . $usermeta_table;
   243 	}
   244 	}
   257 	deleted tinyint(2) NOT NULL default '0',
   258 	deleted tinyint(2) NOT NULL default '0',
   258 	lang_id int(11) NOT NULL default '0',
   259 	lang_id int(11) NOT NULL default '0',
   259 	PRIMARY KEY  (blog_id),
   260 	PRIMARY KEY  (blog_id),
   260 	KEY domain (domain(50),path(5)),
   261 	KEY domain (domain(50),path(5)),
   261 	KEY lang_id (lang_id)
   262 	KEY lang_id (lang_id)
   262 ) $charset_collate;
       
   263 CREATE TABLE $wpdb->blog_versions (
       
   264 	blog_id bigint(20) NOT NULL default '0',
       
   265 	db_version varchar(20) NOT NULL default '',
       
   266 	last_updated datetime NOT NULL default '0000-00-00 00:00:00',
       
   267 	PRIMARY KEY  (blog_id),
       
   268 	KEY db_version (db_version)
       
   269 ) $charset_collate;
   263 ) $charset_collate;
   270 CREATE TABLE $wpdb->blogmeta (
   264 CREATE TABLE $wpdb->blogmeta (
   271 	meta_id bigint(20) unsigned NOT NULL auto_increment,
   265 	meta_id bigint(20) unsigned NOT NULL auto_increment,
   272 	blog_id bigint(20) NOT NULL default '0',
   266 	blog_id bigint(20) NOT NULL default '0',
   273 	meta_key varchar(255) default NULL,
   267 	meta_key varchar(255) default NULL,
   356  * Create WordPress options and set the default values.
   350  * Create WordPress options and set the default values.
   357  *
   351  *
   358  * @since 1.5.0
   352  * @since 1.5.0
   359  * @since 5.1.0 The $options parameter has been added.
   353  * @since 5.1.0 The $options parameter has been added.
   360  *
   354  *
   361  * @global wpdb $wpdb WordPress database abstraction object.
   355  * @global wpdb $wpdb                  WordPress database abstraction object.
   362  * @global int  $wp_db_version
   356  * @global int  $wp_db_version         WordPress database version.
   363  * @global int  $wp_current_db_version
   357  * @global int  $wp_current_db_version The old (current) database version.
   364  *
   358  *
   365  * @param array $options Optional. Custom option $key => $value pairs to use. Default empty array.
   359  * @param array $options Optional. Custom option $key => $value pairs to use. Default empty array.
   366  */
   360  */
   367 function populate_options( array $options = array() ) {
   361 function populate_options( array $options = array() ) {
   368 	global $wpdb, $wp_db_version, $wp_current_db_version;
   362 	global $wpdb, $wp_db_version, $wp_current_db_version;
   373 	 *
   367 	 *
   374 	 * @since 2.6.0
   368 	 * @since 2.6.0
   375 	 */
   369 	 */
   376 	do_action( 'populate_options' );
   370 	do_action( 'populate_options' );
   377 
   371 
   378 	if ( ini_get( 'safe_mode' ) ) {
       
   379 		// Safe mode can break mkdir() so use a flat structure by default.
       
   380 		$uploads_use_yearmonth_folders = 0;
       
   381 	} else {
       
   382 		$uploads_use_yearmonth_folders = 1;
       
   383 	}
       
   384 
       
   385 	// If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
   372 	// If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
   386 	$stylesheet = WP_DEFAULT_THEME;
   373 	$stylesheet = WP_DEFAULT_THEME;
   387 	$template   = WP_DEFAULT_THEME;
   374 	$template   = WP_DEFAULT_THEME;
   388 	$theme      = wp_get_theme( WP_DEFAULT_THEME );
   375 	$theme      = wp_get_theme( WP_DEFAULT_THEME );
   389 	if ( ! $theme->exists() ) {
   376 	if ( ! $theme->exists() ) {
   398 
   385 
   399 	$timezone_string = '';
   386 	$timezone_string = '';
   400 	$gmt_offset      = 0;
   387 	$gmt_offset      = 0;
   401 	/*
   388 	/*
   402 	 * translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
   389 	 * translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
   403 	 * or a valid timezone string (America/New_York). See https://secure.php.net/manual/en/timezones.php
   390 	 * or a valid timezone string (America/New_York). See https://www.php.net/manual/en/timezones.php
   404 	 * for all timezone strings supported by PHP.
   391 	 * for all timezone strings supported by PHP.
   405 	 */
   392 	 */
   406 	$offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings
   393 	$offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings
   407 	if ( is_numeric( $offset_or_tz ) ) {
   394 	if ( is_numeric( $offset_or_tz ) ) {
   408 		$gmt_offset = $offset_or_tz;
   395 		$gmt_offset = $offset_or_tz;
   409 	} elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) ) {
   396 	} elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list(), true ) ) {
   410 			$timezone_string = $offset_or_tz;
   397 			$timezone_string = $offset_or_tz;
   411 	}
   398 	}
   412 
   399 
   413 	$defaults = array(
   400 	$defaults = array(
   414 		'siteurl'                         => $guessurl,
   401 		'siteurl'                         => $guessurl,
   415 		'home'                            => $guessurl,
   402 		'home'                            => $guessurl,
   416 		'blogname'                        => __( 'My Site' ),
   403 		'blogname'                        => __( 'My Site' ),
   417 		/* translators: site tagline */
   404 		/* translators: Site tagline. */
   418 		'blogdescription'                 => __( 'Just another WordPress site' ),
   405 		'blogdescription'                 => __( 'Just another WordPress site' ),
   419 		'users_can_register'              => 0,
   406 		'users_can_register'              => 0,
   420 		'admin_email'                     => 'you@example.com',
   407 		'admin_email'                     => 'you@example.com',
   421 		/* translators: default start of the week. 0 = Sunday, 1 = Monday */
   408 		/* translators: Default start of the week. 0 = Sunday, 1 = Monday. */
   422 		'start_of_week'                   => _x( '1', 'start of week' ),
   409 		'start_of_week'                   => _x( '1', 'start of week' ),
   423 		'use_balanceTags'                 => 0,
   410 		'use_balanceTags'                 => 0,
   424 		'use_smilies'                     => 1,
   411 		'use_smilies'                     => 1,
   425 		'require_name_email'              => 1,
   412 		'require_name_email'              => 1,
   426 		'comments_notify'                 => 1,
   413 		'comments_notify'                 => 1,
   433 		'default_category'                => 1,
   420 		'default_category'                => 1,
   434 		'default_comment_status'          => 'open',
   421 		'default_comment_status'          => 'open',
   435 		'default_ping_status'             => 'open',
   422 		'default_ping_status'             => 'open',
   436 		'default_pingback_flag'           => 1,
   423 		'default_pingback_flag'           => 1,
   437 		'posts_per_page'                  => 10,
   424 		'posts_per_page'                  => 10,
   438 		/* translators: default date format, see https://secure.php.net/date */
   425 		/* translators: Default date format, see https://www.php.net/date */
   439 		'date_format'                     => __( 'F j, Y' ),
   426 		'date_format'                     => __( 'F j, Y' ),
   440 		/* translators: default time format, see https://secure.php.net/date */
   427 		/* translators: Default time format, see https://www.php.net/date */
   441 		'time_format'                     => __( 'g:i a' ),
   428 		'time_format'                     => __( 'g:i a' ),
   442 		/* translators: links last updated date format, see https://secure.php.net/date */
   429 		/* translators: Links last updated date format, see https://www.php.net/date */
   443 		'links_updated_date_format'       => __( 'F j, Y g:i a' ),
   430 		'links_updated_date_format'       => __( 'F j, Y g:i a' ),
   444 		'comment_moderation'              => 0,
   431 		'comment_moderation'              => 0,
   445 		'moderation_notify'               => 1,
   432 		'moderation_notify'               => 1,
   446 		'permalink_structure'             => '',
   433 		'permalink_structure'             => '',
   447 		'rewrite_rules'                   => '',
   434 		'rewrite_rules'                   => '',
   452 		'category_base'                   => '',
   439 		'category_base'                   => '',
   453 		'ping_sites'                      => 'http://rpc.pingomatic.com/',
   440 		'ping_sites'                      => 'http://rpc.pingomatic.com/',
   454 		'comment_max_links'               => 2,
   441 		'comment_max_links'               => 2,
   455 		'gmt_offset'                      => $gmt_offset,
   442 		'gmt_offset'                      => $gmt_offset,
   456 
   443 
   457 		// 1.5
   444 		// 1.5.0
   458 		'default_email_category'          => 1,
   445 		'default_email_category'          => 1,
   459 		'recently_edited'                 => '',
   446 		'recently_edited'                 => '',
   460 		'template'                        => $template,
   447 		'template'                        => $template,
   461 		'stylesheet'                      => $stylesheet,
   448 		'stylesheet'                      => $stylesheet,
   462 		'comment_whitelist'               => 1,
       
   463 		'blacklist_keys'                  => '',
       
   464 		'comment_registration'            => 0,
   449 		'comment_registration'            => 0,
   465 		'html_type'                       => 'text/html',
   450 		'html_type'                       => 'text/html',
   466 
   451 
   467 		// 1.5.1
   452 		// 1.5.1
   468 		'use_trackback'                   => 0,
   453 		'use_trackback'                   => 0,
   469 
   454 
   470 		// 2.0
   455 		// 2.0.0
   471 		'default_role'                    => 'subscriber',
   456 		'default_role'                    => 'subscriber',
   472 		'db_version'                      => $wp_db_version,
   457 		'db_version'                      => $wp_db_version,
   473 
   458 
   474 		// 2.0.1
   459 		// 2.0.1
   475 		'uploads_use_yearmonth_folders'   => $uploads_use_yearmonth_folders,
   460 		'uploads_use_yearmonth_folders'   => 1,
   476 		'upload_path'                     => '',
   461 		'upload_path'                     => '',
   477 
   462 
   478 		// 2.1
   463 		// 2.1.0
   479 		'blog_public'                     => '1',
   464 		'blog_public'                     => '1',
   480 		'default_link_category'           => 2,
   465 		'default_link_category'           => 2,
   481 		'show_on_front'                   => 'posts',
   466 		'show_on_front'                   => 'posts',
   482 
   467 
   483 		// 2.2
   468 		// 2.2.0
   484 		'tag_base'                        => '',
   469 		'tag_base'                        => '',
   485 
   470 
   486 		// 2.5
   471 		// 2.5.0
   487 		'show_avatars'                    => '1',
   472 		'show_avatars'                    => '1',
   488 		'avatar_rating'                   => 'G',
   473 		'avatar_rating'                   => 'G',
   489 		'upload_url_path'                 => '',
   474 		'upload_url_path'                 => '',
   490 		'thumbnail_size_w'                => 150,
   475 		'thumbnail_size_w'                => 150,
   491 		'thumbnail_size_h'                => 150,
   476 		'thumbnail_size_h'                => 150,
   492 		'thumbnail_crop'                  => 1,
   477 		'thumbnail_crop'                  => 1,
   493 		'medium_size_w'                   => 300,
   478 		'medium_size_w'                   => 300,
   494 		'medium_size_h'                   => 300,
   479 		'medium_size_h'                   => 300,
   495 
   480 
   496 		// 2.6
   481 		// 2.6.0
   497 		'avatar_default'                  => 'mystery',
   482 		'avatar_default'                  => 'mystery',
   498 
   483 
   499 		// 2.7
   484 		// 2.7.0
   500 		'large_size_w'                    => 1024,
   485 		'large_size_w'                    => 1024,
   501 		'large_size_h'                    => 1024,
   486 		'large_size_h'                    => 1024,
   502 		'image_default_link_type'         => 'none',
   487 		'image_default_link_type'         => 'none',
   503 		'image_default_size'              => '',
   488 		'image_default_size'              => '',
   504 		'image_default_align'             => '',
   489 		'image_default_align'             => '',
   514 		'widget_categories'               => array(),
   499 		'widget_categories'               => array(),
   515 		'widget_text'                     => array(),
   500 		'widget_text'                     => array(),
   516 		'widget_rss'                      => array(),
   501 		'widget_rss'                      => array(),
   517 		'uninstall_plugins'               => array(),
   502 		'uninstall_plugins'               => array(),
   518 
   503 
   519 		// 2.8
   504 		// 2.8.0
   520 		'timezone_string'                 => $timezone_string,
   505 		'timezone_string'                 => $timezone_string,
   521 
   506 
   522 		// 3.0
   507 		// 3.0.0
   523 		'page_for_posts'                  => 0,
   508 		'page_for_posts'                  => 0,
   524 		'page_on_front'                   => 0,
   509 		'page_on_front'                   => 0,
   525 
   510 
   526 		// 3.1
   511 		// 3.1.0
   527 		'default_post_format'             => 0,
   512 		'default_post_format'             => 0,
   528 
   513 
   529 		// 3.5
   514 		// 3.5.0
   530 		'link_manager_enabled'            => 0,
   515 		'link_manager_enabled'            => 0,
   531 
   516 
   532 		// 4.3.0
   517 		// 4.3.0
   533 		'finished_splitting_shared_terms' => 1,
   518 		'finished_splitting_shared_terms' => 1,
   534 		'site_icon'                       => 0,
   519 		'site_icon'                       => 0,
   540 		// 4.9.6
   525 		// 4.9.6
   541 		'wp_page_for_privacy_policy'      => 0,
   526 		'wp_page_for_privacy_policy'      => 0,
   542 
   527 
   543 		// 4.9.8
   528 		// 4.9.8
   544 		'show_comments_cookies_opt_in'    => 1,
   529 		'show_comments_cookies_opt_in'    => 1,
       
   530 
       
   531 		// 5.3.0
       
   532 		'admin_email_lifespan'            => ( time() + 6 * MONTH_IN_SECONDS ),
       
   533 
       
   534 		// 5.5.0
       
   535 		'disallowed_keys'                 => '',
       
   536 		'comment_previously_approved'     => 1,
       
   537 		'auto_plugin_theme_update_emails' => array(),
   545 	);
   538 	);
   546 
   539 
   547 	// 3.3
   540 	// 3.3.0
   548 	if ( ! is_multisite() ) {
   541 	if ( ! is_multisite() ) {
   549 		$defaults['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version
   542 		$defaults['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version
   550 			? $wp_current_db_version : $wp_db_version;
   543 			? $wp_current_db_version : $wp_db_version;
   551 	}
   544 	}
   552 
   545 
   553 	// 3.0 multisite
   546 	// 3.0.0 multisite.
   554 	if ( is_multisite() ) {
   547 	if ( is_multisite() ) {
   555 		/* translators: site tagline */
   548 		/* translators: %s: Network title. */
   556 		$defaults['blogdescription']     = sprintf( __( 'Just another %s site' ), get_network()->site_name );
   549 		$defaults['blogdescription']     = sprintf( __( 'Just another %s site' ), get_network()->site_name );
   557 		$defaults['permalink_structure'] = '/%year%/%monthnum%/%day%/%postname%/';
   550 		$defaults['permalink_structure'] = '/%year%/%monthnum%/%day%/%postname%/';
   558 	}
   551 	}
   559 
   552 
   560 	$options = wp_parse_args( $options, $defaults );
   553 	$options = wp_parse_args( $options, $defaults );
   561 
   554 
   562 	// Set autoload to no for these options
   555 	// Set autoload to no for these options.
   563 	$fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' );
   556 	$fat_options = array(
       
   557 		'moderation_keys',
       
   558 		'recently_edited',
       
   559 		'disallowed_keys',
       
   560 		'uninstall_plugins',
       
   561 		'auto_plugin_theme_update_emails',
       
   562 	);
   564 
   563 
   565 	$keys             = "'" . implode( "', '", array_keys( $options ) ) . "'";
   564 	$keys             = "'" . implode( "', '", array_keys( $options ) ) . "'";
   566 	$existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
   565 	$existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
   567 
   566 
   568 	$insert = '';
   567 	$insert = '';
       
   568 
   569 	foreach ( $options as $option => $value ) {
   569 	foreach ( $options as $option => $value ) {
   570 		if ( in_array( $option, $existing_options ) ) {
   570 		if ( in_array( $option, $existing_options, true ) ) {
   571 			continue;
   571 			continue;
   572 		}
   572 		}
   573 		if ( in_array( $option, $fat_options ) ) {
   573 
       
   574 		if ( in_array( $option, $fat_options, true ) ) {
   574 			$autoload = 'no';
   575 			$autoload = 'no';
   575 		} else {
   576 		} else {
   576 			$autoload = 'yes';
   577 			$autoload = 'yes';
   577 		}
   578 		}
   578 
   579 
   579 		if ( is_array( $value ) ) {
   580 		if ( is_array( $value ) ) {
   580 			$value = serialize( $value );
   581 			$value = serialize( $value );
   581 		}
   582 		}
       
   583 
   582 		if ( ! empty( $insert ) ) {
   584 		if ( ! empty( $insert ) ) {
   583 			$insert .= ', ';
   585 			$insert .= ', ';
   584 		}
   586 		}
       
   587 
   585 		$insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload );
   588 		$insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload );
   586 	}
   589 	}
   587 
   590 
   588 	if ( ! empty( $insert ) ) {
   591 	if ( ! empty( $insert ) ) {
   589 		$wpdb->query( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
   592 		$wpdb->query( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
   678 	}
   681 	}
   679 
   682 
   680 	// Delete obsolete magpie stuff.
   683 	// Delete obsolete magpie stuff.
   681 	$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'" );
   684 	$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'" );
   682 
   685 
   683 	// Clear expired transients
   686 	// Clear expired transients.
   684 	delete_expired_transients( true );
   687 	delete_expired_transients( true );
   685 }
   688 }
   686 
   689 
   687 /**
   690 /**
   688  * Execute WordPress role creation for the various WordPress versions.
   691  * Execute WordPress role creation for the various WordPress versions.
   704  * Create the roles for WordPress 2.0
   707  * Create the roles for WordPress 2.0
   705  *
   708  *
   706  * @since 2.0.0
   709  * @since 2.0.0
   707  */
   710  */
   708 function populate_roles_160() {
   711 function populate_roles_160() {
   709 	// Add roles
   712 	// Add roles.
   710 
       
   711 	add_role( 'administrator', 'Administrator' );
   713 	add_role( 'administrator', 'Administrator' );
   712 	add_role( 'editor', 'Editor' );
   714 	add_role( 'editor', 'Editor' );
   713 	add_role( 'author', 'Author' );
   715 	add_role( 'author', 'Author' );
   714 	add_role( 'contributor', 'Contributor' );
   716 	add_role( 'contributor', 'Contributor' );
   715 	add_role( 'subscriber', 'Subscriber' );
   717 	add_role( 'subscriber', 'Subscriber' );
   716 
   718 
   717 	// Add caps for Administrator role
   719 	// Add caps for Administrator role.
   718 	$role = get_role( 'administrator' );
   720 	$role = get_role( 'administrator' );
   719 	$role->add_cap( 'switch_themes' );
   721 	$role->add_cap( 'switch_themes' );
   720 	$role->add_cap( 'edit_themes' );
   722 	$role->add_cap( 'edit_themes' );
   721 	$role->add_cap( 'activate_plugins' );
   723 	$role->add_cap( 'activate_plugins' );
   722 	$role->add_cap( 'edit_plugins' );
   724 	$role->add_cap( 'edit_plugins' );
   745 	$role->add_cap( 'level_3' );
   747 	$role->add_cap( 'level_3' );
   746 	$role->add_cap( 'level_2' );
   748 	$role->add_cap( 'level_2' );
   747 	$role->add_cap( 'level_1' );
   749 	$role->add_cap( 'level_1' );
   748 	$role->add_cap( 'level_0' );
   750 	$role->add_cap( 'level_0' );
   749 
   751 
   750 	// Add caps for Editor role
   752 	// Add caps for Editor role.
   751 	$role = get_role( 'editor' );
   753 	$role = get_role( 'editor' );
   752 	$role->add_cap( 'moderate_comments' );
   754 	$role->add_cap( 'moderate_comments' );
   753 	$role->add_cap( 'manage_categories' );
   755 	$role->add_cap( 'manage_categories' );
   754 	$role->add_cap( 'manage_links' );
   756 	$role->add_cap( 'manage_links' );
   755 	$role->add_cap( 'upload_files' );
   757 	$role->add_cap( 'upload_files' );
   767 	$role->add_cap( 'level_3' );
   769 	$role->add_cap( 'level_3' );
   768 	$role->add_cap( 'level_2' );
   770 	$role->add_cap( 'level_2' );
   769 	$role->add_cap( 'level_1' );
   771 	$role->add_cap( 'level_1' );
   770 	$role->add_cap( 'level_0' );
   772 	$role->add_cap( 'level_0' );
   771 
   773 
   772 	// Add caps for Author role
   774 	// Add caps for Author role.
   773 	$role = get_role( 'author' );
   775 	$role = get_role( 'author' );
   774 	$role->add_cap( 'upload_files' );
   776 	$role->add_cap( 'upload_files' );
   775 	$role->add_cap( 'edit_posts' );
   777 	$role->add_cap( 'edit_posts' );
   776 	$role->add_cap( 'edit_published_posts' );
   778 	$role->add_cap( 'edit_published_posts' );
   777 	$role->add_cap( 'publish_posts' );
   779 	$role->add_cap( 'publish_posts' );
   778 	$role->add_cap( 'read' );
   780 	$role->add_cap( 'read' );
   779 	$role->add_cap( 'level_2' );
   781 	$role->add_cap( 'level_2' );
   780 	$role->add_cap( 'level_1' );
   782 	$role->add_cap( 'level_1' );
   781 	$role->add_cap( 'level_0' );
   783 	$role->add_cap( 'level_0' );
   782 
   784 
   783 	// Add caps for Contributor role
   785 	// Add caps for Contributor role.
   784 	$role = get_role( 'contributor' );
   786 	$role = get_role( 'contributor' );
   785 	$role->add_cap( 'edit_posts' );
   787 	$role->add_cap( 'edit_posts' );
   786 	$role->add_cap( 'read' );
   788 	$role->add_cap( 'read' );
   787 	$role->add_cap( 'level_1' );
   789 	$role->add_cap( 'level_1' );
   788 	$role->add_cap( 'level_0' );
   790 	$role->add_cap( 'level_0' );
   789 
   791 
   790 	// Add caps for Subscriber role
   792 	// Add caps for Subscriber role.
   791 	$role = get_role( 'subscriber' );
   793 	$role = get_role( 'subscriber' );
   792 	$role->add_cap( 'read' );
   794 	$role->add_cap( 'read' );
   793 	$role->add_cap( 'level_0' );
   795 	$role->add_cap( 'level_0' );
   794 }
   796 }
   795 
   797 
   945 /**
   947 /**
   946  * Populate network settings.
   948  * Populate network settings.
   947  *
   949  *
   948  * @since 3.0.0
   950  * @since 3.0.0
   949  *
   951  *
   950  * @global wpdb       $wpdb
   952  * @global wpdb       $wpdb         WordPress database abstraction object.
   951  * @global object     $current_site
   953  * @global object     $current_site
   952  * @global WP_Rewrite $wp_rewrite
   954  * @global WP_Rewrite $wp_rewrite   WordPress rewrite component.
   953  *
   955  *
   954  * @param int    $network_id        ID of network to populate.
   956  * @param int    $network_id        ID of network to populate.
   955  * @param string $domain            The domain name for the network (eg. "example.com").
   957  * @param string $domain            The domain name for the network (eg. "example.com").
   956  * @param string $email             Email address for the network administrator.
   958  * @param string $email             Email address for the network administrator.
   957  * @param string $site_name         The name of the network.
   959  * @param string $site_name         The name of the network.
   963  */
   965  */
   964 function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
   966 function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
   965 	global $wpdb, $current_site, $wp_rewrite;
   967 	global $wpdb, $current_site, $wp_rewrite;
   966 
   968 
   967 	$errors = new WP_Error();
   969 	$errors = new WP_Error();
   968 	if ( '' == $domain ) {
   970 	if ( '' === $domain ) {
   969 		$errors->add( 'empty_domain', __( 'You must provide a domain name.' ) );
   971 		$errors->add( 'empty_domain', __( 'You must provide a domain name.' ) );
   970 	}
   972 	}
   971 	if ( '' == $site_name ) {
   973 	if ( '' === $site_name ) {
   972 		$errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) );
   974 		$errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) );
   973 	}
   975 	}
   974 
   976 
   975 	// Check for network collision.
   977 	// Check for network collision.
   976 	$network_exists = false;
   978 	$network_exists = false;
  1079 
  1081 
  1080 		if ( ! $vhost_ok ) {
  1082 		if ( ! $vhost_ok ) {
  1081 			$msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
  1083 			$msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
  1082 
  1084 
  1083 			$msg .= '<p>' . sprintf(
  1085 			$msg .= '<p>' . sprintf(
  1084 				/* translators: %s: host name */
  1086 				/* translators: %s: Host name. */
  1085 				__( 'The installer attempted to contact a random hostname (%s) on your domain.' ),
  1087 				__( 'The installer attempted to contact a random hostname (%s) on your domain.' ),
  1086 				'<code>' . $hostname . '</code>'
  1088 				'<code>' . $hostname . '</code>'
  1087 			);
  1089 			);
  1088 			if ( ! empty( $errstr ) ) {
  1090 			if ( ! empty( $errstr ) ) {
  1089 				/* translators: %s: error message */
  1091 				/* translators: %s: Error message. */
  1090 				$msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
  1092 				$msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
  1091 			}
  1093 			}
  1092 			$msg .= '</p>';
  1094 			$msg .= '</p>';
  1093 
  1095 
  1094 			$msg .= '<p>' . sprintf(
  1096 			$msg .= '<p>' . sprintf(
  1095 				/* translators: %s: asterisk symbol (*) */
  1097 				/* translators: %s: Asterisk symbol (*). */
  1096 				__( '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.' ),
  1098 				__( '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.' ),
  1097 				'<code>*</code>'
  1099 				'<code>*</code>'
  1098 			) . '</p>';
  1100 			) . '</p>';
  1099 
  1101 
  1100 			$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>';
  1102 			$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>';
  1145 
  1147 
  1146 	if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) {
  1148 	if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) {
  1147 		$allowed_themes[ WP_DEFAULT_THEME ] = true;
  1149 		$allowed_themes[ WP_DEFAULT_THEME ] = true;
  1148 	}
  1150 	}
  1149 
  1151 
  1150 	// If WP_DEFAULT_THEME doesn't exist, also whitelist the latest core default theme.
  1152 	// If WP_DEFAULT_THEME doesn't exist, also include the latest core default theme.
  1151 	if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) {
  1153 	if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) {
  1152 		$core_default = WP_Theme::get_core_default_theme();
  1154 		$core_default = WP_Theme::get_core_default_theme();
  1153 		if ( $core_default ) {
  1155 		if ( $core_default ) {
  1154 			$allowed_themes[ $core_default->get_stylesheet() ] = true;
  1156 			$allowed_themes[ $core_default->get_stylesheet() ] = true;
  1155 		}
  1157 		}
       
  1158 	}
       
  1159 
       
  1160 	if ( function_exists( 'clean_network_cache' ) ) {
       
  1161 		clean_network_cache( $network_id );
       
  1162 	} else {
       
  1163 		wp_cache_delete( $network_id, 'networks' );
  1156 	}
  1164 	}
  1157 
  1165 
  1158 	wp_cache_delete( 'networks_have_paths', 'site-options' );
  1166 	wp_cache_delete( 'networks_have_paths', 'site-options' );
  1159 
  1167 
  1160 	if ( ! is_multisite() ) {
  1168 	if ( ! is_multisite() ) {
  1237 		'site_admins'                 => $site_admins,
  1245 		'site_admins'                 => $site_admins,
  1238 		'allowedthemes'               => $allowed_themes,
  1246 		'allowedthemes'               => $allowed_themes,
  1239 		'illegal_names'               => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ),
  1247 		'illegal_names'               => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ),
  1240 		'wpmu_upgrade_site'           => $wp_db_version,
  1248 		'wpmu_upgrade_site'           => $wp_db_version,
  1241 		'welcome_email'               => $welcome_email,
  1249 		'welcome_email'               => $welcome_email,
  1242 		/* translators: %s: site link */
  1250 		/* translators: %s: Site link. */
  1243 		'first_post'                  => __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ),
  1251 		'first_post'                  => __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ),
  1244 		// @todo - network admins should have a method of editing the network siteurl (used for cookie hash)
  1252 		// @todo - Network admins should have a method of editing the network siteurl (used for cookie hash).
  1245 		'siteurl'                     => get_option( 'siteurl' ) . '/',
  1253 		'siteurl'                     => get_option( 'siteurl' ) . '/',
  1246 		'add_new_users'               => '0',
  1254 		'add_new_users'               => '0',
  1247 		'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
  1255 		'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
  1248 		'subdomain_install'           => $subdomain_install,
  1256 		'subdomain_install'           => $subdomain_install,
  1249 		'global_terms_enabled'        => global_terms_enabled() ? '1' : '0',
  1257 		'global_terms_enabled'        => global_terms_enabled() ? '1' : '0',