Wordpress Avatar based on username

Discussion in 'Programming' started by ElusiveOne, Feb 10, 2011.

  1. #1
    I am trying to add a wordpress avatar based on the username, so far I have added the following to the functions.php file in my template to change the default avatar and it works well:

    if ( !function_exists('fb_addgravatar') ) {
    function fb_addgravatar( $avatar_defaults ) {
    $myavatar = get_bloginfo('template_directory') . '/images/pending.png';
    $avatar_defaults[$myavatar] = 'xboxrox';

    return $avatar_defaults;
    }

    add_filter( 'avatar_defaults', 'fb_addgravatar' );
    }

    Now I can change the $myavatar string to a remote url of an image and that works, however the image I want to use is the avatar icons from xbox.

    http://avatar.xboxlive.com/avatar/{$user_login}/avatarpic-l.png​

    Where the user_login = the members gamertag

    This is where my problem lies....
    Wordpress adds a '&s=64' or a '&s=50' after the url for the image.

    http://avatar.xboxlive.com/avatar/ElusiveLeader/avatarpic-l.png for example works perfectly but
    http://avatar.xboxlive.com/avatar/ElusiveLeader/avatarpic-l.png&s=64 returns an error.
    Is there a way of removing the '&s=64' or the '&s=50' resize attributes to call the image?

    Please help, I really would like to set the users avatar in wordpress automatically to match the live image held at http://avatar.xboxlive.com/avatar/{gamertag}/avatarpic-l.png
     
    ElusiveOne, Feb 10, 2011 IP
  2. ElusiveOne

    ElusiveOne Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I have fixed the above error by installing add-local-avatar plugin

    I have in my functions.php:

    if ( !function_exists('fb_addgravatar') ) {
    function fb_addgravatar( $avatar_defaults ) {

    $myavatar = "http://avatar.xboxlive.com/avatar/{$username}/avatarpic-l.png";
    $avatar_defaults[$myavatar] = 'xboxrox';

    return $avatar_defaults;
    }

    add_filter( 'avatar_defaults', 'fb_addgravatar' );
    }

    But the image returns:

    http://avatar.xboxlive.com/avatar//avatarpic-l.png

    How do I insert the users username to the above url???
     
    ElusiveOne, Feb 10, 2011 IP