add_{$meta_type}_metadata
云策文档标注
概述
add_{$meta_type}_metadata 是一个 WordPress 过滤器钩子,用于在添加特定类型元数据时进行短路操作。它允许开发者通过返回非空值来中断默认的元数据添加流程。
关键要点
- 钩子名称是动态的,基于 $meta_type(如 blog、post、comment、term、user 等),例如 add_post_metadata。
- 返回 false 或一个元数据 ID 可以短路函数,返回 null 则继续默认行为。
- 参数包括 $check(控制是否允许添加)、$object_id(对象 ID)、$meta_key(元数据键)、$meta_value(元数据值,可序列化)和 $unique(是否唯一键)。
- 在 add_metadata() 函数中使用,自 WordPress 3.1.0 版本引入。
原文内容
Short-circuits adding metadata of a specific type.
Description
The dynamic portion of the hook name, $meta_type, refers to the meta object type (blog, post, comment, term, user, or any other type with an associated meta table).
Returning a non-null value will effectively short-circuit the function.
Possible hook names include:
add_blog_metadataadd_post_metadataadd_comment_metadataadd_term_metadataadd_user_metadata
Parameters
$checknull|int|false-
Whether to allow adding metadata for the given type. Return false or a meta ID to short-circuit the function. Return null to continue with the default behavior.
$object_idint-
ID of the object metadata is for.
$meta_keystring-
Metadata key.
$meta_valuemixed-
Metadata value. Must be serializable if non-scalar.
$uniquebool-
Whether the specified meta key should be unique for the object.
Source
$check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |