I try to get avatar display from wordpress user. But it can not work. Well... I'm stuck here for 2 days to solve this so I running here.. Here is my 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
);
}
$userInfo->ID and $userInfo->display_name is working good. I got the ID and display name. But the avatar is not working. Any help and suggestion really appreciated. Thank you.
Aucun commentaire:
Enregistrer un commentaire