This tutorial is for people who using the plugin Facebook Connect and wishes to show the user profile's image near the user's name.
Step 1
Open your current theme and edit the file header.php, put this code before the line with...<!DOCTYPE html PUBLIC... etc:
<?php
$config = array (
'appId' => 'your app ID',
'secret' => 'your secret code',
'allowSignedRequest' => false // Optional but should be set to false for non-canvas apps
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
if ($user_id) {
// We gave a user ID, so probably a logged in user.
// if not, we'll get an exception which we handle below
try {
$user_profile = $facebook->api('/me','Get');
} catch (FacebookApiException $e){
// If the user is logged out, you can have an user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll just ask the user to login again here.
$login_url = $facebook->getLoginUrl();
error_log ($e->getType());
error_log ($e->getMessage());
}
}else{
//No User, print a link for the user to login
$login_url = $facebook->getLoginUrl();
}
?>
Step 2
Now if the user is a logged facebook user, we show the associated picture
Always in the header.php, before this code that show the name, <span><?php echo sprintf(__('Hi %s',...etc...
Put this code:
<?php if ($user_id == 0) {
echo "";
}else{
echo "<img src=\"
https://graph.facebook.com/$user_id/picture\" height=\"32\" width=\"32\" /> ";
} ?>
If you want can change the values in height and width as you wish.
Note
This is not my work, i've seen a video tutorial and to make it easy for everybody i decided to write the code showed, now you can simply copy and paste!