WordPress.org

Codex

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

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

Description

This filter is applied before a metadata is returned. For example if a user metadata gets requested the hook would be 'get_user_metadata'.

Return Parameter

The filter must return null if the data should be taken from the database. If it returns anything else, the get_metadata (and therefore the get_user_meta) function will return what the filter returns.

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
$single
(bool) (required) If true the filter should return the value of the metadata field, if false return an array
Default: None

Example

function myplugin_init() {
	add_filter( 'get_user_metadata', 'myplugin_get_foo', 10, 4 );
}

function myplugin_get_foo( $null, $object_id, $meta_key, $single ) {

	if ( 'foo' == $meta_key ) {
		// Always return an array with your return value. There is no need to check $single. This logic is handled in wp-includes/meta.php
		return array( 'bar' );
	}

	return null; // Go on with the normal execution in meta.php

}

add_action( 'init', 'myplugin_init' );

Change Log

Since: 3.1

Source File

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

See Also

Plugin_API/Filter_Reference