__return_false()
云策文档标注
概述
__return_false() 是 WordPress 核心函数,用于在过滤器(filter)中便捷地返回 false 值。它通常作为回调函数,简化代码编写。
关键要点
- 函数返回 false,用于过滤器回调,如 add_filter()
- 与 __return_true() 类似,但返回相反值
- 自 WordPress 3.0.0 版本引入,无参数
代码示例
// 在过滤器 example_filter 上添加返回 false 的回调
add_filter( 'example_filter', '__return_false' );// 禁用前端管理员工具栏
add_filter( 'show_admin_bar', '__return_false' );
原文内容
Returns false.
Description
Useful for returning false to filters easily.
See also
Source
function __return_false() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
return false;
}
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
Skip to note 3 content
Codex
Example
// This will add a filter on `example_filter` that returns false add_filter( 'example_filter', '__return_false' );Skip to note 4 content
Kónståntîn český คำถาม 問題和答案 Поделитьс
Used as a callback for a filter:
// Disable admin toolbar on frontend add_filter( 'show_admin_bar', '__return_false' );