wp/wp-admin/includes/upgrade.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    42 	 *     @type int    $user_id          The ID of the site owner.
    42 	 *     @type int    $user_id          The ID of the site owner.
    43 	 *     @type string $password         The password of the site owner, if their user account didn't already exist.
    43 	 *     @type string $password         The password of the site owner, if their user account didn't already exist.
    44 	 *     @type string $password_message The explanatory message regarding the password.
    44 	 *     @type string $password_message The explanatory message regarding the password.
    45 	 * }
    45 	 * }
    46 	 */
    46 	 */
    47 	function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
    47 	function wp_install(
       
    48 		$blog_title,
       
    49 		$user_name,
       
    50 		$user_email,
       
    51 		$is_public,
       
    52 		$deprecated = '',
       
    53 		#[\SensitiveParameter]
       
    54 		$user_password = '',
       
    55 		$language = ''
       
    56 	) {
    48 		if ( ! empty( $deprecated ) ) {
    57 		if ( ! empty( $deprecated ) ) {
    49 			_deprecated_argument( __FUNCTION__, '2.6.0' );
    58 			_deprecated_argument( __FUNCTION__, '2.6.0' );
    50 		}
    59 		}
    51 
    60 
    52 		wp_check_mysql_version();
    61 		wp_check_mysql_version();
    73 		update_option( 'blogname', $blog_title );
    82 		update_option( 'blogname', $blog_title );
    74 		update_option( 'admin_email', $user_email );
    83 		update_option( 'admin_email', $user_email );
    75 		update_option( 'blog_public', $is_public );
    84 		update_option( 'blog_public', $is_public );
    76 
    85 
    77 		// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
    86 		// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
    78 		update_option( 'fresh_site', 1 );
    87 		update_option( 'fresh_site', 1, false );
    79 
    88 
    80 		if ( $language ) {
    89 		if ( $language ) {
    81 			update_option( 'WPLANG', $language );
    90 			update_option( 'WPLANG', $language );
    82 		}
    91 		}
    83 
    92 
   276 			__(
   285 			__(
   277 				'Hi, this is a comment.
   286 				'Hi, this is a comment.
   278 To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
   287 To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
   279 Commenter avatars come from <a href="%s">Gravatar</a>.'
   288 Commenter avatars come from <a href="%s">Gravatar</a>.'
   280 			),
   289 			),
   281 			esc_url( __( 'https://en.gravatar.com/' ) )
   290 			/* translators: The localized Gravatar URL. */
       
   291 			esc_url( __( 'https://gravatar.com/' ) )
   282 		);
   292 		);
   283 		$wpdb->insert(
   293 		$wpdb->insert(
   284 			$wpdb->comments,
   294 			$wpdb->comments,
   285 			array(
   295 			array(
   286 				'comment_post_ID'      => 1,
   296 				'comment_post_ID'      => 1,
   457 
   467 
   458 			/*
   468 			/*
   459 			 * Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.)
   469 			 * Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.)
   460 			 * TODO: Get previous_blog_id.
   470 			 * TODO: Get previous_blog_id.
   461 			 */
   471 			 */
   462 			if ( ! is_super_admin( $user_id ) && 1 != $user_id ) {
   472 			if ( ! is_super_admin( $user_id ) && 1 !== $user_id ) {
   463 				$wpdb->delete(
   473 				$wpdb->delete(
   464 					$wpdb->usermeta,
   474 					$wpdb->usermeta,
   465 					array(
   475 					array(
   466 						'user_id'  => $user_id,
   476 						'user_id'  => $user_id,
   467 						'meta_key' => $wpdb->base_prefix . '1_capabilities',
   477 						'meta_key' => $wpdb->base_prefix . '1_capabilities',
   560 	 * @param string $blog_url   Site URL.
   570 	 * @param string $blog_url   Site URL.
   561 	 * @param int    $user_id    Administrator's user ID.
   571 	 * @param int    $user_id    Administrator's user ID.
   562 	 * @param string $password   Administrator's password. Note that a placeholder message is
   572 	 * @param string $password   Administrator's password. Note that a placeholder message is
   563 	 *                           usually passed instead of the actual password.
   573 	 *                           usually passed instead of the actual password.
   564 	 */
   574 	 */
   565 	function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
   575 	function wp_new_blog_notification(
       
   576 		$blog_title,
       
   577 		$blog_url,
       
   578 		$user_id,
       
   579 		#[\SensitiveParameter]
       
   580 		$password
       
   581 	) {
   566 		$user      = new WP_User( $user_id );
   582 		$user      = new WP_User( $user_id );
   567 		$email     = $user->user_email;
   583 		$email     = $user->user_email;
   568 		$name      = $user->user_login;
   584 		$name      = $user->user_login;
   569 		$login_url = wp_login_url();
   585 		$login_url = wp_login_url();
   570 
   586 
   636 	 *
   652 	 *
   637 	 * Upgrades the database if needed during a site update.
   653 	 * Upgrades the database if needed during a site update.
   638 	 *
   654 	 *
   639 	 * @since 2.1.0
   655 	 * @since 2.1.0
   640 	 *
   656 	 *
   641 	 * @global int  $wp_current_db_version The old (current) database version.
   657 	 * @global int $wp_current_db_version The old (current) database version.
   642 	 * @global int  $wp_db_version         The new database version.
   658 	 * @global int $wp_db_version         The new database version.
   643 	 */
   659 	 */
   644 	function wp_upgrade() {
   660 	function wp_upgrade() {
   645 		global $wp_current_db_version, $wp_db_version;
   661 		global $wp_current_db_version, $wp_db_version;
   646 
   662 
   647 		$wp_current_db_version = __get_option( 'db_version' );
   663 		$wp_current_db_version = (int) __get_option( 'db_version' );
   648 
   664 
   649 		// We are up to date. Nothing to do.
   665 		// We are up to date. Nothing to do.
   650 		if ( $wp_db_version == $wp_current_db_version ) {
   666 		if ( $wp_db_version === $wp_current_db_version ) {
   651 			return;
   667 			return;
   652 		}
   668 		}
   653 
   669 
   654 		if ( ! is_blog_installed() ) {
   670 		if ( ! is_blog_installed() ) {
   655 			return;
   671 			return;
   697  * @global int $wp_db_version         The new database version.
   713  * @global int $wp_db_version         The new database version.
   698  */
   714  */
   699 function upgrade_all() {
   715 function upgrade_all() {
   700 	global $wp_current_db_version, $wp_db_version;
   716 	global $wp_current_db_version, $wp_db_version;
   701 
   717 
   702 	$wp_current_db_version = __get_option( 'db_version' );
   718 	$wp_current_db_version = (int) __get_option( 'db_version' );
   703 
   719 
   704 	// We are up to date. Nothing to do.
   720 	// We are up to date. Nothing to do.
   705 	if ( $wp_db_version == $wp_current_db_version ) {
   721 	if ( $wp_db_version === $wp_current_db_version ) {
   706 		return;
   722 		return;
   707 	}
   723 	}
   708 
   724 
   709 	// If the version is not set in the DB, try to guess the version.
   725 	// If the version is not set in the DB, try to guess the version.
   710 	if ( empty( $wp_current_db_version ) ) {
   726 	if ( empty( $wp_current_db_version ) ) {
   858 		upgrade_640();
   874 		upgrade_640();
   859 	}
   875 	}
   860 
   876 
   861 	if ( $wp_current_db_version < 57155 ) {
   877 	if ( $wp_current_db_version < 57155 ) {
   862 		upgrade_650();
   878 		upgrade_650();
       
   879 	}
       
   880 
       
   881 	if ( $wp_current_db_version < 58975 ) {
       
   882 		upgrade_670();
       
   883 	}
       
   884 
       
   885 	if ( $wp_current_db_version < 60421 ) {
       
   886 		upgrade_682();
   863 	}
   887 	}
   864 
   888 
   865 	maybe_disable_link_manager();
   889 	maybe_disable_link_manager();
   866 
   890 
   867 	maybe_disable_automattic_widgets();
   891 	maybe_disable_automattic_widgets();
   920 	$allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
   944 	$allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
   921 	if ( $allposts ) :
   945 	if ( $allposts ) :
   922 		foreach ( $allposts as $post ) {
   946 		foreach ( $allposts as $post ) {
   923 			// Check to see if it's already been imported.
   947 			// Check to see if it's already been imported.
   924 			$cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
   948 			$cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
   925 			if ( ! $cat && 0 != $post->post_category ) { // If there's no result.
   949 			if ( ! $cat && 0 !== (int) $post->post_category ) { // If there's no result.
   926 				$wpdb->insert(
   950 				$wpdb->insert(
   927 					$wpdb->post2cat,
   951 					$wpdb->post2cat,
   928 					array(
   952 					array(
   929 						'post_id'     => $post->ID,
   953 						'post_id'     => $post->ID,
   930 						'category_id' => $post->post_category,
   954 						'category_id' => $post->post_category,
   959 /**
   983 /**
   960  * Execute changes made in WordPress 1.2.
   984  * Execute changes made in WordPress 1.2.
   961  *
   985  *
   962  * @ignore
   986  * @ignore
   963  * @since 1.2.0
   987  * @since 1.2.0
       
   988  * @since 6.8.0 User passwords are no longer hashed with md5.
   964  *
   989  *
   965  * @global wpdb $wpdb WordPress database abstraction object.
   990  * @global wpdb $wpdb WordPress database abstraction object.
   966  */
   991  */
   967 function upgrade_110() {
   992 function upgrade_110() {
   968 	global $wpdb;
   993 	global $wpdb;
   974 			$newname = sanitize_title( $user->user_nickname );
   999 			$newname = sanitize_title( $user->user_nickname );
   975 			$wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
  1000 			$wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
   976 		}
  1001 		}
   977 	}
  1002 	}
   978 
  1003 
   979 	$users = $wpdb->get_results( "SELECT ID, user_pass from $wpdb->users" );
       
   980 	foreach ( $users as $row ) {
       
   981 		if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) {
       
   982 			$wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) );
       
   983 		}
       
   984 	}
       
   985 
       
   986 	// Get the GMT offset, we'll use that later on.
  1004 	// Get the GMT offset, we'll use that later on.
   987 	$all_options = get_alloptions_110();
  1005 	$all_options = get_alloptions_110();
   988 
  1006 
   989 	$time_difference = $all_options->time_difference;
  1007 	$time_difference = $all_options->time_difference;
   990 
  1008 
   991 		$server_time = time() + gmdate( 'Z' );
  1009 	$server_time    = time() + (int) gmdate( 'Z' );
   992 	$weblogger_time  = $server_time + $time_difference * HOUR_IN_SECONDS;
  1010 	$weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS;
   993 	$gmt_time        = time();
  1011 	$gmt_time       = time();
   994 
  1012 
   995 	$diff_gmt_server       = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
  1013 	$diff_gmt_server       = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
   996 	$diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
  1014 	$diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
   997 	$diff_gmt_weblogger    = $diff_gmt_server - $diff_weblogger_server;
  1015 	$diff_gmt_weblogger    = $diff_gmt_server - $diff_weblogger_server;
   998 	$gmt_offset            = -$diff_gmt_weblogger;
  1016 	$gmt_offset            = -$diff_gmt_weblogger;
  1093 	$wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
  1111 	$wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
  1094 
  1112 
  1095 	// Some versions have multiple duplicate option_name rows with the same values.
  1113 	// Some versions have multiple duplicate option_name rows with the same values.
  1096 	$options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
  1114 	$options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
  1097 	foreach ( $options as $option ) {
  1115 	foreach ( $options as $option ) {
  1098 		if ( 1 != $option->dupes ) { // Could this be done in the query?
  1116 		if ( $option->dupes > 1 ) { // Could this be done in the query?
  1099 			$limit    = $option->dupes - 1;
  1117 			$limit    = $option->dupes - 1;
  1100 			$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
  1118 			$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
  1101 			if ( $dupe_ids ) {
  1119 			if ( $dupe_ids ) {
  1102 				$dupe_ids = implode( ',', $dupe_ids );
  1120 				$dupe_ids = implode( ',', $dupe_ids );
  1103 				$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
  1121 				$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
  1443 
  1461 
  1444 		// Associate links to categories.
  1462 		// Associate links to categories.
  1445 		$links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
  1463 		$links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
  1446 		if ( ! empty( $links ) ) {
  1464 		if ( ! empty( $links ) ) {
  1447 			foreach ( $links as $link ) {
  1465 			foreach ( $links as $link ) {
  1448 				if ( 0 == $link->link_category ) {
  1466 				if ( 0 === (int) $link->link_category ) {
  1449 					continue;
  1467 					continue;
  1450 				}
  1468 				}
  1451 				if ( ! isset( $link_cat_id_map[ $link->link_category ] ) ) {
  1469 				if ( ! isset( $link_cat_id_map[ $link->link_category ] ) ) {
  1452 					continue;
  1470 					continue;
  1453 				}
  1471 				}
  1668 	if ( $wp_current_db_version < 11958 ) {
  1686 	if ( $wp_current_db_version < 11958 ) {
  1669 		/*
  1687 		/*
  1670 		 * Previously, setting depth to 1 would redundantly disable threading,
  1688 		 * Previously, setting depth to 1 would redundantly disable threading,
  1671 		 * but now 2 is the minimum depth to avoid confusion.
  1689 		 * but now 2 is the minimum depth to avoid confusion.
  1672 		 */
  1690 		 */
  1673 		if ( get_option( 'thread_comments_depth' ) == '1' ) {
  1691 		if ( 1 === (int) get_option( 'thread_comments_depth' ) ) {
  1674 			update_option( 'thread_comments_depth', 2 );
  1692 			update_option( 'thread_comments_depth', 2 );
  1675 			update_option( 'thread_comments', 0 );
  1693 			update_option( 'thread_comments', 0 );
  1676 		}
  1694 		}
  1677 	}
  1695 	}
  1678 }
  1696 }
  1841 
  1859 
  1842 	if ( $wp_current_db_version < 20080 ) {
  1860 	if ( $wp_current_db_version < 20080 ) {
  1843 		if ( 'yes' === $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
  1861 		if ( 'yes' === $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
  1844 			$uninstall_plugins = get_option( 'uninstall_plugins' );
  1862 			$uninstall_plugins = get_option( 'uninstall_plugins' );
  1845 			delete_option( 'uninstall_plugins' );
  1863 			delete_option( 'uninstall_plugins' );
  1846 			add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' );
  1864 			add_option( 'uninstall_plugins', $uninstall_plugins, null, false );
  1847 		}
  1865 		}
  1848 	}
  1866 	}
  1849 }
  1867 }
  1850 
  1868 
  1851 /**
  1869 /**
  2337 		if ( ! is_multisite() ) {
  2355 		if ( ! is_multisite() ) {
  2338 			// Replace non-autoload option can_compress_scripts with autoload option, see #55270
  2356 			// Replace non-autoload option can_compress_scripts with autoload option, see #55270
  2339 			$can_compress_scripts = get_option( 'can_compress_scripts', false );
  2357 			$can_compress_scripts = get_option( 'can_compress_scripts', false );
  2340 			if ( false !== $can_compress_scripts ) {
  2358 			if ( false !== $can_compress_scripts ) {
  2341 				delete_option( 'can_compress_scripts' );
  2359 				delete_option( 'can_compress_scripts' );
  2342 				add_option( 'can_compress_scripts', $can_compress_scripts, '', 'yes' );
  2360 				add_option( 'can_compress_scripts', $can_compress_scripts, '', true );
  2343 			}
  2361 			}
  2344 		}
  2362 		}
  2345 	}
  2363 	}
  2346 }
  2364 }
  2347 
  2365 
  2390 				"theme_mods_$stylesheet",
  2408 				"theme_mods_$stylesheet",
  2391 				$wpdb->esc_like( 'theme_mods_' ) . '%'
  2409 				$wpdb->esc_like( 'theme_mods_' ) . '%'
  2392 			)
  2410 			)
  2393 		);
  2411 		);
  2394 
  2412 
  2395 		$autoload = array_fill_keys( $theme_mods_options, 'no' );
  2413 		$autoload = array_fill_keys( $theme_mods_options, false );
  2396 		wp_set_option_autoload_values( $autoload );
  2414 		wp_set_option_autoload_values( $autoload );
       
  2415 	}
       
  2416 }
       
  2417 /**
       
  2418  * Executes changes made in WordPress 6.7.0.
       
  2419  *
       
  2420  * @ignore
       
  2421  * @since 6.7.0
       
  2422  *
       
  2423  * @global int  $wp_current_db_version The old (current) database version.
       
  2424  */
       
  2425 function upgrade_670() {
       
  2426 	global $wp_current_db_version;
       
  2427 
       
  2428 	if ( $wp_current_db_version < 58975 ) {
       
  2429 		$options = array(
       
  2430 			'recently_activated',
       
  2431 			'_wp_suggested_policy_text_has_changed',
       
  2432 			'dashboard_widget_options',
       
  2433 			'ftp_credentials',
       
  2434 			'adminhash',
       
  2435 			'nav_menu_options',
       
  2436 			'wp_force_deactivated_plugins',
       
  2437 			'delete_blog_hash',
       
  2438 			'allowedthemes',
       
  2439 			'recovery_keys',
       
  2440 			'https_detection_errors',
       
  2441 			'fresh_site',
       
  2442 		);
       
  2443 
       
  2444 		wp_set_options_autoload( $options, false );
       
  2445 	}
       
  2446 }
       
  2447 
       
  2448 /**
       
  2449  * Executes changes made in WordPress 6.8.2.
       
  2450  *
       
  2451  * @ignore
       
  2452  * @since 6.8.2
       
  2453  *
       
  2454  * @global int $wp_current_db_version The old (current) database version.
       
  2455  */
       
  2456 function upgrade_682() {
       
  2457 	global $wp_current_db_version;
       
  2458 
       
  2459 	if ( $wp_current_db_version < 60421 ) {
       
  2460 		// Upgrade Ping-O-Matic and Twingly to use HTTPS.
       
  2461 		$ping_sites_value = get_option( 'ping_sites' );
       
  2462 		$ping_sites_value = explode( "\n", $ping_sites_value );
       
  2463 		$ping_sites_value = array_map(
       
  2464 			function ( $url ) {
       
  2465 				$url = trim( $url );
       
  2466 				$url = sanitize_url( $url );
       
  2467 				if (
       
  2468 					str_ends_with( trailingslashit( $url ), '://rpc.pingomatic.com/' )
       
  2469 					|| str_ends_with( trailingslashit( $url ), '://rpc.twingly.com/' )
       
  2470 				) {
       
  2471 					$url = set_url_scheme( $url, 'https' );
       
  2472 				}
       
  2473 				return $url;
       
  2474 			},
       
  2475 			$ping_sites_value
       
  2476 		);
       
  2477 		$ping_sites_value = array_filter( $ping_sites_value );
       
  2478 		$ping_sites_value = implode( "\n", $ping_sites_value );
       
  2479 		update_option( 'ping_sites', $ping_sites_value );
  2397 	}
  2480 	}
  2398 }
  2481 }
  2399 
  2482 
  2400 /**
  2483 /**
  2401  * Executes network-level upgrade routines.
  2484  * Executes network-level upgrade routines.
  2516 	if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
  2599 	if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
  2517 		if ( wp_should_upgrade_global_tables() ) {
  2600 		if ( wp_should_upgrade_global_tables() ) {
  2518 			$upgrade = false;
  2601 			$upgrade = false;
  2519 			$indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" );
  2602 			$indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" );
  2520 			foreach ( $indexes as $index ) {
  2603 			foreach ( $indexes as $index ) {
  2521 				if ( 'domain_path' === $index->Key_name && 'domain' === $index->Column_name && 140 != $index->Sub_part ) {
  2604 				if ( 'domain_path' === $index->Key_name && 'domain' === $index->Column_name && '140' !== $index->Sub_part ) {
  2522 					$upgrade = true;
  2605 					$upgrade = true;
  2523 					break;
  2606 					break;
  2524 				}
  2607 				}
  2525 			}
  2608 			}
  2526 
  2609 
  2816  * @param string[]|string $queries Optional. The query to run. Can be multiple queries
  2899  * @param string[]|string $queries Optional. The query to run. Can be multiple queries
  2817  *                                 in an array, or a string of queries separated by
  2900  *                                 in an array, or a string of queries separated by
  2818  *                                 semicolons. Default empty string.
  2901  *                                 semicolons. Default empty string.
  2819  * @param bool            $execute Optional. Whether or not to execute the query right away.
  2902  * @param bool            $execute Optional. Whether or not to execute the query right away.
  2820  *                                 Default true.
  2903  *                                 Default true.
  2821  * @return array Strings containing the results of the various update queries.
  2904  * @return string[] Strings containing the results of the various update queries.
  2822  */
  2905  */
  2823 function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
  2906 function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
  2824 	global $wpdb;
  2907 	global $wpdb;
  2825 
  2908 
  2826 	if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) {
  2909 	if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) {
  3086 
  3169 
  3087 				// Get the type without attributes, e.g. `int`.
  3170 				// Get the type without attributes, e.g. `int`.
  3088 				$fieldtype_base = strtok( $fieldtype_without_parentheses, ' ' );
  3171 				$fieldtype_base = strtok( $fieldtype_without_parentheses, ' ' );
  3089 
  3172 
  3090 				// Is actual field type different from the field type in query?
  3173 				// Is actual field type different from the field type in query?
  3091 				if ( $tablefield->Type != $fieldtype ) {
  3174 				if ( $tablefield->Type !== $fieldtype ) {
  3092 					$do_change = true;
  3175 					$do_change = true;
  3093 					if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
  3176 					if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
  3094 						if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {
  3177 						if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {
  3095 							$do_change = false;
  3178 							$do_change = false;
  3096 						}
  3179 						}
  3126 				}
  3209 				}
  3127 
  3210 
  3128 				// Get the default value from the array.
  3211 				// Get the default value from the array.
  3129 				if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) {
  3212 				if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) {
  3130 					$default_value = $matches[1];
  3213 					$default_value = $matches[1];
  3131 					if ( $tablefield->Default != $default_value ) {
  3214 					if ( $tablefield->Default !== $default_value ) {
  3132 						// Add a query to change the column's default value
  3215 						// Add a query to change the column's default value
  3133 						$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
  3216 						$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
  3134 
  3217 
  3135 						$for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
  3218 						$for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
  3136 					}
  3219 					}
  3165 				// Add the index to the index data array.
  3248 				// Add the index to the index data array.
  3166 				$index_ary[ $keyname ]['columns'][]  = array(
  3249 				$index_ary[ $keyname ]['columns'][]  = array(
  3167 					'fieldname' => $tableindex->Column_name,
  3250 					'fieldname' => $tableindex->Column_name,
  3168 					'subpart'   => $tableindex->Sub_part,
  3251 					'subpart'   => $tableindex->Sub_part,
  3169 				);
  3252 				);
  3170 				$index_ary[ $keyname ]['unique']     = ( 0 == $tableindex->Non_unique ) ? true : false;
  3253 				$index_ary[ $keyname ]['unique']     = ( '0' === $tableindex->Non_unique ) ? true : false;
  3171 				$index_ary[ $keyname ]['index_type'] = $tableindex->Index_type;
  3254 				$index_ary[ $keyname ]['index_type'] = $tableindex->Index_type;
  3172 			}
  3255 			}
  3173 
  3256 
  3174 			// For each actual index in the index array.
  3257 			// For each actual index in the index array.
  3175 			foreach ( $index_ary as $index_name => $index_data ) {
  3258 			foreach ( $index_ary as $index_name => $index_data ) {
  3517 		}
  3600 		}
  3518 	}
  3601 	}
  3519 
  3602 
  3520 	// Make the new site theme active.
  3603 	// Make the new site theme active.
  3521 	$current_template = __get_option( 'template' );
  3604 	$current_template = __get_option( 'template' );
  3522 	if ( WP_DEFAULT_THEME == $current_template ) {
  3605 	if ( WP_DEFAULT_THEME === $current_template ) {
  3523 		update_option( 'template', $template );
  3606 		update_option( 'template', $template );
  3524 		update_option( 'stylesheet', $template );
  3607 		update_option( 'stylesheet', $template );
  3525 	}
  3608 	}
  3526 	return $template;
  3609 	return $template;
  3527 }
  3610 }