wp/wp-admin/includes/upgrade.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-admin/includes/upgrade.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/upgrade.php	Tue Dec 15 13:49:49 2020 +0100
@@ -10,14 +10,14 @@
 
 /** Include user installation customization script. */
 if ( file_exists( WP_CONTENT_DIR . '/install.php' ) ) {
-	require( WP_CONTENT_DIR . '/install.php' );
+	require WP_CONTENT_DIR . '/install.php';
 }
 
 /** WordPress Administration API */
-require_once( ABSPATH . 'wp-admin/includes/admin.php' );
+require_once ABSPATH . 'wp-admin/includes/admin.php';
 
 /** WordPress Schema API */
-require_once( ABSPATH . 'wp-admin/includes/schema.php' );
+require_once ABSPATH . 'wp-admin/includes/schema.php';
 
 if ( ! function_exists( 'wp_install' ) ) :
 	/**
@@ -35,7 +35,14 @@
 	 * @param string $deprecated    Optional. Not used.
 	 * @param string $user_password Optional. User's chosen password. Default empty (random password).
 	 * @param string $language      Optional. Language chosen. Default empty.
-	 * @return array Array keys 'url', 'user_id', 'password', and 'password_message'.
+	 * @return array {
+	 *     Data for the newly installed site.
+	 *
+	 *     @type string $url              The URL of the site.
+	 *     @type int    $user_id          The ID of the site owner.
+	 *     @type string $password         The password of the site owner, if their user account didn't already exist.
+	 *     @type string $password_message The explanatory message regarding the password.
+	 * }
 	 */
 	function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) {
 		if ( ! empty( $deprecated ) ) {
@@ -75,16 +82,20 @@
 		$user_id        = username_exists( $user_name );
 		$user_password  = trim( $user_password );
 		$email_password = false;
+		$user_created   = false;
+
 		if ( ! $user_id && empty( $user_password ) ) {
 			$user_password = wp_generate_password( 12, false );
 			$message       = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
 			$user_id       = wp_create_user( $user_name, $user_password, $user_email );
 			update_user_option( $user_id, 'default_password_nag', true, true );
 			$email_password = true;
+			$user_created   = true;
 		} elseif ( ! $user_id ) {
-			// Password has been provided
-			$message = '<em>' . __( 'Your chosen password.' ) . '</em>';
-			$user_id = wp_create_user( $user_name, $user_password, $user_email );
+			// Password has been provided.
+			$message      = '<em>' . __( 'Your chosen password.' ) . '</em>';
+			$user_id      = wp_create_user( $user_name, $user_password, $user_email );
+			$user_created = true;
 		} else {
 			$message = __( 'User already exists. Password inherited.' );
 		}
@@ -92,6 +103,11 @@
 		$user = new WP_User( $user_id );
 		$user->set_role( 'administrator' );
 
+		if ( $user_created ) {
+			$user->user_url = $guessurl;
+			wp_update_user( $user );
+		}
+
 		wp_install_defaults( $user_id );
 
 		wp_install_maybe_enable_pretty_permalinks();
@@ -129,8 +145,8 @@
 	 *
 	 * @since 2.1.0
 	 *
-	 * @global wpdb       $wpdb
-	 * @global WP_Rewrite $wp_rewrite
+	 * @global wpdb       $wpdb         WordPress database abstraction object.
+	 * @global WP_Rewrite $wp_rewrite   WordPress rewrite component.
 	 * @global string     $table_prefix
 	 *
 	 * @param int $user_id User ID.
@@ -138,14 +154,14 @@
 	function wp_install_defaults( $user_id ) {
 		global $wpdb, $wp_rewrite, $table_prefix;
 
-		// Default category
+		// Default category.
 		$cat_name = __( 'Uncategorized' );
-		/* translators: Default category slug */
+		/* translators: Default category slug. */
 		$cat_slug = sanitize_title( _x( 'Uncategorized', 'Default category slug' ) );
 
 		if ( global_terms_enabled() ) {
 			$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
-			if ( $cat_id == null ) {
+			if ( null == $cat_id ) {
 				$wpdb->insert(
 					$wpdb->sitecategories,
 					array(
@@ -183,7 +199,7 @@
 		);
 		$cat_tt_id = $wpdb->insert_id;
 
-		// First post
+		// First post.
 		$now             = current_time( 'mysql' );
 		$now_gmt         = current_time( 'mysql', 1 );
 		$first_post_guid = get_option( 'home' ) . '/?p=1';
@@ -193,7 +209,7 @@
 
 			if ( ! $first_post ) {
 				$first_post = "<!-- wp:paragraph -->\n<p>" .
-				/* translators: first post content, %s: site link */
+				/* translators: First post content. %s: Site link. */
 				__( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ) .
 				"</p>\n<!-- /wp:paragraph -->";
 			}
@@ -203,12 +219,12 @@
 				sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name )
 			);
 
-			// Back-compat for pre-4.4
+			// Back-compat for pre-4.4.
 			$first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post );
 			$first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post );
 		} else {
 			$first_post = "<!-- wp:paragraph -->\n<p>" .
-			/* translators: first post content, %s: site link */
+			/* translators: First post content. %s: Site link. */
 			__( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ) .
 			"</p>\n<!-- /wp:paragraph -->";
 		}
@@ -222,7 +238,7 @@
 				'post_content'          => $first_post,
 				'post_excerpt'          => '',
 				'post_title'            => __( 'Hello world!' ),
-				/* translators: Default post slug */
+				/* translators: Default post slug. */
 				'post_name'             => sanitize_title( _x( 'hello-world', 'Default post slug' ) ),
 				'post_modified'         => $now,
 				'post_modified_gmt'     => $now_gmt,
@@ -241,7 +257,7 @@
 			)
 		);
 
-		// Default comment
+		// Default comment.
 		if ( is_multisite() ) {
 			$first_comment_author = get_site_option( 'first_comment_author' );
 			$first_comment_email  = get_site_option( 'first_comment_email' );
@@ -267,38 +283,39 @@
 				'comment_date'         => $now,
 				'comment_date_gmt'     => $now_gmt,
 				'comment_content'      => $first_comment,
+				'comment_type'         => 'comment',
 			)
 		);
 
