wp_interactivity_get_context()
云策文档标注
概述
wp_interactivity_get_context() 函数用于获取指定命名空间的当前 Interactivity API 上下文,主要在指令处理期间使用。如果省略命名空间参数,则使用内部命名空间栈的当前值。
关键要点
- 函数用途:获取 Interactivity API 的上下文,适用于特定命名空间。
- 使用时机:仅在指令处理过程中调用,确保上下文正确。
- 参数行为:$store_namespace 参数可选,默认为 null,省略时使用当前命名空间栈值。
- 返回值:返回指定命名空间的上下文数组,若命名空间未定义则返回空数组。
- 相关函数:与 wp_interactivity() 关联,用于获取 WP_Interactivity_API 实例。
- 版本历史:自 WordPress 6.6.0 版本引入。
代码示例
function wp_interactivity_get_context( ?string $store_namespace = null ): array {
return wp_interactivity()->get_context( $store_namespace );
}
原文内容
Gets the current Interactivity API context for a given namespace.
Description
The function should be used only during directive processing. If the $store_namespace parameter is omitted, it uses the current namespace value on the internal namespace stack.
It returns an empty array when the specified namespace is not defined.
Parameters
$store_namespacestringoptional-
The unique store namespace identifier.
Default:
null
Source
function wp_interactivity_get_context( ?string $store_namespace = null ): array {
return wp_interactivity()->get_context( $store_namespace );
}
Changelog
| Version | Description |
|---|---|
| 6.6.0 | Introduced. |