Support » Plugin: User Avatar » custom avatar

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Enej Bajgoric

    (@enej)

    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

    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
    }

    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…

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘custom avatar’ is closed to new replies.