wp/wp-admin/includes/schema.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    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 
    39 	$charset_collate = $wpdb->get_charset_collate();
    39 	$charset_collate = $wpdb->get_charset_collate();
    40 
    40 
    41 	if ( $blog_id && $blog_id != $wpdb->blogid ) {
    41 	if ( $blog_id && (int) $blog_id !== $wpdb->blogid ) {
    42 		$old_blog_id = $wpdb->set_blog_id( $blog_id );
    42 		$old_blog_id = $wpdb->set_blog_id( $blog_id );
    43 	}
    43 	}
    44 
    44 
    45 	// Engage multisite if in the middle of turning it on from network.php.
    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 );
    46 	$is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK );
   386 	$timezone_string = '';
   386 	$timezone_string = '';
   387 	$gmt_offset      = 0;
   387 	$gmt_offset      = 0;
   388 	/*
   388 	/*
   389 	 * 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)
   390 	 * or a valid timezone string (America/New_York). See https://www.php.net/manual/en/timezones.php
   390 	 * or a valid timezone string (America/New_York). See https://www.php.net/manual/en/timezones.php
   391 	 * for all timezone strings supported by PHP.
   391 	 * for all timezone strings currently supported by PHP.
       
   392 	 *
       
   393 	 * Important: When a previous timezone string, like `Europe/Kiev`, has been superseded by an
       
   394 	 * updated one, like `Europe/Kyiv`, as a rule of thumb, the **old** timezone name should be used
       
   395 	 * in the "translation" to allow for the default timezone setting to be PHP cross-version compatible,
       
   396 	 * as old timezone names will be recognized in new PHP versions, while new timezone names cannot
       
   397 	 * be recognized in old PHP versions.
       
   398 	 *
       
   399 	 * To verify which timezone strings are available in the _oldest_ PHP version supported, you can
       
   400 	 * use https://3v4l.org/6YQAt#v5.6.20 and replace the "BR" (Brazil) in the code line with the
       
   401 	 * country code for which you want to look up the supported timezone names.
   392 	 */
   402 	 */
   393 	$offset_or_tz = _x( '0', 'default GMT offset or timezone string' );
   403 	$offset_or_tz = _x( '0', 'default GMT offset or timezone string' );
   394 	if ( is_numeric( $offset_or_tz ) ) {
   404 	if ( is_numeric( $offset_or_tz ) ) {
   395 		$gmt_offset = $offset_or_tz;
   405 		$gmt_offset = $offset_or_tz;
   396 	} elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list(), true ) ) {
   406 	} elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) ) {
   397 			$timezone_string = $offset_or_tz;
   407 		$timezone_string = $offset_or_tz;
   398 	}
   408 	}
   399 
   409 
   400 	$defaults = array(
   410 	$defaults = array(
   401 		'siteurl'                         => $guessurl,
   411 		'siteurl'                         => $guessurl,
   402 		'home'                            => $guessurl,
   412 		'home'                            => $guessurl,
   403 		'blogname'                        => __( 'My Site' ),
   413 		'blogname'                        => __( 'My Site' ),
   404 		/* translators: Site tagline. */
   414 		'blogdescription'                 => '',
   405 		'blogdescription'                 => __( 'Just another WordPress site' ),
       
   406 		'users_can_register'              => 0,
   415 		'users_can_register'              => 0,
   407 		'admin_email'                     => 'you@example.com',
   416 		'admin_email'                     => 'you@example.com',
   408 		/* translators: Default start of the week. 0 = Sunday, 1 = Monday. */
   417 		/* translators: Default start of the week. 0 = Sunday, 1 = Monday. */
   409 		'start_of_week'                   => _x( '1', 'start of week' ),
   418 		'start_of_week'                   => _x( '1', 'start of week' ),
   410 		'use_balanceTags'                 => 0,
   419 		'use_balanceTags'                 => 0,
   537 		'auto_plugin_theme_update_emails' => array(),
   546 		'auto_plugin_theme_update_emails' => array(),
   538 
   547 
   539 		// 5.6.0
   548 		// 5.6.0
   540 		'auto_update_core_dev'            => 'enabled',
   549 		'auto_update_core_dev'            => 'enabled',
   541 		'auto_update_core_minor'          => 'enabled',
   550 		'auto_update_core_minor'          => 'enabled',
   542 		// Default to enabled for new installs.
   551 		/*
   543 		// See https://core.trac.wordpress.org/ticket/51742.
   552 		 * Default to enabled for new installs.
       
   553 		 * See https://core.trac.wordpress.org/ticket/51742.
       
   554 		 */
   544 		'auto_update_core_major'          => 'enabled',
   555 		'auto_update_core_major'          => 'enabled',
   545 
   556 
   546 		// 5.8.0
   557 		// 5.8.0
   547 		'wp_force_deactivated_plugins'    => array(),
   558 		'wp_force_deactivated_plugins'    => array(),
       
   559 
       
   560 		// 6.4.0
       
   561 		'wp_attachment_pages_enabled'     => 0,
   548 	);
   562 	);
   549 
   563 
   550 	// 3.3.0
   564 	// 3.3.0
   551 	if ( ! is_multisite() ) {
   565 	if ( ! is_multisite() ) {
   552 		$defaults['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version
   566 		$defaults['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version
   553 			? $wp_current_db_version : $wp_db_version;
   567 			? $wp_current_db_version : $wp_db_version;
   554 	}
   568 	}
   555 
   569 
   556 	// 3.0.0 multisite.
   570 	// 3.0.0 multisite.
   557 	if ( is_multisite() ) {
   571 	if ( is_multisite() ) {
   558 		/* translators: %s: Network title. */
       
   559 		$defaults['blogdescription']     = sprintf( __( 'Just another %s site' ), get_network()->site_name );
       
   560 		$defaults['permalink_structure'] = '/%year%/%monthnum%/%day%/%postname%/';
   572 		$defaults['permalink_structure'] = '/%year%/%monthnum%/%day%/%postname%/';
   561 	}
   573 	}
   562 
   574 
   563 	$options = wp_parse_args( $options, $defaults );
   575 	$options = wp_parse_args( $options, $defaults );
   564 
   576 
   580 		if ( in_array( $option, $existing_options, true ) ) {
   592 		if ( in_array( $option, $existing_options, true ) ) {
   581 			continue;
   593 			continue;
   582 		}
   594 		}
   583 
   595 
   584 		if ( in_array( $option, $fat_options, true ) ) {
   596 		if ( in_array( $option, $fat_options, true ) ) {
   585 			$autoload = 'no';
   597 			$autoload = 'off';
   586 		} else {
   598 		} else {
   587 			$autoload = 'yes';
   599 			$autoload = 'on';
   588 		}
       
   589 
       
   590 		if ( is_array( $value ) ) {
       
   591 			$value = serialize( $value );
       
   592 		}
   600 		}
   593 
   601 
   594 		if ( ! empty( $insert ) ) {
   602 		if ( ! empty( $insert ) ) {
   595 			$insert .= ', ';
   603 			$insert .= ', ';
   596 		}
   604 		}
       
   605 
       
   606 		$value = maybe_serialize( sanitize_option( $option, $value ) );
   597 
   607 
   598 		$insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload );
   608 		$insert .= $wpdb->prepare( '(%s, %s, %s)', $option, $value, $autoload );
   599 	}
   609 	}
   600 
   610 
   601 	if ( ! empty( $insert ) ) {
   611 	if ( ! empty( $insert ) ) {
   968  * @param string $email             Email address for the network administrator.
   978  * @param string $email             Email address for the network administrator.
   969  * @param string $site_name         The name of the network.
   979  * @param string $site_name         The name of the network.
   970  * @param string $path              Optional. The path to append to the network's domain name. Default '/'.
   980  * @param string $path              Optional. The path to append to the network's domain name. Default '/'.
   971  * @param bool   $subdomain_install Optional. Whether the network is a subdomain installation or a subdirectory installation.
   981  * @param bool   $subdomain_install Optional. Whether the network is a subdomain installation or a subdirectory installation.
   972  *                                  Default false, meaning the network is a subdirectory installation.
   982  *                                  Default false, meaning the network is a subdirectory installation.
   973  * @return bool|WP_Error True on success, or WP_Error on warning (with the installation otherwise successful,
   983  * @return true|WP_Error True on success, or WP_Error on warning (with the installation otherwise successful,
   974  *                       so the error code must be checked) or failure.
   984  *                       so the error code must be checked) or failure.
   975  */
   985  */
   976 function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
   986 function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
   977 	global $wpdb, $current_site, $wp_rewrite;
   987 	global $wpdb, $current_site, $wp_rewrite;
       
   988 
       
   989 	$network_id = (int) $network_id;
   978 
   990 
   979 	$errors = new WP_Error();
   991 	$errors = new WP_Error();
   980 	if ( '' === $domain ) {
   992 	if ( '' === $domain ) {
   981 		$errors->add( 'empty_domain', __( 'You must provide a domain name.' ) );
   993 		$errors->add( 'empty_domain', __( 'You must provide a domain name.' ) );
   982 	}
   994 	}
   985 	}
   997 	}
   986 
   998 
   987 	// Check for network collision.
   999 	// Check for network collision.
   988 	$network_exists = false;
  1000 	$network_exists = false;
   989 	if ( is_multisite() ) {
  1001 	if ( is_multisite() ) {
   990 		if ( get_network( (int) $network_id ) ) {
  1002 		if ( get_network( $network_id ) ) {
   991 			$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
  1003 			$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
   992 		}
  1004 		}
   993 	} else {
  1005 	} else {
   994 		if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) {
  1006 		if ( $network_id === (int) $wpdb->get_var(
       
  1007 			$wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id )
       
  1008 		) ) {
   995 			$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
  1009 			$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
   996 		}
  1010 		}
   997 	}
  1011 	}
   998 
  1012 
   999 	if ( ! is_email( $email ) ) {
  1013 	if ( ! is_email( $email ) ) {
  1002 
  1016 
  1003 	if ( $errors->has_errors() ) {
  1017 	if ( $errors->has_errors() ) {
  1004 		return $errors;
  1018 		return $errors;
  1005 	}
  1019 	}
  1006 
  1020 
  1007 	if ( 1 == $network_id ) {
  1021 	if ( 1 === $network_id ) {
  1008 		$wpdb->insert(
  1022 		$wpdb->insert(
  1009 			$wpdb->site,
  1023 			$wpdb->site,
  1010 			array(
  1024 			array(
  1011 				'domain' => $domain,
  1025 				'domain' => $domain,
  1012 				'path'   => $path,
  1026 				'path'   => $path,
  1031 			'site_name'         => $site_name,
  1045 			'site_name'         => $site_name,
  1032 			'subdomain_install' => $subdomain_install,
  1046 			'subdomain_install' => $subdomain_install,
  1033 		)
  1047 		)
  1034 	);
  1048 	);
  1035 
  1049 
  1036 	$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 ) ) );
       
  1037 
       
  1038 	/*
  1050 	/*
  1039 	 * When upgrading from single to multisite, assume the current site will
  1051 	 * When upgrading from single to multisite, assume the current site will
  1040 	 * become the main site of the network. When using populate_network()
  1052 	 * become the main site of the network. When using populate_network()
  1041 	 * to create another network in an existing multisite environment, skip
  1053 	 * to create another network in an existing multisite environment, skip
  1042 	 * these steps since the main site of the new network has not yet been
  1054 	 * these steps since the main site of the new network has not yet been
  1043 	 * created.
  1055 	 * created.
  1044 	 */
  1056 	 */
  1045 	if ( ! is_multisite() ) {
  1057 	if ( ! is_multisite() ) {
  1046 		$current_site            = new stdClass;
  1058 		$current_site            = new stdClass();
  1047 		$current_site->domain    = $domain;
  1059 		$current_site->domain    = $domain;
  1048 		$current_site->path      = $path;
  1060 		$current_site->path      = $path;
  1049 		$current_site->site_name = ucfirst( $domain );
  1061 		$current_site->site_name = ucfirst( $domain );
  1050 		$wpdb->insert(
  1062 		$wpdb->insert(
  1051 			$wpdb->blogs,
  1063 			$wpdb->blogs,
  1056 				'path'       => $path,
  1068 				'path'       => $path,
  1057 				'registered' => current_time( 'mysql' ),
  1069 				'registered' => current_time( 'mysql' ),
  1058 			)
  1070 			)
  1059 		);
  1071 		);
  1060 		$current_site->blog_id = $wpdb->insert_id;
  1072 		$current_site->blog_id = $wpdb->insert_id;
  1061 		update_user_meta( $site_user->ID, 'source_domain', $domain );
  1073 
  1062 		update_user_meta( $site_user->ID, 'primary_blog', $current_site->blog_id );
  1074 		$site_user_id = (int) $wpdb->get_var(
       
  1075 			$wpdb->prepare(
       
  1076 				"SELECT meta_value
       
  1077 				FROM $wpdb->sitemeta
       
  1078 				WHERE meta_key = %s AND site_id = %d",
       
  1079 				'admin_user_id',
       
  1080 				$network_id
       
  1081 			)
       
  1082 		);
       
  1083 
       
  1084 		update_user_meta( $site_user_id, 'source_domain', $domain );
       
  1085 		update_user_meta( $site_user_id, 'primary_blog', $current_site->blog_id );
       
  1086 
       
  1087 		// Unable to use update_network_option() while populating the network.
       
  1088 		$wpdb->insert(
       
  1089 			$wpdb->sitemeta,
       
  1090 			array(
       
  1091 				'site_id'    => $network_id,
       
  1092 				'meta_key'   => 'main_site',
       
  1093 				'meta_value' => $current_site->blog_id,
       
  1094 			)
       
  1095 		);
  1063 
  1096 
  1064 		if ( $subdomain_install ) {
  1097 		if ( $subdomain_install ) {
  1065 			$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
  1098 			$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
  1066 		} else {
  1099 		} else {
  1067 			$wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' );
  1100 			$wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' );
  1083 				'httpversion' => '1.1',
  1116 				'httpversion' => '1.1',
  1084 			)
  1117 			)
  1085 		);
  1118 		);
  1086 		if ( is_wp_error( $page ) ) {
  1119 		if ( is_wp_error( $page ) ) {
  1087 			$errstr = $page->get_error_message();
  1120 			$errstr = $page->get_error_message();
  1088 		} elseif ( 200 == wp_remote_retrieve_response_code( $page ) ) {
  1121 		} elseif ( 200 === wp_remote_retrieve_response_code( $page ) ) {
  1089 				$vhost_ok = true;
  1122 				$vhost_ok = true;
  1090 		}
  1123 		}
  1091 
  1124 
  1092 		if ( ! $vhost_ok ) {
  1125 		if ( ! $vhost_ok ) {
  1093 			$msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
  1126 			$msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
  1149 
  1182 
  1150 	$template       = get_option( 'template' );
  1183 	$template       = get_option( 'template' );
  1151 	$stylesheet     = get_option( 'stylesheet' );
  1184 	$stylesheet     = get_option( 'stylesheet' );
  1152 	$allowed_themes = array( $stylesheet => true );
  1185 	$allowed_themes = array( $stylesheet => true );
  1153 
  1186 
  1154 	if ( $template != $stylesheet ) {
  1187 	if ( $template !== $stylesheet ) {
  1155 		$allowed_themes[ $template ] = true;
  1188 		$allowed_themes[ $template ] = true;
  1156 	}
  1189 	}
  1157 
  1190 
  1158 	if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) {
  1191 	if ( WP_DEFAULT_THEME !== $stylesheet && WP_DEFAULT_THEME !== $template ) {
  1159 		$allowed_themes[ WP_DEFAULT_THEME ] = true;
  1192 		$allowed_themes[ WP_DEFAULT_THEME ] = true;
  1160 	}
  1193 	}
  1161 
  1194 
  1162 	// If WP_DEFAULT_THEME doesn't exist, also include the latest core default theme.
  1195 	// If WP_DEFAULT_THEME doesn't exist, also include the latest core default theme.
  1163 	if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) {
  1196 	if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) {
  1208 We hope you enjoy your new site. Thanks!
  1241 We hope you enjoy your new site. Thanks!
  1209 
  1242 
  1210 --The Team @ SITE_NAME'
  1243 --The Team @ SITE_NAME'
  1211 	);
  1244 	);
  1212 
  1245 
  1213 	$misc_exts        = array(
  1246 	$allowed_file_types = array();
  1214 		// Images.
  1247 	$all_mime_types     = get_allowed_mime_types();
  1215 		'jpg',
  1248 
  1216 		'jpeg',
  1249 	foreach ( $all_mime_types as $ext => $mime ) {
  1217 		'png',
  1250 		array_push( $allowed_file_types, ...explode( '|', $ext ) );
  1218 		'gif',
  1251 	}
  1219 		'webp',
  1252 	$upload_filetypes = array_unique( $allowed_file_types );
  1220 		// Video.
       
  1221 		'mov',
       
  1222 		'avi',
       
  1223 		'mpg',
       
  1224 		'3gp',
       
  1225 		'3g2',
       
  1226 		// "audio".
       
  1227 		'midi',
       
  1228 		'mid',
       
  1229 		// Miscellaneous.
       
  1230 		'pdf',
       
  1231 		'doc',
       
  1232 		'ppt',
       
  1233 		'odt',
       
  1234 		'pptx',
       
  1235 		'docx',
       
  1236 		'pps',
       
  1237 		'ppsx',
       
  1238 		'xls',
       
  1239 		'xlsx',
       
  1240 		'key',
       
  1241 	);
       
  1242 	$audio_exts       = wp_get_audio_extensions();
       
  1243 	$video_exts       = wp_get_video_extensions();
       
  1244 	$upload_filetypes = array_unique( array_merge( $misc_exts, $audio_exts, $video_exts ) );
       
  1245 
  1253 
  1246 	$sitemeta = array(
  1254 	$sitemeta = array(
  1247 		'site_name'                   => __( 'My Network' ),
  1255 		'site_name'                   => __( 'My Network' ),
  1248 		'admin_email'                 => $email,
  1256 		'admin_email'                 => $email,
  1249 		'admin_user_id'               => $site_user->ID,
  1257 		'admin_user_id'               => $site_user->ID,
  1261 		// @todo - Network admins should have a method of editing the network siteurl (used for cookie hash).
  1269 		// @todo - Network admins should have a method of editing the network siteurl (used for cookie hash).
  1262 		'siteurl'                     => get_option( 'siteurl' ) . '/',
  1270 		'siteurl'                     => get_option( 'siteurl' ) . '/',
  1263 		'add_new_users'               => '0',
  1271 		'add_new_users'               => '0',
  1264 		'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
  1272 		'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
  1265 		'subdomain_install'           => $subdomain_install,
  1273 		'subdomain_install'           => $subdomain_install,
  1266 		'global_terms_enabled'        => global_terms_enabled() ? '1' : '0',
       
  1267 		'ms_files_rewriting'          => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
  1274 		'ms_files_rewriting'          => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
  1268 		'user_count'                  => get_site_option( 'user_count' ),
  1275 		'user_count'                  => get_site_option( 'user_count' ),
  1269 		'initial_db_version'          => get_option( 'initial_db_version' ),
  1276 		'initial_db_version'          => get_option( 'initial_db_version' ),
  1270 		'active_sitewide_plugins'     => array(),
  1277 		'active_sitewide_plugins'     => array(),
  1271 		'WPLANG'                      => get_locale(),
  1278 		'WPLANG'                      => get_locale(),