Support » Plugins and Hacks » User Photo plugin in Author Page

  • Resolved Nessdufrat

    (@nessdufrat)


    Hi !
    I’m trying to display the user photo in my author page, from the plugin User Photo.

    that’s my page at the moment (part of it, at least)

    <?php
        global $wpdb, $table_prefix; // set global WP vars needed for script
    
        $order = 'user_nicename'; // set order for users table query
        $user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users
    
        foreach($user_ids as $user_id) : // start authors' profile "loop"
    
        $user = get_userdata($user_id); // retrieve author (i.e. user) details
        $level = $table_prefix . 'user_level'; // set 'user_level' usermeta meta_key record
        $user->user_level = $user->$level; // assign 'user_level' property to $users
        $role = $table_prefix . 'capabilities'; // set 'role' usermeta table meta_key record
        $user->role = array_keys($user->$role); // assign 'role' property to $user
        $user->role = $user->role[0]; // make sure $user->role is not an array
    ?>
    
        <?php
        $image_dir = 'wp-content/uploads/userphoto'; // directory where author images reside
        $image_file = $user->user_nicename; // format for image name
        $image_ext = 'jpg'; // author image extension
    
        $image_path = trim($image_dir, '/') . '/' . $image_file . '.' . $image_ext;
        if(file_exists(ABSPATH . $image_path)) :
        $author_image =    get_bloginfo('home') . '/' . $image_path;
    
    ?>
        <img class="user-image" src="<?php echo $author_image; ?>" alt="<?php echo $user->display_name; ?>" title="<?php echo $user->display_name; ?>" />
    <?php endif; ?>

    I removed the parts of it that weren’t useful for this topic.

    So, basically, I tried replacing :

    <?php
        $image_dir = 'wp-content/uploads/userphoto'; // directory where author images reside
        $image_file = $user->user_nicename; // format for image name
        $image_ext = 'jpg'; // author image extension
    
        $image_path = trim($image_dir, '/') . '/' . $image_file . '.' . $image_ext;
        if(file_exists(ABSPATH . $image_path)) :
        $author_image =    get_bloginfo('home') . '/' . $image_path;
    
    ?>

    By :

    <?php
    $author_image = userphoto_the_author_photo();
    ?>

    therefore calling the function from the user photo plugin.

    My main problem with the previous code was that an gif or png image would not be displayed.

    Basically, I don’t get any output in the src in my img tag. I’m sure I’m doing something wrong and any help would be greatly appreciated !!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Nobody ? 🙁

    I tried searching around for a solution, but all the hacks I found were with jpg only images.

    Anyone knows of a solution to display all image types ?

    Nobody ? Is it really THAT difficult ? I had no idea. I don’t really understand why I can’t get the user photo plugin to work. Tell me, is the synthax correct ?

    (I know, the endforeach is missing in the first code part, but it’s there in the rest of the code in my page, I just didn’t want to copy and paste the whole thing)

    Ok. Thanks to the French forum, the solution is :

    <?php
              $image_dir = 'wp-content/uploads/userphoto'; // directory where author images reside
              $image_file = $user->user_nicename; // format for image name
              $image_path = trim($image_dir, '/') . '/' . $image_file;
              if(file_exists(ABSPATH . $image_path . '.jpg')) :
              $author_image =    get_bloginfo('home') . '/' . $image_path . '.jpg';
              elseif(file_exists(ABSPATH . $image_path . '.png')) :
             $author_image =    get_bloginfo('home') . '/' . $image_path . '.png';
              elseif(file_exists(ABSPATH . $image_path . '.gif')) :
             $author_image =    get_bloginfo('home') . '/' . $image_path . '.gif';
    		 else :
    		 $author_image = "http://mydomain.com/wp-content/uploads/userphoto/defaultbig.gif";
    		endif; ?>
        <img class="user-image" src="<?php echo $author_image; ?>" alt="<?php echo $user->display_name; ?>" title="<?php echo $user->display_name; ?>" />

    I don’t know whether the code is totally correct or not, but it works really fine.

    Note that without the default image, I get the image from the above author repeated for an author without image.
    No idea why, but I’m clearly no PHP godess.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘User Photo plugin in Author Page’ is closed to new replies.