wp/wp-includes/ms-blogs.php
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
child 22 8c2e4d02f4ef
--- a/wp/wp-includes/ms-blogs.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/ms-blogs.php	Fri Sep 05 18:40:08 2025 +0200
@@ -12,7 +12,7 @@
 require_once ABSPATH . WPINC . '/ms-network.php';
 
 /**
- * Update the last_updated field for the current site.
+ * Updates the last_updated field for the current site.
  *
  * @since MU (3.0.0)
  */
@@ -31,12 +31,12 @@
 }
 
 /**
- * Get a full blog URL, given a blog ID.
+ * Gets a full site URL, given a site ID.
  *
  * @since MU (3.0.0)
  *
- * @param int $blog_id Blog ID.
- * @return string Full URL of the blog if found. Empty string if not.
+ * @param int $blog_id Site ID.
+ * @return string Full site URL if found. Empty string if not.
  */
 function get_blogaddress_by_id( $blog_id ) {
 	$bloginfo = get_site( (int) $blog_id );
@@ -52,11 +52,11 @@
 }
 
 /**
- * Get a full blog URL, given a blog name.
+ * Gets a full site URL, given a site name.
  *
  * @since MU (3.0.0)
  *
- * @param string $blogname The (subdomain or directory) name
+ * @param string $blogname Name of the subdomain or directory.
  * @return string
  */
 function get_blogaddress_by_name( $blogname ) {
@@ -75,7 +75,7 @@
 }
 
 /**
- * Retrieves a sites ID given its (subdomain or directory) slug.
+ * Retrieves a site's ID given its (subdomain or directory) slug.
  *
  * @since MU (3.0.0)
  * @since 4.7.0 Converted to use `get_sites()`.
@@ -113,14 +113,14 @@
 }
 
 /**
- * Retrieve the details for a blog from the blogs table and blog options.
+ * Retrieves the details for a blog from the blogs table and blog options.
  *
  * @since MU (3.0.0)
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param int|string|array $fields  Optional. A blog ID, a blog slug, or an array of fields to query against.
- *                                  If not specified the current blog ID is used.
+ *                                  Defaults to the current blog ID.
  * @param bool             $get_all Whether to retrieve all details or only the details in the blogs table.
  *                                  Default is true.
  * @return WP_Site|false Blog details on success. False on failure.
@@ -137,7 +137,7 @@
 			if ( false !== $blog ) {
 				return $blog;
 			}
-			if ( 'www.' === substr( $fields['domain'], 0, 4 ) ) {
+			if ( str_starts_with( $fields['domain'], 'www.' ) ) {
 				$nowww = substr( $fields['domain'], 4 );
 				$blog  = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
 			} else {
@@ -155,7 +155,7 @@
 			if ( false !== $blog ) {
 				return $blog;
 			}
-			if ( 'www.' === substr( $fields['domain'], 0, 4 ) ) {
+			if ( str_starts_with( $fields['domain'], 'www.' ) ) {
 				$nowww = substr( $fields['domain'], 4 );
 				$blog  = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
 			} else {
@@ -187,7 +187,7 @@
 
 	if ( $details ) {
 		if ( ! is_object( $details ) ) {
-			if ( -1 == $details ) {
+			if ( -1 === $details ) {
 				return false;
 			} else {
 				// Clear old pre-serialized objects. Cache clients do better with that.
@@ -207,7 +207,7 @@
 		// If short was requested and full cache is set, we can return.
 		if ( $details ) {
 			if ( ! is_object( $details ) ) {
-				if ( -1 == $details ) {
+				if ( -1 === $details ) {
 					return false;
 				} else {
 					// Clear old pre-serialized objects. Cache clients do better with that.
@@ -273,7 +273,7 @@
 }
 
 /**
- * Clear the blog details cache.
+ * Clears the blog details cache.
  *
  * @since MU (3.0.0)
  *
@@ -289,19 +289,15 @@
 }
 
 /**
- * Update the details for a blog. Updates the blogs table for a given blog ID.
+ * Updates the details for a blog and the blogs table for a given blog ID.
  *
  * @since MU (3.0.0)
  *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
  * @param int   $blog_id Blog ID.
  * @param array $details Array of details keyed by blogs table field names.
  * @return bool True if update succeeds, false otherwise.
  */
 function update_blog_details( $blog_id, $details = array() ) {
-	global $wpdb;
-
 	if ( empty( $details ) ) {
 		return false;
 	}
@@ -337,7 +333,7 @@
 }
 
 /**
- * Retrieve option value for a given blog id based on name of option.
+ * Retrieves option value for a given blog id based on name of option.
  *
  * If the option does not exist or does not have a value, then the return value
  * will be false. This is useful to check whether you need to install an option
@@ -348,24 +344,24 @@
  *
  * @since MU (3.0.0)
  *
- * @param int    $id      A blog ID. Can be null to refer to the current blog.
- * @param string $option  Name of option to retrieve. Expected to not be SQL-escaped.
- * @param mixed  $default Optional. Default value to return if the option does not exist.
+ * @param int    $id            A blog ID. Can be null to refer to the current blog.
+ * @param string $option        Name of option to retrieve. Expected to not be SQL-escaped.
+ * @param mixed  $default_value Optional. Default value to return if the option does not exist.
  * @return mixed Value set for the option.
  */
