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_metadataupdate_comment_metadataupdate_term_metadataupdate_user_metadata
Parameters
$checknull|bool- Whether to allow updating metadata for the given type.
$object_idint- ID of the object metadata is for.
$meta_keystring- Metadata key.
$meta_valuemixed- Metadata value. Must be serializable if non-scalar.
$prev_valuemixed- 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
footo 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 thefookey from the user’s metadata if the value is empty.