钩子文档

site_transient_{$transient}

💡 云策文档标注

概述

site_transient_{$transient} 是一个 WordPress 过滤器钩子,用于修改现有站点瞬态(site transient)的值。它允许开发者在获取站点瞬态时动态过滤其内容。

关键要点

  • 这是一个动态钩子,$transient 部分代表瞬态名称,例如 site_transient_my_transient。
  • 参数包括 $value(站点瞬态的当前值)和 $transient(瞬态名称字符串)。
  • 主要用于 get_site_transient() 函数中,以在返回前修改瞬态值。
  • 自 WordPress 4.4.0 起添加了 $transient 参数,便于在过滤器中识别具体瞬态。

代码示例

return apply_filters( "site_transient_{$transient}", $value, $transient );

📄 原文内容

Filters the value of an existing site transient.

Description

The dynamic portion of the hook name, $transient, refers to the transient name.

Parameters

$valuemixed
Value of site transient.
$transientstring
Transient name.

Source

return apply_filters( "site_transient_{$transient}", $value, $transient );

Changelog

Version Description
4.4.0 The $transient parameter was added.
2.9.0 Introduced.