Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/update (meta type) metadata


This filter is applied before a metadata gets updated. For example if a user metadata gets updated the hook would be 'update_user_metadata'.

Return Parameter

The filter must return null if the data should be saved to the database. If it returns anything else, the update_metadata (and therefore the update_user_meta) function will return what the filter returns. See wp-includes/meta.php, line 122 for more information on this.


(null) (required) Always null
Default: None
(int) (required) ID of the object metadata is for
Default: None
(string) (required) Metadata key
Default: None
(mixed) (required) Metadata value. Must be serializable if non-scalar.
Default: None
(mixed) (required) The previous metadata value.
Default: None


function myplugin_init() {
	add_filter( 'update_user_metadata', 'myplugin_update_foo', 10, 5 );

function myplugin_update_foo( $null, $object_id, $meta_key, $meta_value, $prev_value ) {

	if ( 'foo' == $meta_key && empty( $meta_value ) ) {
		return true; // this means: stop saving the value into the database

	return null; // this means: go on with the normal execution in meta.php


add_action( 'init', 'myplugin_init' );

Change Log

Since: 3.1

Source File

The update_(meta_type)_metadata hook is located in wp-includes/meta.php, line 122


Action Hooks

See Also