-		// First Page
+		// First page.
 		if ( is_multisite() ) {
 			$first_page = get_site_option( 'first_page' );
 		}
 
 		if ( empty( $first_page ) ) {
 			$first_page = "<!-- wp:paragraph -->\n<p>";
-			/* translators: first page content */
+			/* translators: First page content. */
 			$first_page .= __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:" );
 			$first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
 
 			$first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
-			/* translators: first page content */
+			/* translators: First page content. */
 			$first_page .= __( "Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)" );
 			$first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
 
 			$first_page .= "<!-- wp:paragraph -->\n<p>";
-			/* translators: first page content */
+			/* translators: First page content. */
 			$first_page .= __( '...or something like this:' );
 			$first_page .= "</p>\n<!-- /wp:paragraph -->\n\n";
 
 			$first_page .= "<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><p>";
-			/* translators: first page content */
+			/* translators: First page content. */
 			$first_page .= __( 'The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.' );
 			$first_page .= "</p></blockquote>\n<!-- /wp:quote -->\n\n";
 
 			$first_page .= "<!-- wp:paragraph -->\n<p>";
 			$first_page .= sprintf(
-				/* translators: first page content, %s: site admin URL */
+				/* translators: First page content. %s: Site admin URL. */
 				__( 'As a new WordPress user, you should go to <a href="%s">your dashboard</a> to delete this page and create new pages for your content. Have fun!' ),
 				admin_url()
 			);
@@ -316,7 +333,7 @@
 				'post_excerpt'          => '',
 				'comment_status'        => 'closed',
 				'post_title'            => __( 'Sample Page' ),
-				/* translators: Default page slug */
+				/* translators: Default page slug. */
 				'post_name'             => __( 'sample-page' ),
 				'post_modified'         => $now,
 				'post_modified_gmt'     => $now_gmt,
@@ -336,13 +353,13 @@
 			)
 		);
 
-		// Privacy Policy page
+		// Privacy Policy page.
 		if ( is_multisite() ) {
 			// Disable by default unless the suggested content is provided.
 			$privacy_policy_content = get_site_option( 'default_privacy_policy_content' );
 		} else {
 			if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
-				include_once( ABSPATH . 'wp-admin/includes/misc.php' );
+				include_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
 			}
 
 			$privacy_policy_content = WP_Privacy_Policy_Content::get_default_content();
@@ -361,7 +378,7 @@
 					'post_excerpt'          => '',
 					'comment_status'        => 'closed',
 					'post_title'            => __( 'Privacy Policy' ),
-					/* translators: Privacy Policy page slug */
+					/* translators: Privacy Policy page slug. */
 					'post_name'             => __( 'privacy-policy' ),
 					'post_modified'         => $now,
 					'post_modified_gmt'     => $now_gmt,
@@ -450,9 +467,11 @@
 					0 => 'search-2',
 					1 => 'recent-posts-2',
 					2 => 'recent-comments-2',
-					3 => 'archives-2',
-					4 => 'categories-2',
-					5 => 'meta-2',
+				),
+				'sidebar-2'           => array(
+					0 => 'archives-2',
+					1 => 'categories-2',
+					2 => 'meta-2',
 				),
 				'array_version'       => 3,
 			)
@@ -475,8 +494,9 @@
 			$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level' ) );
 			$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities' ) );
 
-			// Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
-			if ( ! is_super_admin( $user_id ) && $user_id != 1 ) {
+			// Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.)
+			// TODO: Get previous_blog_id.
+			if ( ! is_super_admin( $user_id ) && 1 != $user_id ) {
 				$wpdb->delete(
 					$wpdb->usermeta,
 					array(
@@ -525,29 +545,29 @@
 		$wp_rewrite->set_permalink_structure( $permalink_structure );
 
 		/*
-		  * Flush rules with the hard option to force refresh of the web-server's
-		  * rewrite config file (e.g. .htaccess or web.config).
-		  */
+		 * Flush rules with the hard option to force refresh of the web-server's
+		 * rewrite config file (e.g. .htaccess or web.config).
+		 */
 		$wp_rewrite->flush_rules( true );
 
 		$test_url = '';
 
-		// Test against a real WordPress Post
+		// Test against a real WordPress post.
 		$first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
 		if ( $first_post ) {
 			$test_url = get_permalink( $first_post->ID );
 		}
 
 		/*
-		  * Send a request to the site, and check whether
-		  * the 'x-pingback' header is returned as expected.
-		  *
-		  * Uses wp_remote_get() instead of wp_remote_head() because web servers
-		  * can block head requests.
-		  */
+		 * Send a request to the site, and check whether
+		 * the 'x-pingback' header is returned as expected.
+		 *
+		 * Uses wp_remote_get() instead of wp_remote_head() because web servers
+		 * can block head requests.
+		 */
 		$response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
 		$x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
-		$pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo( 'pingback_url' );
+		$pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;
 
 		if ( $pretty_permalinks ) {
 			return true;
@@ -583,8 +603,9 @@
 		$email     = $user->user_email;
 		$name      = $user->user_login;
 		$login_url = wp_login_url();
-		/* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL */
+
 		$message = sprintf(
+			/* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL. */
 			__(
 				'Your new WordPress site has been successfully set up at:
 
@@ -608,7 +629,7 @@
 			$login_url
 		);
 
-		@wp_mail( $email, __( 'New WordPress Site' ), $message );
+		wp_mail( $email, __( 'New WordPress Site' ), $message );
 	}
 endif;
 
@@ -620,16 +641,16 @@
 	 *
 	 * @since 2.1.0
 	 *
-	 * @global int  $wp_current_db_version
-	 * @global int  $wp_db_version
-	 * @global wpdb $wpdb WordPress database abstraction object.
+	 * @global int  $wp_current_db_version The old (current) database version.
+	 * @global int  $wp_db_version         The new database version.
+	 * @global wpdb $wpdb                  WordPress database abstraction object.
 	 */
 	function wp_upgrade() {
 		global $wp_current_db_version, $wp_db_version, $wpdb;
 
 		$wp_current_db_version = __get_option( 'db_version' );
 
-		// We are up-to-date. Nothing to do.
+		// We are up to date. Nothing to do.
 		if ( $wp_db_version == $wp_current_db_version ) {
 			return;
 		}
@@ -649,13 +670,8 @@
 		wp_cache_flush();
 
 		if ( is_multisite() ) {
-			$site_id = get_current_blog_id();
-
-			if ( $wpdb->get_row( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = %d", $site_id ) ) ) {
-				$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->blog_versions} SET db_version = %d WHERE blog_id = %d", $wp_db_version, $site_id ) );
-			} else {
-				$wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( %d, %d, NOW() );", $site_id, $wp_db_version ) );
-			}
+			update_site_meta( get_current_blog_id(), 'db_version', $wp_db_version );
+			update_site_meta( get_current_blog_id(), 'db_last_updated', microtime() );
 		}
 
 		/**
@@ -679,14 +695,15 @@
  * @ignore
  * @since 1.0.1
  *
- * @global int $wp_current_db_version
- * @global int $wp_db_version
+ * @global int $wp_current_db_version The old (current) database version.
+ * @global int $wp_db_version         The new database version.
  */
 function upgrade_all() {
 	global $wp_current_db_version, $wp_db_version;
+
 	$wp_current_db_version = __get_option( 'db_version' );
 
-	// We are up-to-date. Nothing to do.
+	// We are up to date. Nothing to do.
 	if ( $wp_db_version == $wp_current_db_version ) {
 		return;
 	}
@@ -815,6 +832,14 @@
 		upgrade_510();
 	}
 
+	if ( $wp_current_db_version < 45744 ) {
+		upgrade_530();
+	}
+
+	if ( $wp_current_db_version < 48575 ) {
+		upgrade_550();
+	}
+
 	maybe_disable_link_manager();
 
 	maybe_disable_automattic_widgets();
@@ -834,11 +859,11 @@
 function upgrade_100() {
 	global $wpdb;
 
-	// Get the title and ID of every post, post_name to check if it already has a value
+	// Get the title and ID of every post, post_name to check if it already has a value.
 	$posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
 	if ( $posts ) {
 		foreach ( $posts as $post ) {
-			if ( '' == $post->post_name ) {
+			if ( '' === $post->post_name ) {
 				$newtitle = sanitize_title( $post->post_title );
 				$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) );
 			}
@@ -847,7 +872,7 @@
 
 	$categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" );
 	foreach ( $categories as $category ) {
-		if ( '' == $category->category_nicename ) {
+		if ( '' === $category->category_nicename ) {
 			$newtitle = sanitize_title( $category->cat_name );
 			$wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) );
 		}
@@ -873,9 +898,9 @@
 	$allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
 	if ( $allposts ) :
 		foreach ( $allposts as $post ) {
-			// Check to see if it's already been imported
+			// Check to see if it's already been imported.
 			$cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
-			if ( ! $cat && 0 != $post->post_category ) { // If there's no result
+			if ( ! $cat && 0 != $post->post_category ) { // If there's no result.
 				$wpdb->insert(
 					$wpdb->post2cat,
 					array(
@@ -899,7 +924,7 @@
 function upgrade_101() {
 	global $wpdb;
 
-	// Clean up indices, add a few
+	// Clean up indices, add a few.
 	add_clean_index( $wpdb->posts, 'post_name' );
 	add_clean_index( $wpdb->posts, 'post_status' );
 	add_clean_index( $wpdb->categories, 'category_nicename' );
@@ -923,7 +948,7 @@
 	// Set user_nicename.
 	$users = $wpdb->get_results( "SELECT ID, user_nickname, user_nicename FROM $wpdb->users" );
 	foreach ( $users as $user ) {
-		if ( '' == $user->user_nicename ) {
+		if ( '' === $user->user_nicename ) {
 			$newname = sanitize_title( $user->user_nickname );
 			$wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
 		}
@@ -936,12 +961,12 @@
 		}
 	}
 
-	// Get the GMT offset, we'll use that later on
+	// Get the GMT offset, we'll use that later on.
 	$all_options = get_alloptions_110();
 
 	$time_difference = $all_options->time_difference;
 
-		$server_time = time() + date( 'Z' );
+		$server_time = time() + gmdate( 'Z' );
 	$weblogger_time  = $server_time + $time_difference * HOUR_IN_SECONDS;
 	$gmt_time        = time();
 
@@ -950,17 +975,19 @@
 	$diff_gmt_weblogger    = $diff_gmt_server - $diff_weblogger_server;
 	$gmt_offset            = -$diff_gmt_weblogger;
 
-	// Add a gmt_offset option, with value $gmt_offset
+	// Add a gmt_offset option, with value $gmt_offset.
 	add_option( 'gmt_offset', $gmt_offset );
 
-	// Check if we already set the GMT fields (if we did, then
-	// MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
-	// <michel_v> I just slapped myself silly for not thinking about it earlier
-	$got_gmt_fields = ! ( $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) == '0000-00-00 00:00:00' );
+	/*
+	 * Check if we already set the GMT fields. If we did, then
+	 * MAX(post_date_gmt) can't be '0000-00-00 00:00:00'.
+	 * <michel_v> I just slapped myself silly for not thinking about it earlier.
+	 */
+	$got_gmt_fields = ( '0000-00-00 00:00:00' !== $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) );
 
 	if ( ! $got_gmt_fields ) {
 
-		// Add or subtract time to all dates, to get GMT dates
+		// Add or subtract time to all dates, to get GMT dates.
 		$add_hours   = intval( $diff_gmt_weblogger );
 		$add_minutes = intval( 60 * ( $diff_gmt_weblogger - $add_hours ) );
 		$wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
@@ -1034,24 +1061,24 @@
 		update_option( 'active_plugins', $active_plugins );
 	}
 
-	// Obsolete tables
+	// Obsolete tables.
 	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' );
 	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' );
 	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups' );
 	$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' );
 
-	// Update comments table to use comment_type
+	// Update comments table to use comment_type.
 	$wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" );
 	$wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
 
-	// Some versions have multiple duplicate option_name rows with the same values
+	// Some versions have multiple duplicate option_name rows with the same values.
 	$options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
 	foreach ( $options as $option ) {
 		if ( 1 != $option->dupes ) { // Could this be done in the query?
 			$limit    = $option->dupes - 1;
 			$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
 			if ( $dupe_ids ) {
-				$dupe_ids = join( $dupe_ids, ',' );
+				$dupe_ids = join( ',', $dupe_ids );
 				$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
 			}
 		}
@@ -1066,8 +1093,8 @@
  * @ignore
  * @since 2.0.0
  *
- * @global wpdb $wpdb WordPress database abstraction object.
- * @global int  $wp_current_db_version
+ * @global wpdb $wpdb                  WordPress database abstraction object.
+ * @global int  $wp_current_db_version The old (current) database version.
  */
 function upgrade_160() {
 	global $wpdb, $wp_current_db_version;
@@ -1106,22 +1133,22 @@
 
 		if ( isset( $user->user_idmode ) ) :
 			$idmode = $user->user_idmode;
-			if ( $idmode == 'nickname' ) {
+			if ( 'nickname' === $idmode ) {
 				$id = $user->user_nickname;
 			}
-			if ( $idmode == 'login' ) {
+			if ( 'login' === $idmode ) {
 				$id = $user->user_login;
 			}
-			if ( $idmode == 'firstname' ) {
+			if ( 'firstname' === $idmode ) {
 				$id = $user->user_firstname;
 			}
-			if ( $idmode == 'lastname' ) {
+			if ( 'lastname' === $idmode ) {
 				$id = $user->user_lastname;
 			}
-			if ( $idmode == 'namefl' ) {
+			if ( 'namefl' === $idmode ) {
 				$id = $user->user_firstname . ' ' . $user->user_lastname;
 			}
-			if ( $idmode == 'namelf' ) {
+			if ( 'namelf' === $idmode ) {
 				$id = $user->user_lastname . ' ' . $user->user_firstname;
 			}
 			if ( ! $idmode ) {
@@ -1185,11 +1212,11 @@
  * @ignore
  * @since 2.1.0
  *
- * @global wpdb $wpdb WordPress database abstraction object.
- * @global int  $wp_current_db_version
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_210() {
-	global $wpdb, $wp_current_db_version;
+	global $wp_current_db_version, $wpdb;
 
 	if ( $wp_current_db_version < 3506 ) {
 		// Update status and type.
@@ -1200,10 +1227,10 @@
 				$status = $post->post_status;
 				$type   = 'post';
 
-				if ( 'static' == $status ) {
+				if ( 'static' === $status ) {
 					$status = 'publish';
 					$type   = 'page';
-				} elseif ( 'attachment' == $status ) {
+				} elseif ( 'attachment' === $status ) {
 					$status = 'inherit';
 					$type   = 'attachment';
 				}
@@ -1237,8 +1264,8 @@
  * @ignore
  * @since 2.3.0
  *
- * @global wpdb $wpdb WordPress database abstraction object.
- * @global int  $wp_current_db_version
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_230() {
 	global $wp_current_db_version, $wpdb;
@@ -1260,7 +1287,8 @@
 		$term_group  = 0;
 
 		// Associate terms with the same slug in a term group and make slugs unique.
-		if ( $exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) ) ) {
+		$exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
+		if ( $exists ) {
 			$term_group = $exists[0]->term_group;
 			$id         = $exists[0]->term_id;
 			$num        = 2;
@@ -1330,7 +1358,7 @@
 		$post_id  = (int) $post->post_id;
 		$term_id  = (int) $post->category_id;
 		$taxonomy = 'category';
-		if ( ! empty( $post->rel_type ) && 'tag' == $post->rel_type ) {
+		if ( ! empty( $post->rel_type ) && 'tag' === $post->rel_type ) {
 			$taxonomy = 'tag';
 		}
 		$tt_id = $tt_ids[ $term_id ][ $taxonomy ];
@@ -1351,7 +1379,7 @@
 	if ( $wp_current_db_version < 3570 ) {
 		/*
 		 * Create link_category terms for link categories. Create a map of link
-		 * cat IDs to link_category terms.
+		 * category IDs to link_category terms.
 		 */
 		$link_cat_id_map  = array();
 		$default_link_cat = 0;
@@ -1365,7 +1393,8 @@
 			$term_group = 0;
 
 			// Associate terms with the same slug in a term group and make slugs unique.
-			if ( $exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) ) ) {
+			$exists = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug ) );
+			if ( $exists ) {
 				$term_group = $exists[0]->term_group;
 				$term_id    = $exists[0]->term_id;
 			}
@@ -1391,7 +1420,7 @@
 			$tt_ids[ $term_id ] = (int) $wpdb->insert_id;
 		}
 
-		// Associate links to cats.
+		// Associate links to categories.
 		$links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
 		if ( ! empty( $links ) ) {
 			foreach ( $links as $link ) {
@@ -1440,14 +1469,14 @@
 	}
 
 	if ( $wp_current_db_version < 4772 ) {
-		// Obsolete linkcategories table
+		// Obsolete linkcategories table.
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' );
 	}
 
-	// Recalculate all counts
+	// Recalculate all counts.
 	$terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" );
 	foreach ( (array) $terms as $term ) {
-		if ( ( 'post_tag' == $term->taxonomy ) || ( 'category' == $term->taxonomy ) ) {
+		if ( 'post_tag' === $term->taxonomy || 'category' === $term->taxonomy ) {
 			$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id ) );
 		} else {
 			$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id ) );
@@ -1509,7 +1538,7 @@
  * @ignore
  * @since 2.5.0
  *
- * @global int $wp_current_db_version
+ * @global int $wp_current_db_version The old (current) database version.
  */
 function upgrade_250() {
 	global $wp_current_db_version;
@@ -1540,7 +1569,7 @@
  * @ignore
  * @since 2.6.0
  *
- * @global int $wp_current_db_version
+ * @global int $wp_current_db_version The old (current) database version.
  */
 function upgrade_260() {
 	global $wp_current_db_version;
@@ -1556,17 +1585,17 @@
  * @ignore
  * @since 2.7.0
  *
- * @global wpdb $wpdb WordPress database abstraction object.
- * @global int  $wp_current_db_version
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_270() {
-	global $wpdb, $wp_current_db_version;
+	global $wp_current_db_version, $wpdb;
 
 	if ( $wp_current_db_version < 8980 ) {
 		populate_roles_270();
 	}
 
-	// Update post_date for unpublished posts with empty timestamp
+	// Update post_date for unpublished posts with empty timestamp.
 	if ( $wp_current_db_version < 8921 ) {
 		$wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
 	}
@@ -1578,8 +1607,8 @@
  * @ignore
  * @since 2.8.0
  *
- * @global int  $wp_current_db_version
- * @global wpdb $wpdb WordPress database abstraction object.
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_280() {
 	global $wp_current_db_version, $wpdb;
@@ -1611,13 +1640,14 @@
  * @ignore
  * @since 2.9.0
  *
- * @global int $wp_current_db_version
+ * @global int $wp_current_db_version The old (current) database version.
  */
 function upgrade_290() {
 	global $wp_current_db_version;
 
 	if ( $wp_current_db_version < 11958 ) {
-		// Previously, setting depth to 1 would redundantly disable threading, but now 2 is the minimum depth to avoid confusion
+		// Previously, setting depth to 1 would redundantly disable threading,
+		// but now 2 is the minimum depth to avoid confusion.
 		if ( get_option( 'thread_comments_depth' ) == '1' ) {
 			update_option( 'thread_comments_depth', 2 );
 			update_option( 'thread_comments', 0 );
@@ -1631,8 +1661,8 @@
  * @ignore
  * @since 3.0.0
  *
- * @global int  $wp_current_db_version
- * @global wpdb $wpdb WordPress database abstraction object.
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_300() {
 	global $wp_current_db_version, $wpdb;
@@ -1682,8 +1712,8 @@
  * @ignore
  * @since 3.3.0
  *
- * @global int   $wp_current_db_version
- * @global wpdb  $wpdb
+ * @global int   $wp_current_db_version The old (current) database version.
+ * @global wpdb  $wpdb                  WordPress database abstraction object.
  * @global array $wp_registered_widgets
  * @global array $sidebars_widgets
  */
@@ -1749,7 +1779,7 @@
 			$sidebars_widgets                   = $_sidebars_widgets;
 			unset( $_sidebars_widgets );
 
-			// intentional fall-through to upgrade to the next version.
+			// Intentional fall-through to upgrade to the next version.
 		case 2:
 			$sidebars_widgets                  = retrieve_widgets();
 			$sidebars_widgets['array_version'] = 3;
@@ -1763,8 +1793,8 @@
  * @ignore
  * @since 3.4.0
  *
- * @global int   $wp_current_db_version
- * @global wpdb  $wpdb
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_340() {
 	global $wp_current_db_version, $wpdb;
@@ -1786,7 +1816,7 @@
 	}
 
 	if ( $wp_current_db_version < 20080 ) {
-		if ( 'yes' == $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
+		if ( 'yes' === $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
 			$uninstall_plugins = get_option( 'uninstall_plugins' );
 			delete_option( 'uninstall_plugins' );
 			add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' );
@@ -1800,14 +1830,14 @@
  * @ignore
  * @since 3.5.0
  *
- * @global int   $wp_current_db_version
- * @global wpdb  $wpdb
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_350() {
 	global $wp_current_db_version, $wpdb;
 
 	if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
-		update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options()
+		update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options().
 	}
 
 	if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) {
@@ -1823,8 +1853,11 @@
 		}
 	}
 
-	if ( $wp_current_db_version < 22422 && $term = get_term_by( 'slug', 'post-format-standard', 'post_format' ) ) {
-		wp_delete_term( $term->term_id, 'post_format' );
+	if ( $wp_current_db_version < 22422 ) {
+		$term = get_term_by( 'slug', 'post-format-standard', 'post_format' );
+		if ( $term ) {
+			wp_delete_term( $term->term_id, 'post_format' );
+		}
 	}
 }
 
@@ -1834,10 +1867,11 @@
  * @ignore
  * @since 3.7.0
  *
- * @global int $wp_current_db_version
+ * @global int $wp_current_db_version The old (current) database version.
  */
 function upgrade_370() {
 	global $wp_current_db_version;
+
 	if ( $wp_current_db_version < 25824 ) {
 		wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' );
 	}
@@ -1850,10 +1884,11 @@
  * @since 3.7.2
  * @since 3.8.0
  *
- * @global int $wp_current_db_version
+ * @global int $wp_current_db_version The old (current) database version.
  */
 function upgrade_372() {
 	global $wp_current_db_version;
+
 	if ( $wp_current_db_version < 26148 ) {
 		wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
 	}
@@ -1865,10 +1900,11 @@
  * @ignore
  * @since 3.8.0
  *
- * @global int $wp_current_db_version
+ * @global int $wp_current_db_version The old (current) database version.
  */
 function upgrade_380() {
 	global $wp_current_db_version;
+
 	if ( $wp_current_db_version < 26691 ) {
 		deactivate_plugins( array( 'mp6/mp6.php' ), true );
 	}
@@ -1880,13 +1916,14 @@
  * @ignore
  * @since 4.0.0
  *
- * @global int $wp_current_db_version
+ * @global int $wp_current_db_version The old (current) database version.
  */
 function upgrade_400() {
 	global $wp_current_db_version;
+
 	if ( $wp_current_db_version < 29630 ) {
 		if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
-			if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages() ) ) {
+			if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages(), true ) ) {
 				update_option( 'WPLANG', WPLANG );
 			} else {
 				update_option( 'WPLANG', '' );
@@ -1900,9 +1937,6 @@
  *
  * @ignore
  * @since 4.2.0
- *
- * @global int   $wp_current_db_version
- * @global wpdb  $wpdb
  */
 function upgrade_420() {}
 
@@ -1912,7 +1946,7 @@
  * @ignore
  * @since 4.3.0
  *
- * @global int  $wp_current_db_version Current version.
+ * @global int  $wp_current_db_version The old (current) database version.
  * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_430() {
@@ -1951,11 +1985,10 @@
  * @ignore
  * @since 4.3.0
  *
- * @global int  $wp_current_db_version Current version.
- * @global wpdb $wpdb                  WordPress database abstraction object.
+ * @global wpdb $wpdb WordPress database abstraction object.
  */
 function upgrade_430_fix_comments() {
-	global $wp_current_db_version, $wpdb;
+	global $wpdb;
 
 	$content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
 
@@ -2002,7 +2035,7 @@
  * @since 4.3.1
  */
 function upgrade_431() {
-	// Fix incorrect cron entries for term splitting
+	// Fix incorrect cron entries for term splitting.
 	$cron_array = _get_cron_array();
 	if ( isset( $cron_array['wp_batch_split_terms'] ) ) {
 		unset( $cron_array['wp_batch_split_terms'] );
@@ -2016,7 +2049,7 @@
  * @ignore
  * @since 4.4.0
  *
- * @global int  $wp_current_db_version Current version.
+ * @global int  $wp_current_db_version The old (current) database version.
  * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_440() {
@@ -2041,7 +2074,7 @@
  * @ignore
  * @since 4.5.0
  *
- * @global int  $wp_current_db_version Current database version.
+ * @global int  $wp_current_db_version The old (current) database version.
  * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_450() {
@@ -2066,7 +2099,7 @@
  * @ignore
  * @since 4.6.0
  *
- * @global int $wp_current_db_version Current database version.
+ * @global int $wp_current_db_version The old (current) database version.
  */
 function upgrade_460() {
 	global $wp_current_db_version;
@@ -2113,20 +2146,77 @@
 }
 
 /**
+ * Executes changes made in WordPress 5.3.0.
+ *
+ * @ignore
+ * @since 5.3.0
+ */
+function upgrade_530() {
+	/*
+	 * The `admin_email_lifespan` option may have been set by an admin that just logged in,
+	 * saw the verification screen, clicked on a button there, and is now upgrading the db,
+	 * or by populate_options() that is called earlier in upgrade_all().
+	 * In the second case `admin_email_lifespan` should be reset so the verification screen
+	 * is shown next time an admin logs in.
+	 */
+	if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) {
+		update_option( 'admin_email_lifespan', 0 );
+	}
+}
+
+/**
+ * Executes changes made in WordPress 5.5.0.
+ *
+ * @ignore
+ * @since 5.5.0
+ */
+function upgrade_550() {
+	global $wp_current_db_version;
+
+	if ( $wp_current_db_version < 48121 ) {
+		$comment_previously_approved = get_option( 'comment_whitelist', '' );
+		update_option( 'comment_previously_approved', $comment_previously_approved );
+		delete_option( 'comment_whitelist' );
+	}
+
+	if ( $wp_current_db_version < 48575 ) {
+		// Use more clear and inclusive language.
+		$disallowed_list = get_option( 'blacklist_keys' );
+
+		/*
+		 * This option key was briefly renamed `blocklist_keys`.
+		 * Account for sites that have this key present when the original key does not exist.
+		 */
+		if ( false === $disallowed_list ) {
+			$disallowed_list = get_option( 'blocklist_keys' );
+		}
+
+		update_option( 'disallowed_keys', $disallowed_list );
+		delete_option( 'blacklist_keys' );
+		delete_option( 'blocklist_keys' );
+	}
+
+	if ( $wp_current_db_version < 48748 ) {
+		update_option( 'finished_updating_comment_type', 0 );
+		wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
+	}
+}
+
+/**
  * Executes network-level upgrade routines.
  *
  * @since 3.0.0
  *
- * @global int   $wp_current_db_version
- * @global wpdb  $wpdb
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function upgrade_network() {
 	global $wp_current_db_version, $wpdb;
 
-	// Always clear expired transients
+	// Always clear expired transients.
 	delete_expired_transients( true );
 
-	// 2.8.
+	// 2.8.0
 	if ( $wp_current_db_version < 11549 ) {
 		$wpmu_sitewide_plugins   = get_site_option( 'wpmu_sitewide_plugins' );
 		$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
@@ -2157,12 +2247,12 @@
 		}
 	}
 
-	// 3.0
+	// 3.0.0
 	if ( $wp_current_db_version < 13576 ) {
 		update_site_option( 'global_terms_enabled', '1' );
 	}
 
-	// 3.3
+	// 3.3.0
 	if ( $wp_current_db_version < 19390 ) {
 		update_site_option( 'initial_db_version', $wp_current_db_version );
 	}
@@ -2173,7 +2263,7 @@
 		}
 	}
 
-	// 3.4
+	// 3.4.0
 	if ( $wp_current_db_version < 20148 ) {
 		// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
 		$allowedthemes  = get_site_option( 'allowedthemes' );
@@ -2191,7 +2281,7 @@
 		}
 	}
 
-	// 3.5
+	// 3.5.0
 	if ( $wp_current_db_version < 21823 ) {
 		update_site_option( 'ms_files_rewriting', '1' );
 	}
@@ -2206,8 +2296,8 @@
 		}
 	}
 
-	// 4.2
-	if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) {
+	// 4.2.0
+	if ( $wp_current_db_version < 31351 && 'utf8mb4' === $wpdb->charset ) {
 		if ( wp_should_upgrade_global_tables() ) {
 			$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
 			$wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
@@ -2227,13 +2317,13 @@
 		}
 	}
 
-	// 4.3
+	// 4.3.0
 	if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) {
 		if ( wp_should_upgrade_global_tables() ) {
 			$upgrade = false;
 			$indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" );
 			foreach ( $indexes as $index ) {
-				if ( 'domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part ) {
+				if ( 'domain_path' === $index->Key_name && 'domain' === $index->Column_name && 140 != $index->Sub_part ) {
 					$upgrade = true;
 					break;
 				}
@@ -2256,7 +2346,7 @@
 		}
 	}
 
-	// 5.1
+	// 5.1.0
 	if ( $wp_current_db_version < 44467 ) {
 		$network_id = get_main_network_id();
 		delete_network_option( $network_id, 'site_meta_supported' );
@@ -2265,11 +2355,11 @@
 }
 
 //
-// General functions we use to actually do stuff
+// General functions we use to actually do stuff.
 //
 
 /**
- * Creates a table in the database if it doesn't already exist.
+ * Creates a table in the database, if it doesn't already exist.
  *
  * This method checks for an existing database and creates a new one if it's not
  * already present. It doesn't rely on MySQL's "IF NOT EXISTS" statement, but chooses
@@ -2277,28 +2367,29 @@
  *
  * @since 1.0.0
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $table_name Database table name to create.
+ * @param string $table_name Database table name.
  * @param string $create_ddl SQL statement to create table.
- * @return bool If table already exists or was created by function.
+ * @return bool True on success or if the table already exists. False on failure.
  */
 function maybe_create_table( $table_name, $create_ddl ) {
 	global $wpdb;
 
 	$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
 
-	if ( $wpdb->get_var( $query ) == $table_name ) {
+	if ( $wpdb->get_var( $query ) === $table_name ) {
 		return true;
 	}
 
-	// Didn't find it try to create it..
+	// Didn't find it, so try to create it.
 	$wpdb->query( $create_ddl );
 
 	// We cannot directly tell that whether this succeeded!
-	if ( $wpdb->get_var( $query ) == $table_name ) {
+	if ( $wpdb->get_var( $query ) === $table_name ) {
 		return true;
 	}
+
 	return false;
 }
 
@@ -2307,7 +2398,7 @@
  *
  * @since 1.0.1
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param string $table Database table name.
  * @param string $index Index name to drop.
@@ -2315,13 +2406,18 @@
  */
 function drop_index( $table, $index ) {
 	global $wpdb;
+
 	$wpdb->hide_errors();
+
 	$wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" );
-	// Now we need to take out all the extra ones we may have created
+
+	// Now we need to take out all the extra ones we may have created.
 	for ( $i = 0; $i < 25; $i++ ) {
 		$wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" );
 	}
+
 	$wpdb->show_errors();
+
 	return true;
 }
 
@@ -2330,7 +2426,7 @@
  *
  * @since 1.0.1
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param string $table Database table name.
  * @param string $index Database table index column.
@@ -2338,40 +2434,44 @@
  */
 function add_clean_index( $table, $index ) {
 	global $wpdb;
+
 	drop_index( $table, $index );
 	$wpdb->query( "ALTER TABLE `$table` ADD INDEX ( `$index` )" );
+
 	return true;
 }
 
 /**
- * Adds column to a database table if it doesn't already exist.
+ * Adds column to a database table, if it doesn't already exist.
  *
  * @since 1.3.0
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $table_name  The table name to modify.
- * @param string $column_name The column name to add to the table.
- * @param string $create_ddl  The SQL statement used to add the column.
- * @return bool True if already exists or on successful completion, false on error.
+ * @param string $table_name  Database table name.
+ * @param string $column_name Table column name.
+ * @param string $create_ddl  SQL statement to add column.
+ * @return bool True on success or if the column already exists. False on failure.
  */
 function maybe_add_column( $table_name, $column_name, $create_ddl ) {
 	global $wpdb;
+
 	foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
-		if ( $column == $column_name ) {
+		if ( $column === $column_name ) {
 			return true;
 		}
 	}
 
-	// Didn't find it try to create it.
+	// Didn't find it, so try to create it.
 	$wpdb->query( $create_ddl );
 
 	// We cannot directly tell that whether this succeeded!
 	foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) {
-		if ( $column == $column_name ) {
+		if ( $column === $column_name ) {
 			return true;
 		}
 	}
+
 	return false;
 }
 
@@ -2380,10 +2480,10 @@
  *
  * @since 4.2.0
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param string $table The table to convert.
- * @return bool true if the table was converted, false if it wasn't.
+ * @return bool True if the table was converted, false if it wasn't.
  */
 function maybe_convert_table_to_utf8mb4( $table ) {
 	global $wpdb;
@@ -2423,16 +2523,17 @@
  *
  * @since 1.2.0
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @return stdClass List of options.
  */
 function get_alloptions_110() {
 	global $wpdb;
 	$all_options = new stdClass;
-	if ( $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ) ) {
+	$options     = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
+	if ( $options ) {
 		foreach ( $options as $option ) {
-			if ( 'siteurl' == $option->option_name || 'home' == $option->option_name || 'category_base' == $option->option_name ) {
+			if ( 'siteurl' === $option->option_name || 'home' === $option->option_name || 'category_base' === $option->option_name ) {
 				$option->option_value = untrailingslashit( $option->option_value );
 			}
 			$all_options->{$option->option_name} = stripslashes( $option->option_value );
@@ -2448,29 +2549,29 @@
  * @since 1.5.1
  * @access private
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param string $setting Option name.
  * @return mixed
  */
-function __get_option( $setting ) {
+function __get_option( $setting ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
 	global $wpdb;
 
-	if ( $setting == 'home' && defined( 'WP_HOME' ) ) {
+	if ( 'home' === $setting && defined( 'WP_HOME' ) ) {
 		return untrailingslashit( WP_HOME );
 	}
 
-	if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) {
+	if ( 'siteurl' === $setting && defined( 'WP_SITEURL' ) ) {
 		return untrailingslashit( WP_SITEURL );
 	}
 
 	$option = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) );
 
-	if ( 'home' == $setting && '' == $option ) {
+	if ( 'home' === $setting && ! $option ) {
 		return __get_option( 'siteurl' );
 	}
 
-	if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting ) {
+	if ( in_array( $setting, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) {
 		$option = untrailingslashit( $option );
 	}
 
@@ -2513,7 +2614,7 @@
  *
  * @since 1.5.0
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param string[]|string $queries Optional. The query to run. Can be multiple queries
  *                                 in an array, or a string of queries separated by
@@ -2522,14 +2623,14 @@
  *                                 Default true.
  * @return array Strings containing the results of the various update queries.
  */
-function dbDelta( $queries = '', $execute = true ) {
+function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
 	global $wpdb;
 
 	if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) {
 		$queries = wp_get_db_schema( $queries );
 	}
 
-	// Separate individual queries into an array
+	// Separate individual queries into an array.
 	if ( ! is_array( $queries ) ) {
 		$queries = explode( ';', $queries );
 		$queries = array_filter( $queries );
@@ -2544,11 +2645,11 @@
 	 */
 	$queries = apply_filters( 'dbdelta_queries', $queries );
 
-	$cqueries   = array(); // Creation Queries
-	$iqueries   = array(); // Insertion Queries
+	$cqueries   = array(); // Creation queries.
+	$iqueries   = array(); // Insertion queries.
 	$for_update = array();
 
-	// Create a tablename index for an array ($cqueries) of queries
+	// Create a tablename index for an array ($cqueries) of queries.
 	foreach ( $queries as $qry ) {
 		if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
 			$cqueries[ trim( $matches[1], '`' ) ] = $qry;
@@ -2560,7 +2661,7 @@
 		} elseif ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
 			$iqueries[] = $qry;
 		} else {
-			// Unrecognized query type
+			// Unrecognized query type.
 		}
 	}
 
@@ -2592,12 +2693,12 @@
 	$global_tables = $wpdb->tables( 'global' );
 	foreach ( $cqueries as $table => $qry ) {
 		// Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
-		if ( in_array( $table, $global_tables ) && ! wp_should_upgrade_global_tables() ) {
+		if ( in_array( $table, $global_tables, true ) && ! wp_should_upgrade_global_tables() ) {
 			unset( $cqueries[ $table ], $for_update[ $table ] );
 			continue;
 		}
 
-		// Fetch the table column structure from the database
+		// Fetch the table column structure from the database.
 		$suppress    = $wpdb->suppress_errors();
 		$tablefields = $wpdb->get_results( "DESCRIBE {$table};" );
 		$wpdb->suppress_errors( $suppress );
@@ -2607,7 +2708,9 @@
 		}
 
 		// Clear the field and index arrays.
-		$cfields = $indices = $indices_without_subparts = array();
+		$cfields                  = array();
+		$indices                  = array();
+		$indices_without_subparts = array();
 
 		// Get all of the field names in the query from between the parentheses.
 		preg_match( '|\((.*)\)|ms', $qry, $match2 );
@@ -2682,7 +2785,8 @@
 					$index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . strtolower( $index_matches['index_name'] ) . '`';
 
 					// Parse the columns. Multiple columns are separated by a comma.
-					$index_columns = $index_columns_without_subparts = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) );
+					$index_columns                  = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) );
+					$index_columns_without_subparts = $index_columns;
 
 					// Normalize columns.
 					foreach ( $index_columns as $id => &$index_column ) {
@@ -2742,7 +2846,7 @@
 			$tablefield_field_lowercased = strtolower( $tablefield->Field );
 			$tablefield_type_lowercased  = strtolower( $tablefield->Type );
 
-			// If the table field exists in the field array ...
+			// If the table field exists in the field array...
 			if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
 
 				// Get the field type from the query.
@@ -2753,21 +2857,22 @@
 				// Is actual field type different from the field type in query?
 				if ( $tablefield->Type != $fieldtype ) {
 					$do_change = true;
-					if ( in_array( $fieldtype_lowercased, $text_fields ) && in_array( $tablefield_type_lowercased, $text_fields ) ) {
-						if ( array_search( $fieldtype_lowercased, $text_fields ) < array_search( $tablefield_type_lowercased, $text_fields ) ) {
+					if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
+						if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {
 							$do_change = false;
 						}
 					}
 
-					if ( in_array( $fieldtype_lowercased, $blob_fields ) && in_array( $tablefield_type_lowercased, $blob_fields ) ) {
-						if ( array_search( $fieldtype_lowercased, $blob_fields ) < array_search( $tablefield_type_lowercased, $blob_fields ) ) {
+					if ( in_array( $fieldtype_lowercased, $blob_fields, true ) && in_array( $tablefield_type_lowercased, $blob_fields, true ) ) {
+						if ( array_search( $fieldtype_lowercased, $blob_fields, true ) < array_search( $tablefield_type_lowercased, $blob_fields, true ) ) {
 							$do_change = false;
 						}
 					}
 
 					if ( $do_change ) {
 						// Add a query to change the column type.
-						$cqueries[]                                      = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
+						$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
+
 						$for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
 					}
 				}
@@ -2777,7 +2882,8 @@
 					$default_value = $matches[1];
 					if ( $tablefield->Default != $default_value ) {
 						// Add a query to change the column's default value
-						$cqueries[]                                      = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
+						$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
+
 						$for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
 					}
 				}
@@ -2792,7 +2898,8 @@
 		// For every remaining field specified for the table.
 		foreach ( $cfields as $fieldname => $fielddef ) {
 			// Push a query line into $cqueries that adds the field to that table.
-			$cqueries[]                              = "ALTER TABLE {$table} ADD COLUMN $fielddef";
+			$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
+
 			$for_update[ $table . '.' . $fieldname ] = 'Added column ' . $table . '.' . $fieldname;
 		}
 
@@ -2805,14 +2912,14 @@
 
 			// For every index in the table.
 			foreach ( $tableindices as $tableindex ) {
+				$keyname = strtolower( $tableindex->Key_name );
 
 				// Add the index to the index data array.
-				$keyname                             = strtolower( $tableindex->Key_name );
 				$index_ary[ $keyname ]['columns'][]  = array(
 					'fieldname' => $tableindex->Column_name,
 					'subpart'   => $tableindex->Sub_part,
 				);
-				$index_ary[ $keyname ]['unique']     = ( $tableindex->Non_unique == 0 ) ? true : false;
+				$index_ary[ $keyname ]['unique']     = ( 0 == $tableindex->Non_unique ) ? true : false;
 				$index_ary[ $keyname ]['index_type'] = $tableindex->Index_type;
 			}
 
@@ -2821,7 +2928,7 @@
 
 				// Build a create string to compare to the query.
 				$index_string = '';
-				if ( $index_name == 'primary' ) {
+				if ( 'primary' === $index_name ) {
 					$index_string .= 'PRIMARY ';
 				} elseif ( $index_data['unique'] ) {
 					$index_string .= 'UNIQUE ';
@@ -2840,7 +2947,7 @@
 
 				// For each column in the index.
 				foreach ( $index_data['columns'] as $column_data ) {
-					if ( $index_columns != '' ) {
+					if ( '' !== $index_columns ) {
 						$index_columns .= ',';
 					}
 
@@ -2852,7 +2959,8 @@
 				$index_string .= " ($index_columns)";
 
 				// Check if the index definition exists, ignoring subparts.
-				if ( ! ( ( $aindex = array_search( $index_string, $indices_without_subparts ) ) === false ) ) {
+				$aindex = array_search( $index_string, $indices_without_subparts, true );
+				if ( false !== $aindex ) {
 					// If the index already exists (even with different subparts), we don't need to create it.
 					unset( $indices_without_subparts[ $aindex ] );
 					unset( $indices[ $aindex ] );
@@ -2863,7 +2971,8 @@
 		// For every remaining index specified for the table.
 		foreach ( (array) $indices as $index ) {
 			// Push a query line into $cqueries that adds the index to that table.
-			$cqueries[]   = "ALTER TABLE {$table} ADD $index";
+			$cqueries[] = "ALTER TABLE {$table} ADD $index";
+
 			$for_update[] = 'Added index ' . $table . ' ' . $index;
 		}
 
@@ -2949,17 +3058,17 @@
 	);
 
 	foreach ( $files as $oldfile => $newfile ) {
-		if ( $oldfile == 'index.php' ) {
+		if ( 'index.php' === $oldfile ) {
 			$oldpath = $home_path;
 		} else {
 			$oldpath = ABSPATH;
 		}
 
 		// Check to make sure it's not a new index.
-		if ( $oldfile == 'index.php' ) {
+		if ( 'index.php' === $oldfile ) {
 			$index = implode( '', file( "$oldpath/$oldfile" ) );
 			if ( strpos( $index, 'WP_USE_THEMES' ) !== false ) {
-				if ( ! @copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) {
+				if ( ! copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) {
 					return false;
 				}
 
@@ -2968,7 +3077,7 @@
 			}
 		}
 
-		if ( ! @copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) {
+		if ( ! copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) {
 			return false;
 		}
 
@@ -3020,28 +3129,29 @@
  *
  * @param string $theme_name The name of the theme.
  * @param string $template   The directory name of the theme.
- * @return false|void
+ * @return void|false
  */
 function make_site_theme_from_default( $theme_name, $template ) {
 	$site_dir    = WP_CONTENT_DIR . "/themes/$template";
 	$default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
 
 	// Copy files from the default theme to the site theme.
-	//$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
-
-	$theme_dir = @ opendir( $default_dir );
+	// $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' );
+
+	$theme_dir = @opendir( $default_dir );
 	if ( $theme_dir ) {
 		while ( ( $theme_file = readdir( $theme_dir ) ) !== false ) {
 			if ( is_dir( "$default_dir/$theme_file" ) ) {
 				continue;
 			}
-			if ( ! @copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
+			if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
 				return;
 			}
 			chmod( "$site_dir/$theme_file", 0777 );
 		}
+
+		closedir( $theme_dir );
 	}
-	@closedir( $theme_dir );
 
 	// Rewrite the theme header.
 	$stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) );
@@ -3071,19 +3181,20 @@
 		return false;
 	}
 
-	$images_dir = @ opendir( "$default_dir/images" );
+	$images_dir = @opendir( "$default_dir/images" );
 	if ( $images_dir ) {
 		while ( ( $image = readdir( $images_dir ) ) !== false ) {
 			if ( is_dir( "$default_dir/images/$image" ) ) {
 				continue;
 			}
-			if ( ! @copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
+			if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
 				return;
 			}
 			chmod( "$site_dir/images/$image", 0777 );
 		}
+
+		closedir( $images_dir );
 	}
-	@closedir( $images_dir );
 }
 
 /**
@@ -3093,7 +3204,7 @@
  *
  * @since 1.5.0
  *
- * @return false|string
+ * @return string|false
  */
 function make_site_theme() {
 	// Name the theme after the blog.
@@ -3130,7 +3241,7 @@
 
 	// Make the new site theme active.
 	$current_template = __get_option( 'template' );
-	if ( $current_template == WP_DEFAULT_THEME ) {
+	if ( WP_DEFAULT_THEME == $current_template ) {
 		update_option( 'template', $template );
 		update_option( 'stylesheet', $template );
 	}
@@ -3162,6 +3273,7 @@
 		case 1:
 			return 'contributor';
 		case 0:
+		default:
 			return 'subscriber';
 	}
 }
@@ -3171,7 +3283,7 @@
  *
  * @since 2.1.0
  *
- * @global wpdb  $wpdb
+ * @global wpdb $wpdb WordPress database abstraction object.
  */
 function wp_check_mysql_version() {
 	global $wpdb;
@@ -3190,8 +3302,8 @@
 	$plugins = __get_option( 'active_plugins' );
 
 	foreach ( (array) $plugins as $plugin ) {
-		if ( basename( $plugin ) == 'widgets.php' ) {
-			array_splice( $plugins, array_search( $plugin, $plugins ), 1 );
+		if ( 'widgets.php' === basename( $plugin ) ) {
+			array_splice( $plugins, array_search( $plugin, $plugins, true ), 1 );
 			update_option( 'active_plugins', $plugins );
 			break;
 		}
@@ -3203,8 +3315,8 @@
  *
  * @since 3.5.0
  *
- * @global int  $wp_current_db_version
- * @global wpdb $wpdb WordPress database abstraction object.
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function maybe_disable_link_manager() {
 	global $wp_current_db_version, $wpdb;
@@ -3219,13 +3331,13 @@
  *
  * @since 2.9.0
  *
- * @global int  $wp_current_db_version
- * @global wpdb $wpdb WordPress database abstraction object.
+ * @global int  $wp_current_db_version The old (current) database version.
+ * @global wpdb $wpdb                  WordPress database abstraction object.
  */
 function pre_schema_upgrade() {
 	global $wp_current_db_version, $wpdb;
 
-	// Upgrade versions prior to 2.9
+	// Upgrade versions prior to 2.9.
 	if ( $wp_current_db_version < 11557 ) {
 		// Delete duplicate options. Keep the option with the highest option_id.
 		$wpdb->query( "DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id" );
@@ -3240,7 +3352,7 @@
 	// Multisite schema upgrades.
 	if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) {
 
-		// Upgrade versions prior to 3.7
+		// Upgrade versions prior to 3.7.
 		if ( $wp_current_db_version < 25179 ) {
 			// New primary key for signups.
 			$wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
@@ -3282,7 +3394,7 @@
 	 *
 	 * @since 3.0.0
 	 *
-	 * @global wpdb   $wpdb
+	 * @global wpdb   $wpdb            WordPress database abstraction object.
 	 * @global string $charset_collate
 	 */
 	function install_global_terms() {
@@ -3298,7 +3410,7 @@
   KEY last_updated (last_updated)
 ) $charset_collate;
 ";
-		// now create tables
+		// Now create tables.
 		dbDelta( $ms_queries );
 	}
 endif;
@@ -3323,20 +3435,20 @@
  */
 function wp_should_upgrade_global_tables() {
 
-	// Return false early if explicitly not upgrading
+	// Return false early if explicitly not upgrading.
 	if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
 		return false;
 	}
 
-	// Assume global tables should be upgraded
+	// Assume global tables should be upgraded.
 	$should_upgrade = true;
 
-	// Set to false if not on main network (does not matter if not multi-network)
+	// Set to false if not on main network (does not matter if not multi-network).
 	if ( ! is_main_network() ) {
 		$should_upgrade = false;
 	}
 
-	// Set to false if not on main site of current network (does not matter if not multi-site)
+	// Set to false if not on main site of current network (does not matter if not multi-site).
 	if ( ! is_main_site() ) {
 		$should_upgrade = false;
 	}