pre_post_{$field}
云策文档标注
概述
pre_post_{$field} 是一个 WordPress 过滤器钩子,用于在保存前修改特定文章字段的值。它仅适用于以 post_ 为前缀的字段,动态部分 $field_no_prefix 指字段名去除前缀后的部分。
关键要点
- 钩子名称格式为 pre_post_{$field},其中 $field 是字段名(如 ID、comment_status 等)。
- 仅应用于以 post_ 为前缀的文章字段,例如 post_ID、post_comment_status。
- 参数 $value 是文章字段的当前值,可通过过滤器修改。
- 在 WordPress 2.3.0 版本中引入。
代码示例
$value = apply_filters( "pre_post_{$field}", $value );注意事项
此钩子与 sanitize_post_field() 函数相关,用于在特定上下文中清理文章字段。
原文内容
Filters the value of a specific field before saving.
Description
Only applied to post fields with a name which is prefixed with post_.
The dynamic portion of the hook name, $field_no_prefix, refers to the post field name minus the post_ prefix. Possible filter names include:
pre_post_IDpre_post_comment_statuspre_post_ping_statuspre_post_to_pingpre_post_pingedpre_post_guidpre_post_menu_orderpre_post_comment_count
Parameters
$valuemixed-
Value of the post field.
Source
$value = apply_filters( "pre_post_{$field}", $value );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |