This filter is applied before a metadata is returned. For example if a user metadata gets requested the hook would be 'get_user_metadata'.
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.
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' );
Since: 3.1
The get_(meta_type)_metadata hook is located in wp-includes/meta.php
, line 485