0

By default, get_user_meta returns an array, a single value or false. I want to change the return value somehow. How to do that?

I want to modify the return type of a template tag get_user_meta inside the class only. How to do this? I am trying this:-

class modifyUserMeta {
    function modifyUserMeta(){
        add_filter('get_user_meta',$this->modifyMeta);
    }
    function modifyMeta(){
    //how can i modify the return type of get_user_meta?
    }
}
  • 1
    You need to add a little more detail. It is hard to know what you are asking or what you are trying to do. – helgatheviking Jul 8 '14 at 17:33
  • I am trying to modify the return result of get_user_meta. How to do that? – manoj Jul 8 '14 at 19:34
1

There is no get_user_meta filter. Despite WP often having filters same as function name, it isn't the rule exactly.

There is however deeper filter in more generic get_metadata() function:

$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );

if ( null !== $check ) {
    if ( $single && is_array( $check ) )
        return $check[0];
    else
        return $check;
}

Also your PHP is a mess with callback there. All together:

class modifyUserMeta {

    function modifyUserMeta(){

        add_filter('get_user_metadata', array($this, modifyMeta), 10, 4 );
    }

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

        // check ID, key, and format then return accordingly
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.