Short-circuits updating metadata of a specific type.
Description
The dynamic portion of the hook name, $meta_type
, refers to the meta object type (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:
update_post_metadata
update_comment_metadata
update_term_metadata
update_user_metadata
Parameters
$check
null|bool- Whether to allow updating metadata for the given type.
$object_id
int- ID of the object metadata is for.
$meta_key
string- Metadata key.
$meta_value
mixed- Metadata value. Must be serializable if non-scalar.
$prev_value
mixed- Previous value to check before updating.
If specified, only update existing metadata entries with this value. Otherwise, update all entries.
Source
$check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
Example migrated from Codex:
The example below skips saving the metadata with the key ‘foo’ and an empty value. For other metadata, continue the normal execution.
Similar to stevenlinx’s example, to skip saving empty value of
foo
to user metadata. Note that this could create problems if the user is attempting to clear previously entered data; an additional hook should be included that deletes thefoo
key from the user’s metadata if the value is empty.