-function get_blog_option( $id, $option, $default = false ) {
+function get_blog_option( $id, $option, $default_value = false ) {
 	$id = (int) $id;
 
 	if ( empty( $id ) ) {
 		$id = get_current_blog_id();
 	}
 
-	if ( get_current_blog_id() == $id ) {
-		return get_option( $option, $default );
+	if ( get_current_blog_id() === $id ) {
+		return get_option( $option, $default_value );
 	}
 
 	switch_to_blog( $id );
-	$value = get_option( $option, $default );
+	$value = get_option( $option, $default_value );
 	restore_current_blog();
 
 	/**
@@ -382,7 +378,7 @@
 }
 
 /**
- * Add a new option for a given blog ID.
+ * Adds a new option for a given blog ID.
  *
  * You do not need to serialize values. If the value needs to be serialized, then
  * it will be serialized before it is inserted into the database. Remember,
@@ -397,7 +393,7 @@
  *
  * @param int    $id     A blog ID. Can be null to refer to the current blog.
  * @param string $option Name of option to add. Expected to not be SQL-escaped.
- * @param mixed  $value  Optional. Option value, can be anything. Expected to not be SQL-escaped.
+ * @param mixed  $value  Option value, can be anything. Expected to not be SQL-escaped.
  * @return bool True if the option was added, false otherwise.
  */
 function add_blog_option( $id, $option, $value ) {
@@ -407,7 +403,7 @@
 		$id = get_current_blog_id();
 	}
 
-	if ( get_current_blog_id() == $id ) {
+	if ( get_current_blog_id() === $id ) {
 		return add_option( $option, $value );
 	}
 
@@ -419,7 +415,7 @@
 }
 
 /**
- * Removes option by name for a given blog ID. Prevents removal of protected WordPress options.
+ * Removes an option by name for a given blog ID. Prevents removal of protected WordPress options.
  *
  * @since MU (3.0.0)
  *
@@ -434,7 +430,7 @@
 		$id = get_current_blog_id();
 	}
 
-	if ( get_current_blog_id() == $id ) {
+	if ( get_current_blog_id() === $id ) {
 		return delete_option( $option );
 	}
 
@@ -446,7 +442,7 @@
 }
 
 /**
- * Update an option for a particular blog.
+ * Updates an option for a particular blog.
  *
  * @since MU (3.0.0)
  *
@@ -463,7 +459,7 @@
 		_deprecated_argument( __FUNCTION__, '3.1.0' );
 	}
 
-	if ( get_current_blog_id() == $id ) {
+	if ( get_current_blog_id() === $id ) {
 		return update_option( $option, $value );
 	}
 
@@ -475,13 +471,12 @@
 }
 
 /**
- * Switch the current blog.
+ * Switches the current blog.
  *
  * This function is useful if you need to pull posts, or other information,
  * from other blogs. You can switch back afterwards using restore_current_blog().
  *
- * Things that aren't switched:
- *  - plugins. See #14941
+ * PHP code loaded with the originally requested site, such as code from a plugin or theme, does not switch. See #14941.
  *
  * @see restore_current_blog()
  * @since MU (3.0.0)
@@ -490,7 +485,7 @@
  * @global int             $blog_id
  * @global array           $_wp_switched_stack
  * @global bool            $switched
- * @global string          $table_prefix
+ * @global string          $table_prefix       The database table prefix.
  * @global WP_Object_Cache $wp_object_cache
  *
  * @param int  $new_blog_id The ID of the blog to switch to. Default: current blog.
@@ -512,7 +507,7 @@
 	 * set the right vars, do the associated actions, but skip
 	 * the extra unnecessary work
 	 */
-	if ( $new_blog_id == $prev_blog_id ) {
+	if ( $new_blog_id === $prev_blog_id ) {
 		/**
 		 * Fires when the blog is switched.
 		 *
@@ -552,10 +547,33 @@
 			if ( is_array( $global_groups ) ) {
 				wp_cache_add_global_groups( $global_groups );
 			} else {
-				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
+				wp_cache_add_global_groups(
+					array(
+						'blog-details',
+						'blog-id-cache',
+						'blog-lookup',
+						'blog_meta',
+						'global-posts',
+						'networks',
+						'network-queries',
+						'sites',
+						'site-details',
+						'site-options',
+						'site-queries',
+						'site-transient',
+						'theme_files',
+						'rss',
+						'users',
+						'user-queries',
+						'user_meta',
+						'useremail',
+						'userlogins',
+						'userslugs',
+					)
+				);
 			}
 
-			wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
+			wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) );
 		}
 	}
 
@@ -568,7 +586,7 @@
 }
 
 /**
- * Restore the current blog, after calling switch_to_blog().
+ * Restores the current blog, after calling switch_to_blog().
  *
  * @see switch_to_blog()
  * @since MU (3.0.0)
@@ -577,7 +595,7 @@
  * @global array           $_wp_switched_stack
  * @global int             $blog_id
  * @global bool            $switched
- * @global string          $table_prefix
+ * @global string          $table_prefix       The database table prefix.
  * @global WP_Object_Cache $wp_object_cache
  *
  * @return bool True on success, false if we're already on the current blog.
@@ -592,7 +610,7 @@
 	$new_blog_id  = array_pop( $GLOBALS['_wp_switched_stack'] );
 	$prev_blog_id = get_current_blog_id();
 
-	if ( $new_blog_id == $prev_blog_id ) {
+	if ( $new_blog_id === $prev_blog_id ) {
 		/** This filter is documented in wp-includes/ms-blogs.php */
 		do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' );
 
@@ -623,10 +641,33 @@
 			if ( is_array( $global_groups ) ) {
 				wp_cache_add_global_groups( $global_groups );
 			} else {
-				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
+				wp_cache_add_global_groups(
+					array(
+						'blog-details',
+						'blog-id-cache',
+						'blog-lookup',
+						'blog_meta',
+						'global-posts',
+						'networks',
+						'network-queries',
+						'sites',
+						'site-details',
+						'site-options',
+						'site-queries',
+						'site-transient',
+						'theme_files',
+						'rss',
+						'users',
+						'user-queries',
+						'user_meta',
+						'useremail',
+						'userlogins',
+						'userslugs',
+					)
+				);
 			}
 
-			wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
+			wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) );
 		}
 	}
 
@@ -648,7 +689,7 @@
  * @param int $old_site_id Old site ID.
  */
 function wp_switch_roles_and_user( $new_site_id, $old_site_id ) {
-	if ( $new_site_id == $old_site_id ) {
+	if ( $new_site_id === $old_site_id ) {
 		return;
 	}
 
@@ -661,7 +702,7 @@
 }
 
 /**
- * Determines if switch_to_blog() is in effect
+ * Determines if switch_to_blog() is in effect.
  *
  * @since 3.5.0
  *
@@ -674,7 +715,7 @@
 }
 
 /**
- * Check if a particular blog is archived.
+ * Checks if a particular blog is archived.
  *
  * @since MU (3.0.0)
  *
@@ -686,7 +727,7 @@
 }
 
 /**
- * Update the 'archived' status of a particular blog.
+ * Updates the 'archived' status of a particular blog.
  *
  * @since MU (3.0.0)
  *
@@ -700,7 +741,7 @@
 }
 
 /**
- * Update a blog details field.
+ * Updates a blog details field.
  *
  * @since MU (3.0.0)
  * @since 5.1.0 Use wp_update_site() internally.
@@ -741,7 +782,7 @@
 }
 
 /**
- * Get a blog details field.
+ * Gets a blog details field.
  *
  * @since MU (3.0.0)
  *
@@ -763,7 +804,7 @@
 }
 
 /**
- * Get a list of most recently updated blogs.
+ * Gets a list of most recently updated blogs.
  *
  * @since MU (3.0.0)
  *
@@ -837,12 +878,12 @@
  * Handler for updating the current site's posts count when a post is deleted.
  *
  * @since 4.0.0
+ * @since 6.2.0 Added the `$post` parameter.
  *
- * @param int $post_id Post ID.
+ * @param int     $post_id Post ID.
+ * @param WP_Post $post    Post object.
  */
-function _update_posts_count_on_delete( $post_id ) {
-	$post = get_post( $post_id );
-
+function _update_posts_count_on_delete( $post_id, $post ) {
 	if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) {
 		return;
 	}
@@ -877,7 +918,7 @@
 }
 
 /**
- * Count number of sites grouped by site status.
+ * Counts number of sites grouped by site status.
  *
  * @since 5.3.0
  *