最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Passing the custom field values in the wp_get_current_user array function

programmeradmin0浏览0评论

How to pass the custom field values which were stored while creating a new user into the wp_get_current_user array function

When I call the wp_get_current_user() function the result which I found is as follows:

WP_User Object
(
    [data] => stdClass Object
        (
            [ID] => 20
            [user_login] => testing
            [user_pass] => $P$BAfSwYFZEUKIkQyF30Eq7GN3HOUXFW/
            [user_nicename] => testing
            [user_email] => [email protected]
            [user_url] => 
            [user_registered] => 2015-12-15 07:11:35
            [user_activation_key] => 1450163495:$P$Br7QHNREuY.esEZdB3c92fK2CrW9QH.
            [user_status] => 0
            [display_name] => testing testing
            [token_key] => 
        )

    [ID] => 20
    [caps] => Array
        (
            [subscriber] => 1
        )

    [cap_key] => wp_capabilities
    [roles] => Array
        (
            [0] => subscriber
        )

    [allcaps] => Array
        (
            [read] => 1
            [level_0] => 1
            [subscriber] => 1
        )

    [filter] => 
)

But I want the answer to be as

WP_User Object
    (
        [data] => stdClass Object
            (
                [ID] => 20
                [user_login] => testing
                [user_pass] => $P$BAfSwYFZEUKIkQyF30Eq7GN3HOUXFW/
                [user_nicename] => testing
                [user_email] => [email protected]
                [user_url] => 
                [user_registered] => 2015-12-15 07:11:35
                [user_activation_key] => 1450163495:$P$Br7QHNREuY.esEZdB3c92fK2CrW9QH.
                [user_status] => 0
                [display_name] => testing testing
                [token_key] => 
                [client] => abc
                [user_groups] => test
            )

        [ID] => 20
        [caps] => Array
            (
                [subscriber] => 1
            )

        [cap_key] => wp_capabilities
        [roles] => Array
            (
                [0] => subscriber
            )

        [allcaps] => Array
            (
                [read] => 1
                [level_0] => 1
                [subscriber] => 1
            )

        [filter] => 
    )

Compare the [data] part of both the array

How do I achieve this?

Thanks for the help in advance

How to pass the custom field values which were stored while creating a new user into the wp_get_current_user array function

When I call the wp_get_current_user() function the result which I found is as follows:

WP_User Object
(
    [data] => stdClass Object
        (
            [ID] => 20
            [user_login] => testing
            [user_pass] => $P$BAfSwYFZEUKIkQyF30Eq7GN3HOUXFW/
            [user_nicename] => testing
            [user_email] => [email protected]
            [user_url] => 
            [user_registered] => 2015-12-15 07:11:35
            [user_activation_key] => 1450163495:$P$Br7QHNREuY.esEZdB3c92fK2CrW9QH.
            [user_status] => 0
            [display_name] => testing testing
            [token_key] => 
        )

    [ID] => 20
    [caps] => Array
        (
            [subscriber] => 1
        )

    [cap_key] => wp_capabilities
    [roles] => Array
        (
            [0] => subscriber
        )

    [allcaps] => Array
        (
            [read] => 1
            [level_0] => 1
            [subscriber] => 1
        )

    [filter] => 
)

But I want the answer to be as

WP_User Object
    (
        [data] => stdClass Object
            (
                [ID] => 20
                [user_login] => testing
                [user_pass] => $P$BAfSwYFZEUKIkQyF30Eq7GN3HOUXFW/
                [user_nicename] => testing
                [user_email] => [email protected]
                [user_url] => 
                [user_registered] => 2015-12-15 07:11:35
                [user_activation_key] => 1450163495:$P$Br7QHNREuY.esEZdB3c92fK2CrW9QH.
                [user_status] => 0
                [display_name] => testing testing
                [token_key] => 
                [client] => abc
                [user_groups] => test
            )

        [ID] => 20
        [caps] => Array
            (
                [subscriber] => 1
            )

        [cap_key] => wp_capabilities
        [roles] => Array
            (
                [0] => subscriber
            )

        [allcaps] => Array
            (
                [read] => 1
                [level_0] => 1
                [subscriber] => 1
            )

        [filter] => 
    )

Compare the [data] part of both the array

How do I achieve this?

Thanks for the help in advance

Share Improve this question edited Aug 4, 2017 at 9:18 Johansson 15.4k11 gold badges43 silver badges79 bronze badges asked Dec 15, 2015 at 9:01 1991wp1991wp 1008 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 1

You can simply do this like.

$user = wp_get_current_user();
$user->data->client = $user->client; // $user->meta_key
$user->data->user_groups = $user->user_groups; // $user->meta_key

I found the answer for my question. No need to pass the values in the array we can call the separate function to get the values of the custom fields based on the current user for e.g. get_user_meta($current->ID);

发布评论

评论列表(0)

  1. 暂无评论