wp/wp-admin/includes/upgrade.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    86 
    86 
    87 		if ( ! $user_id && empty( $user_password ) ) {
    87 		if ( ! $user_id && empty( $user_password ) ) {
    88 			$user_password = wp_generate_password( 12, false );
    88 			$user_password = wp_generate_password( 12, false );
    89 			$message       = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
    89 			$message       = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
    90 			$user_id       = wp_create_user( $user_name, $user_password, $user_email );
    90 			$user_id       = wp_create_user( $user_name, $user_password, $user_email );
    91 			update_user_option( $user_id, 'default_password_nag', true, true );
    91 			update_user_meta( $user_id, 'default_password_nag', true );
    92 			$email_password = true;
    92 			$email_password = true;
    93 			$user_created   = true;
    93 			$user_created   = true;
    94 		} elseif ( ! $user_id ) {
    94 		} elseif ( ! $user_id ) {
    95 			// Password has been provided.
    95 			// Password has been provided.
    96 			$message      = '<em>' . __( 'Your chosen password.' ) . '</em>';
    96 			$message      = '<em>' . __( 'Your chosen password.' ) . '</em>';
   401 			update_option( 'wp_page_for_privacy_policy', 3 );
   401 			update_option( 'wp_page_for_privacy_policy', 3 );
   402 		}
   402 		}
   403 
   403 
   404 		// Set up default widgets for default theme.
   404 		// Set up default widgets for default theme.
   405 		update_option(
   405 		update_option(
   406 			'widget_search',
   406 			'widget_block',
   407 			array(
   407 			array(
   408 				2              => array( 'title' => '' ),
   408 				2              => array( 'content' => '<!-- wp:search /-->' ),
   409 				'_multiwidget' => 1,
   409 				3              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Posts' ) . '</h2><!-- /wp:heading --><!-- wp:latest-posts /--></div><!-- /wp:group -->' ),
   410 			)
   410 				4              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Recent Comments' ) . '</h2><!-- /wp:heading --><!-- wp:latest-comments {"displayAvatar":false,"displayDate":false,"displayExcerpt":false} /--></div><!-- /wp:group -->' ),
   411 		);
   411 				5              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Archives' ) . '</h2><!-- /wp:heading --><!-- wp:archives /--></div><!-- /wp:group -->' ),
   412 		update_option(
   412 				6              => array( 'content' => '<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>' . __( 'Categories' ) . '</h2><!-- /wp:heading --><!-- wp:categories /--></div><!-- /wp:group -->' ),
   413 			'widget_recent-posts',
       
   414 			array(
       
   415 				2              => array(
       
   416 					'title'  => '',
       
   417 					'number' => 5,
       
   418 				),
       
   419 				'_multiwidget' => 1,
       
   420 			)
       
   421 		);
       
   422 		update_option(
       
   423 			'widget_recent-comments',
       
   424 			array(
       
   425 				2              => array(
       
   426 					'title'  => '',
       
   427 					'number' => 5,
       
   428 				),
       
   429 				'_multiwidget' => 1,
       
   430 			)
       
   431 		);
       
   432 		update_option(
       
   433 			'widget_archives',
       
   434 			array(
       
   435 				2              => array(
       
   436 					'title'    => '',
       
   437 					'count'    => 0,
       
   438 					'dropdown' => 0,
       
   439 				),
       
   440 				'_multiwidget' => 1,
       
   441 			)
       
   442 		);
       
   443 		update_option(
       
   444 			'widget_categories',
       
   445 			array(
       
   446 				2              => array(
       
   447 					'title'        => '',
       
   448 					'count'        => 0,
       
   449 					'hierarchical' => 0,
       
   450 					'dropdown'     => 0,
       
   451 				),
       
   452 				'_multiwidget' => 1,
       
   453 			)
       
   454 		);
       
   455 		update_option(
       
   456 			'widget_meta',
       
   457 			array(
       
   458 				2              => array( 'title' => '' ),
       
   459 				'_multiwidget' => 1,
   413 				'_multiwidget' => 1,
   460 			)
   414 			)
   461 		);
   415 		);
   462 		update_option(
   416 		update_option(
   463 			'sidebars_widgets',
   417 			'sidebars_widgets',
   464 			array(
   418 			array(
   465 				'wp_inactive_widgets' => array(),
   419 				'wp_inactive_widgets' => array(),
   466 				'sidebar-1'           => array(
   420 				'sidebar-1'           => array(
   467 					0 => 'search-2',
   421 					0 => 'block-2',
   468 					1 => 'recent-posts-2',
   422 					1 => 'block-3',
   469 					2 => 'recent-comments-2',
   423 					2 => 'block-4',
   470 				),
   424 				),
   471 				'sidebar-2'           => array(
   425 				'sidebar-2'           => array(
   472 					0 => 'archives-2',
   426 					0 => 'block-5',
   473 					1 => 'categories-2',
   427 					1 => 'block-6',
   474 					2 => 'meta-2',
       
   475 				),
   428 				),
   476 				'array_version'       => 3,
   429 				'array_version'       => 3,
   477 			)
   430 			)
   478 		);
   431 		);
       
   432 
   479 		if ( ! is_multisite() ) {
   433 		if ( ! is_multisite() ) {
   480 			update_user_meta( $user_id, 'show_welcome_panel', 1 );
   434 			update_user_meta( $user_id, 'show_welcome_panel', 1 );
   481 		} elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) {
   435 		} elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) {
   482 			update_user_meta( $user_id, 'show_welcome_panel', 2 );
   436 			update_user_meta( $user_id, 'show_welcome_panel', 2 );
   483 		}
   437 		}
   584 	return false;
   538 	return false;
   585 }
   539 }
   586 
   540 
   587 if ( ! function_exists( 'wp_new_blog_notification' ) ) :
   541 if ( ! function_exists( 'wp_new_blog_notification' ) ) :
   588 	/**
   542 	/**
   589 	 * Notifies the site admin that the setup is complete.
   543 	 * Notifies the site admin that the installation of WordPress is complete.
   590 	 *
   544 	 *
   591 	 * Sends an email with wp_mail to the new administrator that the site setup is complete,
   545 	 * Sends an email to the new administrator that the installation is complete
   592 	 * and provides them with a record of their login credentials.
   546 	 * and provides them with a record of their login credentials.
   593 	 *
   547 	 *
   594 	 * @since 2.1.0
   548 	 * @since 2.1.0
   595 	 *
   549 	 *
   596 	 * @param string $blog_title Site title.
   550 	 * @param string $blog_title Site title.
   597 	 * @param string $blog_url   Site url.
   551 	 * @param string $blog_url   Site URL.
   598 	 * @param int    $user_id    User ID.
   552 	 * @param int    $user_id    Administrator's user ID.
   599 	 * @param string $password   User's Password.
   553 	 * @param string $password   Administrator's password. Note that a placeholder message is
       
   554 	 *                           usually passed instead of the actual password.
   600 	 */
   555 	 */
   601 	function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
   556 	function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
   602 		$user      = new WP_User( $user_id );
   557 		$user      = new WP_User( $user_id );
   603 		$email     = $user->user_email;
   558 		$email     = $user->user_email;
   604 		$name      = $user->user_login;
   559 		$name      = $user->user_login;
   627 			$name,
   582 			$name,
   628 			$password,
   583 			$password,
   629 			$login_url
   584 			$login_url
   630 		);
   585 		);
   631 
   586 
   632 		wp_mail( $email, __( 'New WordPress Site' ), $message );
   587 		$installed_email = array(
       
   588 			'to'      => $email,
       
   589 			'subject' => __( 'New WordPress Site' ),
       
   590 			'message' => $message,
       
   591 			'headers' => '',
       
   592 		);
       
   593 
       
   594 		/**
       
   595 		 * Filters the contents of the email sent to the site administrator when WordPress is installed.
       
   596 		 *
       
   597 		 * @since 5.6.0
       
   598 		 *
       
   599 		 * @param array $installed_email {
       
   600 		 *     Used to build wp_mail().
       
   601 		 *
       
   602 		 *     @type string $to      The email address of the recipient.
       
   603 		 *     @type string $subject The subject of the email.
       
   604 		 *     @type string $message The content of the email.
       
   605 		 *     @type string $headers Headers.
       
   606 		 * }
       
   607 		 * @param WP_User $user          The site administrator user object.
       
   608 		 * @param string  $blog_title    The site title.
       
   609 		 * @param string  $blog_url      The site URL.
       
   610 		 * @param string  $password      The site administrator's password. Note that a placeholder message
       
   611 		 *                               is usually passed instead of the user's actual password.
       
   612 		 */
       
   613 		$installed_email = apply_filters( 'wp_installed_email', $installed_email, $user, $blog_title, $blog_url, $password );
       
   614 
       
   615 		wp_mail(
       
   616 			$installed_email['to'],
       
   617 			$installed_email['subject'],
       
   618 			$installed_email['message'],
       
   619 			$installed_email['headers']
       
   620 		);
   633 	}
   621 	}
   634 endif;
   622 endif;
   635 
   623 
   636 if ( ! function_exists( 'wp_upgrade' ) ) :
   624 if ( ! function_exists( 'wp_upgrade' ) ) :
   637 	/**
   625 	/**
   838 
   826 
   839 	if ( $wp_current_db_version < 48575 ) {
   827 	if ( $wp_current_db_version < 48575 ) {
   840 		upgrade_550();
   828 		upgrade_550();
   841 	}
   829 	}
   842 
   830 
       
   831 	if ( $wp_current_db_version < 49752 ) {
       
   832 		upgrade_560();
       
   833 	}
       
   834 
   843 	maybe_disable_link_manager();
   835 	maybe_disable_link_manager();
   844 
   836 
   845 	maybe_disable_automattic_widgets();
   837 	maybe_disable_automattic_widgets();
   846 
   838 
   847 	update_option( 'db_version', $wp_db_version );
   839 	update_option( 'db_version', $wp_db_version );
   986 	$got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
   978 	$got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
   987 
   979 
   988 	if ( ! $got_gmt_fields ) {
   980 	if ( ! $got_gmt_fields ) {
   989 
   981 
   990 		// Add or subtract time to all dates, to get GMT dates.
   982 		// Add or subtract time to all dates, to get GMT dates.
   991 		$add_hours   = intval( $diff_gmt_weblogger );
   983 		$add_hours   = (int) $diff_gmt_weblogger;
   992 		$add_minutes = intval( 60 * ( $diff_gmt_weblogger - $add_hours ) );
   984 		$add_minutes = (int) ( 60 * ( $diff_gmt_weblogger - $add_hours ) );
   993 		$wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
   985 		$wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
   994 		$wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
   986 		$wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
   995 		$wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
   987 		$wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
   996 		$wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
   988 		$wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
   997 		$wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
   989 		$wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
  1076 	foreach ( $options as $option ) {
  1068 	foreach ( $options as $option ) {
  1077 		if ( 1 != $option->dupes ) { // Could this be done in the query?
  1069 		if ( 1 != $option->dupes ) { // Could this be done in the query?
  1078 			$limit    = $option->dupes - 1;
  1070 			$limit    = $option->dupes - 1;
  1079 			$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
  1071 			$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
  1080 			if ( $dupe_ids ) {
  1072 			if ( $dupe_ids ) {
  1081 				$dupe_ids = join( ',', $dupe_ids );
  1073 				$dupe_ids = implode( ',', $dupe_ids );
  1082 				$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
  1074 				$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
  1083 			}
  1075 			}
  1084 		}
  1076 		}
  1085 	}
  1077 	}
  1086 
  1078 
  2012 	if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
  2004 	if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
  2013 		// Sites with malformed DB schemas are on their own.
  2005 		// Sites with malformed DB schemas are on their own.
  2014 		return;
  2006 		return;
  2015 	}
  2007 	}
  2016 
  2008 
  2017 	$allowed_length = intval( $content_length['length'] ) - 10;
  2009 	$allowed_length = (int) $content_length['length'] - 10;
  2018 
  2010 
  2019 	$comments = $wpdb->get_results(
  2011 	$comments = $wpdb->get_results(
  2020 		"SELECT `comment_ID` FROM `{$wpdb->comments}`
  2012 		"SELECT `comment_ID` FROM `{$wpdb->comments}`
  2021 			WHERE `comment_date_gmt` > '2015-04-26'
  2013 			WHERE `comment_date_gmt` > '2015-04-26'
  2022 			AND LENGTH( `comment_content` ) >= {$allowed_length}
  2014 			AND LENGTH( `comment_content` ) >= {$allowed_length}
  2197 	}
  2189 	}
  2198 
  2190 
  2199 	if ( $wp_current_db_version < 48748 ) {
  2191 	if ( $wp_current_db_version < 48748 ) {
  2200 		update_option( 'finished_updating_comment_type', 0 );
  2192 		update_option( 'finished_updating_comment_type', 0 );
  2201 		wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
  2193 		wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
       
  2194 	}
       
  2195 }
       
  2196 
       
  2197 /**
       
  2198  * Executes changes made in WordPress 5.6.0.
       
  2199  *
       
  2200  * @ignore
       
  2201  * @since 5.6.0
       
  2202  */
       
  2203 function upgrade_560() {
       
  2204 	global $wp_current_db_version, $wpdb;
       
  2205 
       
  2206 	if ( $wp_current_db_version < 49572 ) {
       
  2207 		/*
       
  2208 		 * Clean up the `post_category` column removed from schema in version 2.8.0.
       
  2209 		 * Its presence may conflict with `WP_Post::__get()`.
       
  2210 		 */
       
  2211 		$post_category_exists = $wpdb->get_var( "SHOW COLUMNS FROM $wpdb->posts LIKE 'post_category'" );
       
  2212 		if ( ! is_null( $post_category_exists ) ) {
       
  2213 			$wpdb->query( "ALTER TABLE $wpdb->posts DROP COLUMN `post_category`" );
       
  2214 		}
       
  2215 
       
  2216 		/*
       
  2217 		 * When upgrading from WP < 5.6.0 set the core major auto-updates option to `unset` by default.
       
  2218 		 * This overrides the same option from populate_options() that is intended for new installs.
       
  2219 		 * See https://core.trac.wordpress.org/ticket/51742.
       
  2220 		 */
       
  2221 		update_option( 'auto_update_core_major', 'unset' );
       
  2222 	}
       
  2223 
       
  2224 	if ( $wp_current_db_version < 49632 ) {
       
  2225 		/*
       
  2226 		 * Regenerate the .htaccess file to add the `HTTP_AUTHORIZATION` rewrite rule.
       
  2227 		 * See https://core.trac.wordpress.org/ticket/51723.
       
  2228 		 */
       
  2229 		save_mod_rewrite_rules();
       
  2230 	}
       
  2231 
       
  2232 	if ( $wp_current_db_version < 49735 ) {
       
  2233 		delete_transient( 'dirsize_cache' );
       
  2234 	}
       
  2235 
       
  2236 	if ( $wp_current_db_version < 49752 ) {
       
  2237 		$results = $wpdb->get_results(
       
  2238 			$wpdb->prepare(
       
  2239 				"SELECT 1 FROM {$wpdb->usermeta} WHERE meta_key = %s LIMIT 1",
       
  2240 				WP_Application_Passwords::USERMETA_KEY_APPLICATION_PASSWORDS
       
  2241 			)
       
  2242 		);
       
  2243 
       
  2244 		if ( ! empty( $results ) ) {
       
  2245 			$network_id = get_main_network_id();
       
  2246 			update_network_option( $network_id, WP_Application_Passwords::OPTION_KEY_IN_USE, 1 );
       
  2247 		}
  2202 	}
  2248 	}
  2203 }
  2249 }
  2204 
  2250 
  2205 /**
  2251 /**
  2206  * Executes network-level upgrade routines.
  2252  * Executes network-level upgrade routines.
  3454 	}
  3500 	}
  3455 
  3501 
  3456 	/**
  3502 	/**
  3457 	 * Filters if upgrade routines should be run on global tables.
  3503 	 * Filters if upgrade routines should be run on global tables.
  3458 	 *
  3504 	 *
       
  3505 	 * @since 4.3.0
       
  3506 	 *
  3459 	 * @param bool $should_upgrade Whether to run the upgrade routines on global tables.
  3507 	 * @param bool $should_upgrade Whether to run the upgrade routines on global tables.
  3460 	 */
  3508 	 */
  3461 	return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade );
  3509 	return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade );
  3462 }
  3510 }