edit_{$field}
云策文档标注
概述
edit_{$field} 是一个 WordPress 过滤器钩子,用于在编辑特定文章字段时过滤其值。它允许开发者自定义文章字段的编辑值处理。
关键要点
- 钩子名称是动态的,$field 部分对应文章字段名,如 edit_post_author、edit_post_content 等。
- 参数包括 $value(字段值)和 $post_id(文章 ID),用于在过滤器中修改或验证字段值。
- 常用于 sanitize_post_field() 等函数中,确保字段值在编辑上下文中安全处理。
代码示例
$value = apply_filters( "edit_{$field}", $value, $post_id );注意事项
- 此钩子自 WordPress 2.3.0 版本引入,使用时需注意版本兼容性。
- 相关函数如 sanitize_user_field() 和 sanitize_bookmark_field() 也使用类似机制,可参考其实现。
原文内容
Filters the value of a specific post field to edit.
Description
The dynamic portion of the hook name, $field, refers to the post field name. Possible filter names include:
edit_post_authoredit_post_dateedit_post_date_gmtedit_post_contentedit_post_titleedit_post_excerptedit_post_statusedit_post_passwordedit_post_nameedit_post_modifiededit_post_modified_gmtedit_post_content_filterededit_post_parentedit_post_typeedit_post_mime_type
Parameters
$valuemixed-
Value of the post field.
$post_idint-
Post ID.
Source
$value = apply_filters( "edit_{$field}", $value, $post_id );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |