RSS Feed Subscribe to RSS Feed

Adding User Photo to WordPress User Profile

I finally got around to packaging up the Add User Photo plugin. You can download it here. Unzip it and upload to your plugins directory, and then activate it. You also need to 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">

Reader's Comments

  1. Seb | September 21st, 2006 at 1:37 am

    Brilliant !

    Seems to be working, but I’m note sure what piece of code to use in order to display the picture in the front office. If you can manage to add this info, you’re a king ! :)

    Thanks

    Reply to this comment
  2. Seb | September 21st, 2006 at 1:44 am

    OK, I’ve found out something working:

    user_login;?>.jpg?rand=” height=”100″/>

    Not sure if it’s the right thing, but working.

    Reply to this comment
  3. Seb | September 21st, 2006 at 1:45 am

    user_login; ?>.jpg?rand=” height=”100″/>

    Reply to this comment
  4. Seb | September 21st, 2006 at 1:49 am

    Can’t paste the code, sorry :(

    Reply to this comment
  5. Andrew Ferguson | September 21st, 2006 at 12:52 pm

    Including the picture depends on how you want to call it.

    If you want to include code, you have to escape it. You can also surround it with [html]Your code here[/html]

    The output will look something like:
    [html]Your code here[/html]

    Reply to this comment
  6. Andrew Ferguson | September 21st, 2006 at 12:59 pm

    The project I designed this for is my schools Radio Website (http://radio.mines.edu). Users are listed by their user_ID, so when their profile is viewed, a quick lookup finds their user_login.

    Once the user_login is found, I use the PHP file_exists() to determine if the user has uploaded an image. If they have, it uses that. If not, it uses a generic image.

    Also, the WordPress Database class is a very powerful way to interface with the DB. This is the best way to get the information you need.

    Reply to this comment
  7. foto do usuário no wordpress - athanazio | September 30th, 2006 at 12:24 am

    [...] http://www.andrewferguson.net/2006/09/20/adding-user-photo-to-wordpress-user-profile/ [...]

    Reply to this comment
  8. Michael Pollock | October 2nd, 2006 at 5:27 pm

    Hi Andrew:

    Great idea. Unfortunately I tried uploading a photo and got the following errors when I clicked the “Update Profile” button:

    Warning: move_uploaded_file(/homepages/8/d104609365/htdocs/dev4//wp-content/images/admin.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/8/d104609365/htdocs/dev4/wp-content/plugins/fergcorp_addUserPhoto.php on line 61

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phpMrUKie’ to ‘/homepages/8/d104609365/htdocs/dev4//wp-content/images/admin.jpg’ in /homepages/8/d104609365/htdocs/dev4/wp-content/plugins/fergcorp_addUserPhoto.php on line 61

    Warning: Cannot modify header information - headers already sent by (output started at /homepages/8/d104609365/htdocs/dev4/wp-content/plugins/fergcorp_addUserPhoto.php:61) in /homepages/8/d104609365/htdocs/dev4/wp-includes/pluggable-functions.php on line 272

    Any ideas? The filename I’m trying to upload is agent.jpg.

    Thanks - Michael

    Reply to this comment
  9. Michael Pollock | October 2nd, 2006 at 5:38 pm

    Found the problem.

    There was no /images directory in my wp-content folder.

    I created the directory and it’s all fixed.

    Thanks again - Michael

    Reply to this comment
  10. Jimothy Jenkins | October 10th, 2006 at 9:31 am

    First off, thanks for the hard work, this is exactly what I need. I’m trying to integrate this with wordpress MU, and I’m having some difficulties. Basically, I want to display the user’s picture in the sidebar, but for some reason the .$profileuser->user_login part of the img src url isn’t returning anything. The path is fine, just nothing returned for the user_login. Do you have any ideas? I don’t know if MU accesses user_login differently, or even if I can get to that variable from the front side. Any help would be appreciated.

    Reply to this comment
  11. Jimothy Jenkins | October 10th, 2006 at 9:49 am

    never mind, I was off on what I needed. I’ve re-read the code and understand what’s happening now.

    Reply to this comment
  12. WordPress › Author Image plugin? « WordPress MU Forums | October 10th, 2006 at 11:27 am

    [...] http://www.andrewferguson.net/2006/09/20/adding-user-photo-to-wordpress-user-profile/ [...]

    Reply to this comment
  13. Herb Moyer | October 17th, 2006 at 2:32 am

    Not sure if anyone else ran into this problem, but if you try to upload a picture and it keeps giving you an error message about the file being a pjpeg instead of a jpg just change line 60 of the plugin code to show the following:

    if(($_FILES['photoUpload']['type'] == “image/jpeg” or “image/pjpeg”) || ($_FILES['photoUpload']['type'] == “image/jpg” or “image/pjpeg”)){

    And then it should work fine.

    Reply to this comment
  14. Andrew Ferguson | October 17th, 2006 at 10:04 am

    Actually, you should you should use:
    [php]
    if(($_FILES['photoUpload']['type'] == “image/jpeg”) || ($_FILES['photoUpload']['type'] == “image/jpg”) || ($_FILES['photoUpload']['type'] == “image/pjpeg”)){
    [/php]

    Reply to this comment
  15. Michael Halligan | October 18th, 2006 at 1:52 pm

    Andrew, even after modifying line 60 of fegcorp_addUserPhoto.php to be : 1.
    if(($_FILES['photoUpload']['type'] == “image/jpeg”) || ($_FILES['photoUpload']['type'] == “image/jpg”) || ($_FILES['photoUpload']['type'] == “image/pjpeg”)){

    an upload of a jpeg file returns:

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

    Please go back and try again.

    Reply to this comment
  16. RadoOne | October 20th, 2006 at 12:55 pm

    Hi Andrew, thanks for that great plugin! Could you please write here the piece of code I should use to show the photo of a post author on single.php page? Thanks in advance.

    Reply to this comment
  17. Gilbert | October 25th, 2006 at 3:15 pm

    I get this error when trying to upload a .jpg image:

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

    Please go back and try again.”

    Any ideas?

    Reply to this comment
  18. Gilbert | October 25th, 2006 at 3:29 pm

    Sorry, I had forgotten to make the change to profile.php

    It’s working as it should, my mistake.

    Reply to this comment
  19. Gilbert | October 26th, 2006 at 1:11 am

    After using this for a while, I realized that since it runs your function every time you update your profile, when I go into the profile just to change some other field but not to update my picture, it still tries to upload something and I get an error because it’s not jpg or jpeg. Can something be written in there to test for a blank field or perhaps a checkbox the user checks everytime you wish to upload a new picture?

    Reply to this comment
  20. Adrian | November 3rd, 2006 at 10:52 pm

    I just wanted to echo the request for some examples of code that will display the user’s photo on an author template, or in the sidebar. Also, I am curious if this could be used in the comments to display the photo next to an author’s comment. Kind of like the gravatar stuff. Thanks in advance.

    Reply to this comment
  21. Adrian | November 3rd, 2006 at 11:50 pm

    If anyone is interested, this is what I got to work on an author profile template:

    <img src="<?php echo get_bloginfo(’url’)."/wp-content/images/".$curauth->user_login; ?>.jpg?rand=<?php echo rand(); ?>" height="100" align="right" />

    I am still trying to get it to work in the comments…

    Reply to this comment
  22. Adrian | November 4th, 2006 at 12:42 am

    To get this to work in the comments, you can use this plugin:
    http://inner.geek.nz/archives/2005/01/12/wp-plugin-official-comments/

    Once you have this installed you could put this code in your comments template:

    <?php
    if(is_wpuser_comment() != 0) {
    echo "<a href=’http://www.yourblogaddress/author/".comment_wpusername()."’><img
    src=’http://www.yourblogaddress.com/beta/wp-content/images/".comment_wpusername().".jpg’
    echo rand(); height=’100′ width=’100′ alt=’User Photo’ align=’left’ /> </a> "; } ?>

    Not knowing a lick of php, I surprised myself that I could make this work…

    Reply to this comment
  23. Adrian | November 4th, 2006 at 11:45 pm

    I just realized that I have the same problem as Gilbert with the error when I try to update anything on my profile without putting anything in the upload photo field. Has anyone found a solution to this problem?

    Reply to this comment
  24. Andrew Ferguson | November 4th, 2006 at 11:50 pm

    Hey all,

    I just want to let you know that I am here and reading your comments. I been really busy with school and what not, but I have a break in about two weeks. I’m hoping to take a look at the code then.

    -Ferg

    Reply to this comment
  25. Kevin | November 10th, 2006 at 8:46 pm

    I was also looking for a way to prevent the error message if I did an update without including another upload image. So I included a parent if statement to see if the file type is null, in which case it will not execute the upload.

    I also added a ‘chmod’ command to set the file permissions once the file is uploaded, since i was having trouble with this the way my server is configured.

    [html]
    if ( $_FILES['photoUpload']['type'] != “” ) { if(($_FILES['photoUpload']['type'] == “image/jpeg”) || ($_FILES['photoUpload']['type'] == “image/jpg”) || ($_FILES['photoUpload']['type'] == “image/pjpeg”)) { move_uploaded_file($_FILES['photoUpload']['tmp_name'], ABSPATH.”/images/”.$userdata->user_login.”.jpg”);
    chmod(ABSPATH.”/images/”.$userdata->user_login.”.jpg”, 0644);
    }
    else
    //die(”error: “.$_FILES['photoUpload']['error']);
    die(”Error: Please only upload jpg files! Your content type is ".$_FILES['photoUpload']['type'].”Please go back and try again.”);
    }
    [/html]

    I hope this helps.

    Reply to this comment
  26. Adrian | November 11th, 2006 at 10:09 am

    Kevin, That sounds like just what is needed, but I can’t seem to get it too work. Where in the plugin should this code go?

    Reply to this comment
  27. Kevin | November 11th, 2006 at 4:38 pm

    Hi, the modification needs to go in the fergcorp_addUserPhoto_updateField function. I’ve created a modified and commented one that can be downloaded here: http://www.kef.ca/public/fergcorp_addUserPhoto_kefmod.zip

    I’ve actually imbedded the code into my own code as I wanted to create a separate admin page for additional profile information and I wanted the picture to appear on that page.

    Kevin.

    Reply to this comment
  28. Adrian | November 11th, 2006 at 9:34 pm

    Kevin,
    That worked perfectly. Thanks so much for your help!

    Reply to this comment
  29. Kevin | November 12th, 2006 at 2:11 pm

    I forgot to include the chmod command in the zipped version. I’ve added it: http://www.kef.ca/public/fergcorp_addUserPhoto_kefmod.zip

    Kevin

    Reply to this comment
  30. Blogging - RenegadeLatinoWiki | November 28th, 2006 at 7:56 pm

    [...] From RenegadeLatinoWiki Jump to: navigation, search [edit] Wordpress Plugins Ultimate Tag Warrior 3 Usermeta Userextra User Photo fgallery: Probobly best used for hosting images on the same server/site. Page Restriction Static Front Page [edit] Get Paid for Blogging ReviewMe Blogitive Retrieved from “http://wiki.renegadelatino.com/index.php?title=Blogging” [...]

    Reply to this comment
  31. errows | December 7th, 2006 at 8:43 am

    Thank you for the plugin.
    In Kevin’s last ZIP, the wp-content folder is missing in the path.
    [html]
    //Change this line chmod(ABSPATH.”/images/”.$userdata->user_login.”.jpg”, 0644);

    //for this one:
    chmod(ABSPATH.”/wp-content/images/”.$userdata->user_login.”.jpg”, 0644);
    [/html]

    Reply to this comment
  32. Jeff McNeill | December 12th, 2006 at 1:18 pm

    Andrew Ferguson dot NET » Blog Archive » Adding User Photo to WordPress User Profile

    Reply to this comment
  33. Billy Dnnis | December 15th, 2006 at 11:02 am

    Thanks for the plugin, but I cannot seem to get it to work.

    I get an error whenever I try to upload my image:

    Warning: move_uploaded_file(/home/peoriapu/public_html/blogpeoria//wp-content/images/peoriap.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/peoriapu/public_html/blogpeoria/wp-content/plugins/fergcorp_addUserPhoto.php on line 61

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phpeojTv7′ to ‘/home/peoriapu/public_html/blogpeoria//wp-content/images/peoriap.jpg’ in /home/DELETED/public_html/blogpeoria/wp-content/plugins/fergcorp_addUserPhoto.php on line 61

    Warning: Cannot modify header information - headers already sent by (output started at /home/DELETED/public_html/blogpeoria/wp-content/plugins/fergcorp_addUserPhoto.php:61) in /home/DELETED/public_html/blogpeoria/wp-includes/pluggable-functions.php on line 272

    Reply to this comment
  34. Billy Dnnis | December 15th, 2006 at 11:07 am

    Sigh.
    Nevermind.
    I added “/images” file to wp-content.

    Reply to this comment
  35. niko | January 10th, 2007 at 1:31 pm

    sorry for a stupid question, I’m just bit lost on this one. how can I load the updated image? fex in to the author sidebar?

    Reply to this comment
  36. WPMU Author Profile Enhanced Plugin : The Almighty and His Servant | February 3rd, 2007 at 7:05 pm

    [...] its present state this plugin makes use of the Author Image Plugin by Andrew Ferguson, and the Author Profile Widget that Ergate [...]

    Reply to this comment
  37. pankaj | February 8th, 2007 at 7:50 am

    hi all, how do i show profile image on post pages?
    plz help…

    Reply to this comment
  38. Martin | August 23rd, 2007 at 7:23 am

    Fantastic plugin…….. Have made a slight change so that as admin on the edit-user screen I can upload the image for them as I want to have all my images same size on the member profile list page.

    I would really appreciate it if someone could now tell me how to incorporate shrink-image to one size into this plugin as a user could and will try to upload a 12×10 photo, etc… I’ve looked at WP shrink_dimensions code but don’t know exactly how to incorporate it.
    Thanks in advance.

    Reply to this comment
  39. Martin | September 4th, 2007 at 10:26 am

    Cancel that help on shrink image.. Worked it out..
    Thanks.

    Reply to this comment
  40. Bradley | January 2nd, 2008 at 3:46 pm

    Martin: How did you make the images the same size? I’ve tried the obvious ” height=”100″ width=”100″ ” in the plugin code, but I don’t think that’s resizing anything.

    Andrew: Thank you so much for this plugin! I finally have a way to let users/members upload their own photo!

    Reply to this comment
  41. Mike Smith | January 14th, 2008 at 1:33 am

    Does anyone know for Wordpress MU, how you can display the 10 most recent profile pictures on the main page of the site? not the bloggers site, but the main site (ie: yoursite.com, not blogger.yoursite.com). I want to have a “Newest Members” section on the main page, but can’t figure this out.

    Any help is appreciated.

    Thanks,
    Mike

    Reply to this comment
  42. Bradley | January 14th, 2008 at 10:26 am

    Mike: If you figure it out, I’d love to know, too. My first thought would be just a category called “Newest Members” with (regular WP) posts that you could customize with their photo, some info, etc. Of course, that’s probably not automated either … anyway, just a thought.

    Reply to this comment
  43. Nandan | January 27th, 2008 at 7:46 am

    I think if you have a space in the name of the file then that gives you an err. I just renamed my .jpg to a std 8.3 file name and it worked for me.

    I want to show a page where I can display the author photo and his ‘About yourself’ information. any help is greatly appreciated.

    Thanks.

    Reply to this comment
  44. lauren | May 7th, 2009 at 9:42 pm

    Hi. My problem is that I can’t properly edit my /wp-admin/profile.php file. It’s only 20 lines long. If you can tell me where the edit I’m supposed to make belongs, I’ll be ready to go on to the next issue. For reference, the file looks like this:

    ?php
    /**
    * User Profile Administration Panel.
    *
    * @package WordPress
    * @subpackage Administration
    */

    /**
    * This is a profile page.
    *
    * @since unknown
    * @var bool
    */
    define(’IS_PROFILE_PAGE’, true);

    /** Load User Editing Page */
    require_once(’user-edit.php’);
    ?>

    (and thanks for your time. I’m sure the plugin is wonderful.)

    Reply to this comment
  45. Andrew Ferguson | May 30th, 2009 at 10:31 pm

    I’ve updated GiladG’s original comment with the code he sent me. I’ve also posted this other bit. Thanks for putting up with the situation until I can get it resolved!

    From GiladG:

    Another issue that I ran into with the plugin and was going to post a solution code was that when updating the profile page one must upload a picture each time because if no picture was included the update script would die saying ‘Please only upload jpg files!’. What I did to fix it was wrap the image processing portion with an IF so if a file was not uploaded the processing portion would be disregarded. So this is what it looks like now (blue is my addition (Editors note: just line one of the code)):

    [php]
    if (is_uploaded_file($_FILES['photoUpload']['tmp_name'])) {

    if(($_FILES['photoUpload']['type'] == “image/jpeg”) || ($_FILES['photoUpload']['type'] == “image/jpg”)){

    move_uploaded_file($_FILES['photoUpload']['tmp_name'], ABSPATH.”/wp-content/images/”.$userdata->user_login.”.jpg”);

    }

    else

    //die(”error: “.$_FILES['photoUpload']['error']);

    die(”

    Error: Please only upload jpg files! Your content type is ".$_FILES['photoUpload']['type'].”

    Please go back and try again.

    “);

    }

    [/php]

    Either way, you made my life a whole lot easier with this plugin. Never thought it would be so easy to implement the upload. Thank you for that!

    Reply to this comment
    • GiladG | May 31st, 2009 at 3:20 am

      Thanks Andrew.

      Quick note, since the colors I had in my email do not show here, only the first line (IF STATEMENT) and the last line (CURLY BRACKET) are my addition. The rest is a part of the original code.

      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!