WordPress.org

Ready to get started?Download WordPress

Codex

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

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

Description

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.

Parameters

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

Example


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' );

Source File

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

Related

Action Hooks

See Also

Plugin_API/Filter_Reference