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?
    }
}
2
  • 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. Jul 8, 2014 at 17:33
  • I am trying to modify the return result of get_user_meta. How to do that?
    – manojadams
    Jul 8, 2014 at 19:34

1 Answer 1

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
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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