{$field}_pre
云策文档标注
概述
此文档介绍 WordPress 中的 {$field}_pre 过滤器,用于在保存前修改特定文章字段的值。该过滤器仅适用于名称不以 post_ 为前缀的文章字段。
关键要点
- 过滤器名称是动态的,基于字段名,例如 ID_pre、comment_status_pre 等。
- 参数 $value 表示文章字段的当前值,可在过滤器中修改。
- 此过滤器在 sanitize_post_field() 函数中被调用,用于字段的清理过程。
代码示例
$value = apply_filters( "{$field}_pre", $value );注意事项
- 仅适用于非 post_ 前缀的字段,如 ID、guid 等。
- 自 WordPress 2.3.0 版本引入。
原文内容
Filters the value of a specific post field before saving.
Description
Only applied to post fields with a name which is not prefixed with post_.
The dynamic portion of the hook name, $field, refers to the post field name. Possible filter names include:
ID_precomment_status_preping_status_preto_ping_prepinged_preguid_premenu_order_precomment_count_pre
Parameters
$valuemixed-
Value of the post field.
Source
$value = apply_filters( "{$field}_pre", $value );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |