函数文档

wp_cache_switch_to_blog()

💡 云策文档标注

概述

wp_cache_switch_to_blog() 函数用于切换内部博客 ID,以改变在博客特定组中创建缓存键时使用的博客标识。此函数是 WordPress 对象缓存系统的一部分,主要面向多站点环境下的开发者。

关键要点

  • 函数作用:切换内部博客 ID,影响缓存键的生成。
  • 参数:$blog_id(整数,必需),指定要切换到的站点 ID。
  • 内部实现:调用 WP_Object_Cache::switch_to_blog() 方法。
  • 相关函数:与 switch_to_blog() 和 restore_current_blog() 配合使用,用于多站点博客切换。
  • 版本历史:自 WordPress 3.5.0 版本引入。

代码示例

function wp_cache_switch_to_blog( $blog_id ) {
    global $wp_object_cache;
    $wp_object_cache->switch_to_blog( $blog_id );
}

📄 原文内容

Switches the internal blog ID.

Description

This changes the blog id used to create keys in blog specific groups.

See also

Parameters

$blog_idintrequired
Site ID.

Source

function wp_cache_switch_to_blog( $blog_id ) {
	global $wp_object_cache;

	$wp_object_cache->switch_to_blog( $blog_id );
}

Changelog

Version Description
3.5.0 Introduced.