WordPress.org

Ready to get started?Download WordPress

Forums

User Avatar
[resolved] custom avatar (5 posts)

  1. Mantzer
    Member
    Posted 2 years ago #

    is it possible to determine if the user has updated their avatar? i have a members list but only want to display users that don't have the default avatar in their profile.

    http://wordpress.org/extend/plugins/user-avatar/

  2. enej
    Member
    Plugin Contributor

    Posted 2 years ago #

    You could see write a php function to see if a image file exists in the specific folder. Each user has its own images in the folder that is the same as their user ID.

    Cheers

  3. Brooke Dukes
    Member
    Posted 2 years ago #

    User Avatar makes it a bit difficult because although each user has a unique folder the filename itself is random. I was able to do it by using this code. It is also possible to set fixed paths but in my case it was better to get the upload dirs from WordPress.

    $uploads = wp_upload_dir(); //WordPress upload path
            $uploads_url = ( $uploads['baseurl'] ); //full url of upload dir
            $uploads_dir = ( $uploads['basedir'] ); //full path of upload dir
            $user_id = $post->post_author; //id of author (if used in loop)
            $avatar_filename = user_avatar_avatar_exists($user_id ); //function from plugin
    
    if (file_exists($uploads_dir.'/avatars/'.$user_id .'/'.$avatar_filename)) {
    // file is there so do something like show it
    }
  4. Mantzer
    Member
    Posted 2 years ago #

    thanks. this works great. now the only problem left is, that some users have set up a gravatar image and i need to check for that as well...

  5. Mantzer
    Member
    Posted 2 years ago #

    sorry that was easy. but if anybody's interested, this is what i'm using now:

    $uploads = wp_upload_dir(); //WordPress upload path
    $uploads_url = ( $uploads['baseurl'] ); //full url of upload dir
    $uploads_dir = ( $uploads['basedir'] ); //full path of upload dir
    $user_id = $post->post_author; //id of author (if used in loop)
    $avatar_filename = user_avatar_avatar_exists($user_id ); //function from plugin

    $hash = md5(strtolower(trim($user->user_email)));
    $uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
    $headers = @get_headers($uri);

    if (((preg_match("|200|", $headers[0])) || (file_exists($uploads_dir.'/avatars/'.$user_id .'/'.$avatar_filename))) {
    ...
    }

    cheers.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.