wp/wp-includes/ms-site.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
--- a/wp/wp-includes/ms-site.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/ms-site.php	Fri Sep 05 18:40:08 2025 +0200
@@ -114,8 +114,10 @@
 			$meta['WPLANG'] = get_network_option( $new_site->network_id, 'WPLANG' );
 		}
 
-		// Rebuild the data expected by the `wpmu_new_blog` hook prior to 5.1.0 using allowed keys.
-		// The `$allowed_data_fields` matches the one used in `wpmu_create_blog()`.
+		/*
+		 * Rebuild the data expected by the `wpmu_new_blog` hook prior to 5.1.0 using allowed keys.
+		 * The `$allowed_data_fields` matches the one used in `wpmu_create_blog()`.
+		 */
 		$allowed_data_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
 		$meta                = array_merge( array_intersect_key( $data, array_flip( $allowed_data_fields ) ), $meta );
 
@@ -339,7 +341,8 @@
  *
  * @since 4.6.0
  * @since 5.1.0 Introduced the `$update_meta_cache` parameter.
- * @access private
+ * @since 6.1.0 This function is no longer marked as "private".
+ * @since 6.3.0 Use wp_lazyload_site_meta() for lazy-loading of site meta.
  *
  * @see update_site_cache()
  * @global wpdb $wpdb WordPress database abstraction object.
@@ -354,11 +357,30 @@
 	if ( ! empty( $non_cached_ids ) ) {
 		$fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
 
-		update_site_cache( $fresh_sites, $update_meta_cache );
+		update_site_cache( $fresh_sites, false );
+	}
+
+	if ( $update_meta_cache ) {
+		wp_lazyload_site_meta( $ids );
 	}
 }
 
 /**
+ * Queue site meta for lazy-loading.
+ *
+ * @since 6.3.0
+ *
+ * @param array $site_ids List of site IDs.
+ */
+function wp_lazyload_site_meta( array $site_ids ) {
+	if ( empty( $site_ids ) ) {
+		return;
+	}
+	$lazyloader = wp_metadata_lazyloader();
+	$lazyloader->queue_objects( 'blog', $site_ids );
+}
+
+/**
  * Updates sites in cache.
  *
  * @since 4.6.0
@@ -502,11 +524,7 @@
 function wp_normalize_site_data( $data ) {
 	// Sanitize domain if passed.
 	if ( array_key_exists( 'domain', $data ) ) {
-		$data['domain'] = trim( $data['domain'] );
-		$data['domain'] = preg_replace( '/\s+/', '', sanitize_user( $data['domain'], true ) );
-		if ( is_subdomain_install() ) {
-			$data['domain'] = str_replace( '@', '', $data['domain'] );
-		}
+		$data['domain'] = preg_replace( '/[^a-z0-9\-.:]+/i', '', $data['domain'] );
 	}
 
 	// Sanitize path if passed.
@@ -822,7 +840,7 @@
 	 *
 	 * @since MU (3.0.0)
 	 *
-	 * @param string $basedir Uploads path without subdirectory. @see wp_upload_dir()
+	 * @param string $basedir Uploads path without subdirectory. See {@see wp_upload_dir()}.
 	 * @param int    $site_id The site ID.
 	 */
 	$dir     = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $site->id );
@@ -855,12 +873,12 @@
 			}
 			@closedir( $dh );
 		}
-		$index++;
+		++$index;
 	}
 
 	$stack = array_reverse( $stack ); // Last added directories are deepest.
 	foreach ( (array) $stack as $dir ) {
-		if ( $dir != $top_dir ) {
+		if ( $dir !== $top_dir ) {
 			@rmdir( $dir );
 		}
 	}
@@ -988,7 +1006,7 @@
 	 */
 	do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key );
 
-	wp_cache_set( 'last_changed', microtime(), 'sites' );
+	wp_cache_set_sites_last_changed();
 
 	/**
 	 * Fires after the blog details cache is cleared.
@@ -1108,7 +1126,7 @@
 		return;
 	}
 
-	if ( $new_site->network_id != $old_site->network_id ) {
+	if ( $new_site->network_id !== $old_site->network_id ) {
 		wp_maybe_update_network_site_counts( $new_site->network_id );
 		wp_maybe_update_network_site_counts( $old_site->network_id );
 	}
@@ -1131,8 +1149,8 @@
 		$old_site = new WP_Site( new stdClass() );
 	}
 
-	if ( $new_site->spam != $old_site->spam ) {
-		if ( 1 == $new_site->spam ) {
+	if ( $new_site->spam !== $old_site->spam ) {
+		if ( '1' === $new_site->spam ) {
 
 			/**
 			 * Fires when the 'spam' status is added to a site.
@@ -1155,8 +1173,8 @@
 		}
 	}
 
-	if ( $new_site->mature != $old_site->mature ) {
-		if ( 1 == $new_site->mature ) {
+	if ( $new_site->mature !== $old_site->mature ) {
+		if ( '1' === $new_site->mature ) {
 
 			/**
 			 * Fires when the 'mature' status is added to a site.
@@ -1179,8 +1197,8 @@
 		}
 	}
 
-	if ( $new_site->archived != $old_site->archived ) {
-		if ( 1 == $new_site->archived ) {
+	if ( $new_site->archived !== $old_site->archived ) {
+		if ( '1' === $new_site->archived ) {
 
 			/**
 			 * Fires when the 'archived' status is added to a site.
@@ -1203,8 +1221,8 @@
 		}
 	}
 
-	if ( $new_site->deleted != $old_site->deleted ) {
-		if ( 1 == $new_site->deleted ) {
+	if ( $new_site->deleted !== $old_site->deleted ) {
+		if ( '1' === $new_site->deleted ) {
 
 			/**
 			 * Fires when the 'deleted' status is added to a site.
@@ -1227,15 +1245,16 @@
 		}
 	}
 
-	if ( $new_site->public != $old_site->public ) {
+	if ( $new_site->public !== $old_site->public ) {
 
 		/**
 		 * Fires after the current blog's 'public' setting is updated.
 		 *
 		 * @since MU (3.0.0)
 		 *
-		 * @param int    $site_id Site ID.
-		 * @param string $value   The value of the site status.
+		 * @param int    $site_id   Site ID.
+		 * @param string $is_public Whether the site is public. A numeric string,
+		 *                          for compatibility reasons. Accepts '1' or '0'.
 		 */
 		do_action( 'update_blog_public', $site_id, $new_site->public );
 	}
@@ -1247,7 +1266,7 @@
  * @since 5.1.0
  *
  * @param WP_Site $new_site The site object after the update.
- * @param WP_Site $old_site The site obejct prior to the update.
+ * @param WP_Site $old_site The site object prior to the update.
  */
 function wp_maybe_clean_new_site_cache_on_update( $new_site, $old_site ) {
 	if ( $old_site->domain !== $new_site->domain || $old_site->path !== $new_site->path ) {
@@ -1260,17 +1279,18 @@
  *
  * @since 5.1.0
  *
- * @param int    $site_id Site ID.
- * @param string $public  The value of the site status.
+ * @param int    $site_id   Site ID.
+ * @param string $is_public Whether the site is public. A numeric string,
+ *                          for compatibility reasons. Accepts '1' or '0'.
  */
-function wp_update_blog_public_option_on_site_update( $site_id, $public ) {
+function wp_update_blog_public_option_on_site_update( $site_id, $is_public ) {
 
 	// Bail if the site's database tables do not exist (yet).
 	if ( ! wp_is_site_initialized( $site_id ) ) {
 		return;
 	}
 
-	update_blog_option( $site_id, 'blog_public', $public );
+	update_blog_option( $site_id, 'blog_public', $is_public );
 }
 
 /**
@@ -1279,7 +1299,7 @@
  * @since 5.1.0
  */
 function wp_cache_set_sites_last_changed() {
-	wp_cache_set( 'last_changed', microtime(), 'sites' );
+	wp_cache_set_last_changed( 'sites' );
 }
 
 /**