Skip to content

Commit

Permalink
Merge pull request rodrigoprimo#59 from Frique/save-twitter-avatar
Browse files Browse the repository at this point in the history
Save Twitter avatar to user meta & show with get_avatar
  • Loading branch information
rodrigoprimo committed Aug 8, 2014
2 parents a312afd + a5ac095 commit 8957a77
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 7 additions & 1 deletion social-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function sc_social_connect_process_login( $is_ajax = false ) {
$sc_first_name = $names[0];
$sc_last_name = $names[1];
$sc_screen_name = $_REQUEST[ 'social_connect_screen_name' ];
$sc_avatar = isset( $_REQUEST['social_connect_avatar'] ) ? str_replace( 'http:', '', $_REQUEST['social_connect_avatar'] ) : '';
$sc_profile_url = '';
// Get host name from URL
$site_url = parse_url( site_url() );
Expand Down Expand Up @@ -216,6 +217,10 @@ function sc_social_connect_process_login( $is_ajax = false ) {
if ( $user_id && is_integer( $user_id ) ) {
update_user_meta( $user_id, $sc_provider_identity_key, $sc_provider_identity );
}

if( isset( $sc_avatar ) && $sc_avatar ){
update_user_meta( $user_id, 'social_connect_twitter_avatar', $sc_avatar );
}
} else {
add_filter( 'wp_login_errors', 'sc_login_errors' );

Expand Down Expand Up @@ -337,7 +342,8 @@ function sc_filter_avatar($avatar, $id_or_email, $size, $default, $alt) {
$size_label = 'mini';
}

$custom_avatar = "http://api.twitter.com/1/users/profile_image?id=$social_id&size=$size_label";
$custom_avatar = get_user_meta( $user_id, 'social_connect_twitter_avatar', true );
$custom_avatar = str_replace( '_normal', '_' . $size_label, $custom_avatar );
break;
}
}
Expand Down
20 changes: 12 additions & 8 deletions twitter/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,33 @@
$name = $user->name;
$screen_name = $user->screen_name;
$twitter_id = $user->id;
$avatar = $user->profile_image_url;
$signature = social_connect_generate_signature($twitter_id);

do_action( 'social_connect_before_register_twitter', $twitter_id, $signature );
?>

<html>
<head>
<script>
function init() {
window.opener.wp_social_connect({'action' : 'social_connect', 'social_connect_provider' : 'twitter',
'social_connect_signature' : '<?php echo $signature ?>',
'social_connect_twitter_identity' : '<?php echo $twitter_id ?>',
'social_connect_screen_name' : '<?php echo $screen_name ?>',
'social_connect_name' : '<?php echo $name ?>'});

window.opener.wp_social_connect({
'action' : 'social_connect',
'social_connect_provider' : 'twitter',
'social_connect_signature' : '<?php echo $signature; ?>',
'social_connect_twitter_identity' : '<?php echo $twitter_id; ?>',
'social_connect_screen_name' : '<?php echo $screen_name; ?>',
'social_connect_avatar' : '<?php echo $avatar; ?>',
'social_connect_name' : '<?php echo $name; ?>'
});
window.close();
}
</script>
</head>
<body onload="init();">
</body>
</html>

<?php
} else {
/* Save HTTP status for error dialog on connnect page.*/
Expand Down

0 comments on commit 8957a77

Please sign in to comment.