• Resolved MonkimoE

    (@monkimoe)


    I have custom apps need to get wordpress user data. Here is the code:

    public function authUser(ConnectionInterface $conn, array $cookies) {
        global $current_user;
        $current_user = null;
        $wpDir = $conn->Config['wordpress']['dir'];
    
        $this->debug("WP Autorization cookies:"); $this->debug($cookies);
    
        foreach ($cookies as $key => $value) {
            $_COOKIE[$key] = urldecode($value);
        }
        require_once($wpDir . '/wp-config.php');
        require_once($wpDir . '/wp-includes/wp-db.php');
        require_once($wpDir . '/wp-includes/pluggable.php');
        $userInfo  = wp_get_current_user();
        if(!$userInfo || !$userInfo->ID){
            return null;
        }
    
        // get avatar from WordPress
        $avatar = get_avatar( $userInfo->ID, 50 );
    
        return array(
            'id'            => $userInfo->ID,
            'name'          => $userInfo->display_name,
            'image'         => $avatar
        );
    }

    ‘id’ and ‘name’ is working good… I got the ID and display name. But the ‘image’ is not work getting avatar image. Is there anything I missed here? Any help and suggestion really appreciated. Thank you.

Viewing 1 replies (of 1 total)
  • From the Codex:

    Return Values

    string
    An img element. The function does not output anything; you have to echo the return value.

    Also are you sure that you have Show Avatars checked in Settings > Discussion?

    Finally: You’ll probably have more luck posting a question like this in the Plugins & Hacks forum instead.

Viewing 1 replies (of 1 total)
  • The topic ‘get_avatar() not work’ is closed to new replies.