RSS Feed Subscribe to RSS Feed

Add User Photo

Overview
Allows adding a photo to a user profile

Compatibility

  • 2.1.*
  • 2.0.*
  • 1.5 (in theory, not tested)

Installation
Download the file and put it in your plugins directory. In your wp-content folder, create a directory called images and make sure that it was write permissions.

Modify line 21 of /wp-admin/profile.php, adding enctype="multipart/form-data" to the form tag. So at the end of the day, line 21 should look like:

<form name="profile" id="your-profile" action="profile-update.php" method="post" enctype="multipart/form-data">

Activate plugin.

Usage
User will now be able to upload a jpg-based image. The image is uploaded and renamed to their username with a jpg extension (e.g. johndoe.jpg).

The file is located in /wp-content/images/

To use the file, simply reference its location. This can be done using an absolute reference (i.e. pointing to an image at http://www.example.com/wp-content/images/johndoe.jpg) or through PHP programming.

Example:

If you know the UserID, but not the username, you can do a simple lookup:

$userLogin= $wpdb->get_var("SELECT $wpdb->users.user_login FROM $wpdb->users WHERE $wpdb->_users.ID = ".$someUserID.");

if(file_exists(ABSPATH."wp-content/images/".$userLogin.".jpg"))
	$imageURL = get_bloginfo('url')."/wp-content/images/".$userLogin.".jpg";
else
	$imageURL = get_bloginfo('url')."/wp-content/images/unknown.jpg";;

echo "<img src=\"$imageURL\" />";

In the above example, an addition file, unknown.jpg, has been placed in the images directory to serve as a placeholder for users who haven’t uploaded images. You also need to specify the value of $someUserID.

Download
Latest Version:

Reader's Comments

  1. The Big Chorizo | August 26th, 2007 at 3:41 pm

    Thanks for the plugin but has anybody solved the bug that Yotsume mentioned: “Error: Please only upload jpg files! Your content type is”

    I’m having the same problem using WP2.2. I even edited the photo in fireworks to make sure it was jpg and it still returns this error.

    This plugin is ideal for what I’m trying to do, just a photo for each user that can be displayed on his profile or author page. No strange gravatar things that normal people don’t understand :-)

    Keep up the good work, Andrew!

    Reply to this comment
  2. Martin | September 3rd, 2007 at 11:07 pm

    This is for Sofia…
    I found I can upload photos for my members by duplicating the line:

    add_action(’show_user_profile’, ‘fergcorp_addUserFolder_addField’);

    and changing the duplicated line to ‘edit_user_profile’

    so you will have three lines then:

    add_action(’show_user_profile’, ‘fergcorp_addUserFolder_addField’);
    add_action(’edit_user_profile’, ‘fergcorp_addUserFolder_addField’);
    add_action ‘personal_options_update’, ‘fergcorp_addUserPhoto_updateField’);

    Hope this helps.
    Martin

    Reply to this comment
  3. Martin | September 3rd, 2007 at 11:15 pm

    Oops.. One more thing Sofia..
    You also have to add the:

    enctype=”multipart/form-data”>

    to the

    Reply to this comment
  4. Martin | September 3rd, 2007 at 11:18 pm

    Sorry, Got cut off.
    Oops.. One more thing Sofia..
    You also have to add the:

    enctype=”multipart/form-data” (see top of this page)

    to line 76 of user_edit.php file in the admin folder if using Wordpress 2.1.2.
    It may be some other line in a diff version.

    Reply to this comment
  5. Martin | September 3rd, 2007 at 11:30 pm

    This is for the The Big Chorizo:
    Normally the error message you get would be “Error: Please only upload jpg files! Your content type is image/pjpeg”

    For a while I was getting the msg w/o the type printing out and found that I had not added the enctype=”multipart/form-data” (with a trailing greater than) to the profile.php file. Not sure if the orig. poster just forgot to type the rest ofthe error msg, but hope this helps.

    p.s. had to put trailing greater than as using the symbol may cut off the comment.

    Reply to this comment
  6. chag | September 8th, 2007 at 6:52 am

    Hi

    I wrote a small code to automatically resize the uploaded pictures.

    add this 2 functions

    [php]
    function calcratio($src_w, $src_h, $dst_w, $dst_h){
    $ratio_orig = $src_w/$src_h;
    if ($dst_w/$dst_h > $ratio_orig) {
    $dst_w = $dst_h*$ratio_orig;
    } else {
    $dst_h = $dst_w/$ratio_orig;
    }

    $result=array($dst_w, $dst_h);
    return $result;
    }

    function redimage($filename,$src_w,$src_h) {
    $newsize = calcratio($src_w, $src_h, 120, 150);
    $dst_im = ImageCreateTrueColor($newsize[0],$newsize[1]);
    $src_im = imagecreatefromjpeg($filename);

    ImageCopyResampled($dst_im,$src_im,0,0,0,0,$newsize[0],$newsize[1],$src_w,$src_h);
    ImageJpeg($dst_im,$filename);

    ImageDestroy($dst_im);
    ImageDestroy($src_im);
    }

    [/php]

    juste before this line :

    [php]
    add_action(’show_user_profile’, ‘fergcorp_addToUser_addFields’);
    [/php]

    And add this 2 lines :
    [php]
    list($width, $height) = getimagesize($final_path);
    redimage($final_path, $width,$height);
    [/php]

    after the move_uploaded_file command :

    [php]
    move_uploaded_file($_FILES['photoUpload']['tmp_name'], $final_path);
    chmod($final_path, 0644); // rw for owner, r for everyone else
    [/php]

    This code require the GD2 library. The resized size can be set on this line :

    [php]
    $newsize = calcratio($src_w, $src_h, 120, 150);
    [/php]

    Actually, the image size is 120px width and 150px height

    The calcratio function will keep the image aspect when the image is resized. Hope it helps.

    You can see the complete source code here : http://pastebin.com/f2002953b

    Chag

    Reply to this comment
  7. roj | October 19th, 2007 at 2:41 am

    I think this is better than using gravatar.. Thank you for this plugin.

    to chad: tried your code but it gives me the error message even if I have no user photo.

    Reply to this comment
  8. chag | October 19th, 2007 at 7:56 am

    Hi,

    what error message ?

    Reply to this comment
  9. roj | October 19th, 2007 at 10:10 am

    to chag: this is the error

    Error:Please only upload jpg files! Your content type is
    Please go back and try again.

    …but I managed to avoid the error by adding

    || ($_FILES['photoUpload']['type'] == “” at the IF statement of

    fergcorp_addToUser_updateFields()

    I’m not sure if that’s the right solution but after adding it, now it’s working.

    Reply to this comment
  10. tukangKOMENTAR | December 20th, 2007 at 7:28 pm

    I still get error msg: Error: Please only upload jpg files! Your content type is. (without pjpeg), every time I hit Update Profile button. Any idea why?

    Reply to this comment
  11. Mike Smith | March 6th, 2008 at 9:32 pm

    Hey Andrew,

    This is a great plugin. I tried using your db code to have the image show the current author’s image if you’re viewing the author but I get an error.

    [code language="php"]WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
    SELECT user_login FROM wp_users WHERE ID =[/code]

    This is the code I put at the top of the author page:

    [code language="php"]< ?php $username = $wpdb->get_var(”SELECT user_login FROM $wpdb->users WHERE ID = “.$_REQUEST['author']); ?>[/code]

    I’m not sure what I could be doing wrong? I’d love to get this working because I’ve got a project that will have 6-7 authors so I’d like their images showing automatically.

    Thanks

    Reply to this comment
  12. Mike Smith | March 6th, 2008 at 9:42 pm

    Just so everyone knows, as SOON as I posted that comment, I figured this out :)

    Wordpress has you add this to your author page to get the current user.

    [code language="php"]< ?php
    if(get_query_var('author_name')) :
    $curauth = get_userdatabylogin(get_query_var('author_name'));
    else :
    $curauth = get_userdata(get_query_var('author'));
    endif;
    ?>[/code]

    So this way, you can use codes to show the name, login name, description, ect. All I did was replace the get $username from my above comment, and replaced it with this code

    [code language="html"][/code]

    Reply to this comment
  13. Must have wordpress plug-in round up | Wordpress Hut | March 9th, 2008 at 4:21 pm

    [...] it. Interested in using wordpress to power your e-commerce websites? This is the plug-in you need. Add User Photo - Andrew put together an awesome plug-in that allows all of your authors and anyone else who signs [...]

    Reply to this comment
  14. Aike | August 13th, 2008 at 9:29 am

    Auf Deutsch kann mit keiner bei dem Plugin helfen oder? Ich bekomme keine Fotos hochgeladen steht immer:

    Error: Please only upload jpg files! Your content type is

    Please go back and try again.

    ich habe es mit allen jpg Datein versucht, groß klein aber nicht

    Reply to this comment
  15. Andrew Ferguson | August 16th, 2008 at 8:18 pm

    @Aike:

    If the MIME type is not image/jpg or image/jpeg, the file will not upload. It is possible to have the plugin not check the file type, however users would be able to upload any type of file at the point, which would be security risk.

    If you are okay with that, then change line 61 from:
    if(($_FILES['photoUpload']['type'] == “image/jpeg”) || ($_FILES['photoUpload']['type'] == “image/jpg”)){
    to
    if(1){

    Reply to this comment
  16. Mauricio | November 20th, 2008 at 6:02 am

    Hi Andrew,

    After uploaded my image, I receive the following error message: “Upload error: Unable to place the user photo at: /home/restricted/home/MYSITE/public_html/wp-content/uploads/userphoto/admin.JPG.
    I checked the permissions and the uploads folder settings and it seems to be ok.
    Regards.

    Reply to this comment
  17. jack | December 4th, 2008 at 3:28 pm

    hi
    I downloaded the file and made it in wp-content/plugins folder and i changed the form to encrypt=multipart/ settings in wpadmin/profile.php
    after this i go and check the profile page i didnt find the field and input box in that page.pls tell me how to do it. i need to add create table for that image or how to make it work for me

    Reply to this comment
  18. jack | December 4th, 2008 at 4:46 pm

    Sorry andrew its working fine the person who given me the work described wrong folder anyway thanks its working great

    Reply to this comment
  19. Sonny | January 26th, 2009 at 7:32 pm

    Hi, this pluggin work fine in firefox but not in IE. and there is no profile-update.php page in wp-admin folder. thanks.

    Reply to this comment
  20. Brian Niles | January 27th, 2009 at 9:11 am

    How has all of this changed with Wordpress 2.7? I see one item is different - the /wp-admin/profile.php file is actually /wp-admin/user-edit.php

    Also, trying to put the author’s photo in their post - keep in mind we have multiple authors for this blog. Any advice or code to help me modify the index.php file to do this?

    Reply to this comment
  21. lauren | May 7th, 2009 at 10:40 pm

    I posted a detailed request for help, and it appears to have disappeared. Before I retype the whole thing, I will look and see what happens to this.

    Reply to this comment
  22. lauren | May 7th, 2009 at 10:51 pm

    Ok, let me try this again.

    I can’t edit line 21 of /wp-admin/profile.php because the file is only 20 lines long.

    The complete file is below. Please tell me how I modify it to get this plugin to work.

    Reply to this comment
  23. Paul Boyce | June 5th, 2009 at 11:20 pm

    Does this have the ability to upload more than one picture per profile? I am dying for a solution to make this happen.

    Reply to this comment

Leave a Comment

Gravatar: Get your picture displayed next to your comment: http://gravatar.com

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Plugin Help: If your requesting help about a plugin, please provide as much information as possible. At the very least, include your WordPress Version and the Plugin Version!