__return_zero()
云策文档标注
概述
__return_zero() 是一个 WordPress 核心函数,用于在过滤器中轻松返回整数值 0。它简化了代码,避免手动编写返回 0 的逻辑。
关键要点
- __return_zero() 返回整数 0,适用于需要返回 0 的过滤器场景。
- 该函数从 WordPress 3.0.0 版本开始引入,是核心函数的一部分。
- 使用示例:通过 add_filter 将 __return_zero 添加到过滤器,如 add_filter( 'example_filter', '__return_zero' )。
代码示例
add_filter( 'example_filter', '__return_zero' );
原文内容
Returns 0.
Description
Useful for returning 0 to filters easily.
Source
function __return_zero() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
return 0;
}
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
Skip to note 2 content
Codex
Add a filter on `example_filter` that returns 0.
add_filter( 'example_filter', '__return_zero' );