The delete_{$meta_type}_metadata
dynamic filter effectively allows you to prevent certain meta data from being deleted. The dynamic $meta_type
variable accepts ‘user’, ‘comment’, or ‘post’.
It is evaluated in delete_metadata()
in the wp-includes/meta.php file.
delete_{$meta_type}_metadata
accepts 5 arguments:
- bool
null
If anything other than null is returned,delete_metadata()
will short-circuit and return the boolean equivalent of that value. Default return fordelete_metadata()
is true on successful delete, false on failure - int
$object_id
The user, comment or post object id - string
$meta_key
The meta key to delete - string
$meta_value
The meta value to delete - bool
$delete_all
Whether to ignore$object_id
further down indelete_metadata()
. Default is false
Example:
Let’s say you want to keep non-admin users from deleting featured images once they’re set (for some reason). The following uses the dynamic delete_post_metadata
hook accomplish this.
View the code example on Gist.