pre_{$field}
云策文档标注
概述
pre_{$field} 是一个 WordPress 过滤器钩子,用于在保存前修改特定文章字段的值。它仅适用于以 post_ 为前缀的字段名,动态部分 $field 代表字段名称。
关键要点
- 过滤器名称格式为 pre_{$field},其中 $field 是文章字段名,例如 pre_post_title、pre_post_content 等。
- 仅应用于以 post_ 为前缀的字段,如 post_author、post_date 等。
- 参数 $value 是文章字段的原始值,过滤器可以修改并返回新值。
- 在 WordPress 2.3.0 版本中引入。
代码示例
$value = apply_filters( "pre_{$field}", $value );注意事项
- 相关函数包括 sanitize_post_field()、sanitize_user_field() 和 sanitize_bookmark_field(),用于基于上下文清理字段。
原文内容
Filters the value of a specific post 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, refers to the post field name. Possible filter names include:
pre_post_authorpre_post_datepre_post_date_gmtpre_post_contentpre_post_titlepre_post_excerptpre_post_statuspre_post_passwordpre_post_namepre_post_modifiedpre_post_modified_gmtpre_post_content_filteredpre_post_parentpre_post_typepre_post_mime_type
Parameters
$valuemixed-
Value of the post field.
Source
$value = apply_filters( "pre_{$field}", $value );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |