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:
Last updated on August 16th, 2008 at 08:19 pm
0
Pingback: Thaiwordpress Wordpress Social
Pingback: blog.designcreatology is at the spa...
Pingback: Weblog Tools Collection
Pingback: Andrew Ferguson dot NET » Blog Archive » Add User Photo
does this image get resized or thumbnailed?
Currently: no.
Hi.
I’ve managed to activate the plugin, upload photos, but how do I display them?
If you could help me out here, I’d be very greatful!
Cruella,
I’ve added an example above. That should give you a good start.
Great!
Thankyou
Hi
Can you give us a better explanation about this plugin?
Thanxs 🙂
Your example doesn’t work.
Can you give us a better explanation about this plugin?
Not really. It’s a relatively straight forward plugin that allows you to upload a user photo to a directory. Can you be more specific?
Your example doesn’t work.
That should work just fine. I pretty much just copied and pasted it from the production version. I went back and clarified some more information about the user ID.
Also, just saying, “Your example doesn’t work,” isn’t very helpful. There are a million different issues that might cause a piece of PHP code to choke. I’m not a mind reader. Details about how your implementing the code and any error messages you’re receiving are good things to include as well.
You could use a cropping feature (optional) like the one at:
http://theblemish.com/post-thumbs-plugin/
in order to use it as an avatar…
Pingback: Weblog Tools Collection » Blog Archive » WordPress Plugin Releases for 2/20
Pingback: WeblogToolsCollection DE » Blog Archive » WordPress Plugin Veröffentlichungen am 20.2.
Pingback: WeblogToolsCollection Español » Blog Archive » Wordpress Plugins Publicados 2/20
Pingback: Plugin: Add User Photo to Profile | Wordpress Tutorials And Blogging Tips
Pingback: Plugin: Add User Photo to Profile - Easy Wordpress Forum
Rubira did you enclose the PHP code in “” (without the space between
Found another possible reason… check the file permission of the image uploaded. If it’s not readable by “Public” then that could be the cause. Andrew, is there a way to force the permission setting?
Please remove my last comment since the less-than sign got stripped out.
Another request: could you please add a check that if the upload field is empty, the code should NOT check the file type for jpg and allow the rest of the update to be successful? This is a scenario where a photo is already uploaded, but the user wants to change something else in the profile. The user should not be forced to upload an image every time.
The current work around is to just ignore the error. The rest of the information seem to update OK.
Thanks!
For some reason even if taking format.jpg into the system it gives an error message:
Error: Please only upload jpg files! Your content type is image/pjpeg
What went wrong? Think this plugin can not handle jpeg- format files properly?
Still would like to use your plugin! Any advise appreciated.
Pingback: Planet Wordpress
Markku,
Mine works, but from your output, it seems your file name had an extension of “pjpeg”.
——————————- also ———————–
I have the fix for the file permission on non-Windows systems. Replace line 76 in the php file with:
$final_path = ABSPATH.”/wp-content/images/”.$userdata->user_login.”.jpg”;
move_uploaded_file($_FILES[‘photoUpload’][‘tmp_name’], $final_path);
chmod($final_path, 0644); // rw for owner, r for everyone else
Here is the last fix from me to not output error when there the user isn’t uploading a file, but just changing the rest of the profile:
replace the line with “else” with
elseif (strlen($_FILES[‘photoUpload’][‘name’])>0)
Andrew, is there a way to force the permission setting?
I don’t think so. I might be able to include a shell script, but you have to make it executable, which sort of defeats the purpose of automating the entire thing (i.e. you either change the folder permissions or you change a file to permission so that you can automatically change the folder permissions).
I could be, I’ll take a look.
Another request: could you please add a check that if the upload field is empty
Yes, I’ll be including this in the next release.
For some reason even if taking format.jpg into the system it gives an error message:
Error: Please only upload jpg files! Your content type is image/pjpeg
This is a known error that I actually forgot about before I released it. It will be fixed one way or another in the next release.
As a temporary fix, you can modify line 61 by adding:
This makes line 61:
Hope that helps for now.
Pingback: Post Meta Data WordPress Plugins « Lorelle on WordPress
1. I’ve activated your Plugin and it’s working, but I’m not sure what the intended use is.
For example, I thought your Plugin might display an uploaded user’s photo next to their comments, but that’s not happening.
What exactly is the purpose of a user uploading their photo if no-one else can see it?
2. Please give more details about your example PHP code, in layman’s terms. What does that code “do” exactly? Where might someone paste that code?
Thanks in advance.
Rusty Miller: If you take a look at this page: http://studblogg.uib.no/?author=5 you can see what the plugin “does”.
Rusty, please see the usage information above.
Now I understand the purpose of your Plugin. Thank you for clarifying.
As you can tell, I’m more interested in an “avatar” Plugin, to show a picture next to a user comment.
Any recommendations?
The only thing that comes to mind are Gravatars, http://codex.wordpress.org/Using_Gravatars
General Note:
I just added a donation button on the side bar (to the right), so if you *really* like my plugins (and/or me) you might consider making a donation. I’ve been spending more and more time writing and supporting plugins. I?m a college student (3rd year Elect. Eng.) and really only do this programming thing on the side for the love of it.
hi andrew,
I was wondering if it was possible to use this plugin to upload images on the authors of a blog when you edit their profiles as the administrator.
At the moment it only works when I edit my own administrator profile, but I want to be able to use it also with the profile of the other users… is there an easy way to do this?
thanks
Sofia,
It’s currently not possible to upload images on behalf of other people. That seems like a good feature, so I’ll add that to the list for inclusion in the next release.
Pingback: MagicWordpress - Total Wordpress Connection - Home
Ok, Your plugin here is a super bug in code in to many places! .jpg .JPG neither work! No way my photos are not jpg format and your plug in still kicks back only an error of: Error: Please only upload jpg files! Your content type is
Ok time to hunt for a better coded profile plug-in
Yotsume,
It’s a pretty alpha stage code. It’s mostly designed as a starting place for other coders to use or for PHP guru’s to play with. Sorry you’re having such a hard time.
As for your error, the plugin is checking the MIME type. If the file you upload has not been correctly identified as an “image/jpeg”, then it won’t work.
Pingback: WP Plugins DB » Blog Archive » Add User Photo
Yo lo puse así y funca bien:
okay i have been trying, for months now, to display a nice user profile page with the userpic in it. i tried dans avatar thing (the modded version with userpics) and it only bring sup your usericon or no icon if you are not logged in. your plugin looked promising howver, i need to to automatically bring up a certain users pic rather than putting in the id. That way when you click on a users nickname from an authors (users) generated link, it goes to their generated profile and brings up the pic… if that makes sense. i need /?author=1 to come up with that author’s (1) pic.
@billy:
Shouldn’t be too hard. You’ll need to do a bit of coding.
The first step will be to get the username from the userid. This is easily accomplished using mySQL query to the DB. Based on your above variable scheme:
Then use the
$username
variable to access their picture:Hey Andrey,
thanks for the plug in – it’s rather… badly written. Otherwise after I rewrote it it’s fine.
S.
Hey Andrew, this is really cool, and I want it to work!!
Right now, when I click the update button with a jpg file ready to upload, I get several php errors, which appear to be permission related. I have wp-content/images/ with pemissions set to 644 (also tried 766)
Warning: move_uploaded_file(/home/christia/public_html//wp-content/images/admin.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/christia/public_html/wp-content/plugins/addUserPhoto.php on line 62
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phpqK8rkq’ to ‘/home/christia/public_html//wp-content/images/admin.jpg’ in /home/christia/public_html/wp-content/plugins/addUserPhoto.php on line 62
Warning: Cannot modify header information – headers already sent by (output started at /home/christia/public_html/wp-content/plugins/addUserPhoto.php:62) in /home/christia/public_html/wp-includes/pluggable.php on line 275
I considered the solution offered by HH (it sounded like it might be related) but he says to replace line 76 in the php file — and there is no line 76 in adduserphoto.php.
Any thoughts on what else I can try?
I discovered that this error was happening in the regular write post upload area as well, so I went hunting on the WP support forums, and found several relevant threads. Especially relevant were:
http://wordpress.org/support/topic/107994
http://wordpress.org/support/topic/102139
In both threads the conclusion was that this was something only the host could fix (unless you have root access). So I contacted my host, and the support tech created the wp-content/images/ folder for me, and gave it write permissions. His magic touch or command authority solved the problem, and I can upload both in write pages, and in AddUserPhoto. Hurray! Hope this helps others. 🙂
Marci,
You are correct, there is no line 76… My mistake. It was supposed to be line 62. So:
old line 62:
replace with 3 lines:
Sorry about the previous error. Hope this works for you.
Thanks HH. 🙂 I did get it working (my comment explaining what I did — or rather, what my host did — probably was still in moderation when you wrote). But next time I put this on a site (and I will!) I’ll definitely give this a try. Thanks for the clarification! And thanks again to Andrew for a great plugin. This is so needed, considering what I’ve seen on the forum.
Marci 🙂
Pingback: Flippress Blog » Blog Archiv » Backend mit Wordpress
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!
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
Oops.. One more thing Sofia..
You also have to add the:
enctype=”multipart/form-data”>
to the
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.
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.
Hi
I wrote a small code to automatically resize the uploaded pictures.
add this 2 functions
juste before this line :
And add this 2 lines :
after the move_uploaded_file command :
This code require the GD2 library. The resized size can be set on this line :
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
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.
Hi,
what error message ?
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.
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?
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.
This is the code I put at the top of the author page:
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
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.
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
Pingback: Must have wordpress plug-in round up | Wordpress Hut
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
@Aike:
If the MIME type is not
image/jpg
orimage/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){
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.
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
Sorry andrew its working fine the person who given me the work described wrong folder anyway thanks its working great
Hi, this pluggin work fine in firefox but not in IE. and there is no profile-update.php page in wp-admin folder. thanks.
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?
“I see one item is different – the /wp-admin/profile.php file is actually /wp-admin/user-edit.php”
That’s inaccurate. profile.php is a central part of the whole WP process.
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.
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.
Does this have the ability to upload more than one picture per profile? I am dying for a solution to make this happen.
no, it doesn’t
Andrew,
I just installed this – and it appears to be be working although I did not edit the profile.php (when I did it caused syntax errors).
Is there a way to get the photos to show up in a sidebar?
Thanks for this plugin!
Tina
@Tina
With a little bit of coding, it should be pretty easy to get the photos to show up in the sidebar.
If you would be interested in financially sponsoring that development, let me know.
huge thanks for plugin!
It’s a great idea, I’ve just never really understood why this isn’t part of the core as an option.
Concerning your plugin, have you investigated is there a possibility to add option to an user profile without modifying the core? Send the plugin to the developement team, you never know, it might get accepted.
@Toni L
I haven’t done any work on this plugin since WordPress 2.1 was released. At the time, there was no way to interface without hacking (i.e. mod-ing) the core. However, I would imagine that there are some new hooks that could be used. Unfortunately, I don’t have the time to continue to develop this on my own time, unless someone where to sponsor development.
Pingback: links for 2010-09-10
Pingback: Adding User Photo to WordPress User Profile | Andrew Ferguson
Am pus codul in profile.php, si la profil a aparut adauga foto, dar nu pot incarca foto, primesc mesajul de eroare(Error: Please only upload jpg files!) cu toate ca imaginea mea e .jpg
Eu nu lipi?i codul din exemplul dvs. (poate asta e problema), deoarece nu am ?tiut unde s?-l pun?
Te rog ajuta ma sa inteleg unde sa il pun
I put the code in profile.php, and appeared to profile add photos, but I can not upload photos, get the error message (Error: Please only upload jpg files!) although my image is. jpg
I do not paste the code from your example (maybe that’s the problem) because I did not know where to put it?
Please help me understand where to put it
@costel:
Please see:
https://andrewferguson.net/wordpress-plugins/add-user-photo/comment-page-7/#comment-257564
Hello Andrew,
I was wondering how can I add the photo to the author.php page, I was using user photo, which had a couple of commands that I could add to call the photo.
* userphoto_the_author_photo()
* userphoto_the_author_thumbnail()
* userphoto_comment_author_photo()
* userphoto_comment_author_thumbnail()
Do you have similar commands for your plugin?
Also, I have over 200 people in my company. I was wondering if I have your plugin installed, and I place all 200 photos in the images folder will it let them be associated to that person. or will I need to go into each persons profile and upload the photo for them.
Thanks,
Aaron
@Aaron:
I haven’t done much with this code recently. The code really just serves to provide a couple of hooks to make it easier to upload the data and leaves it up to you to develop the code to bring back out.
Take a look at previous comments; if you still need help developing the code, I am available for hire at very reasonable rates.
Hello Andrew,
I have tried implementing as you suggested; however, I do not have a line 21. and when I try changing line 61 to
if(1){
and then I try uploading a photo it goes through the motions, but no image is uploaded.Before, it gave me the same error that Aike had, Error: Please only upload jpg files! Your content type is.
Do you know how I can get it to upload?
Thanks,
Aaron
@Aaron:
As listed above, please note the compatibility of this plugin is only for:
If you need help updating the code for a current version of WordPress, I am available for hire at very reasonable rates.
Hi Andrew,
Could you update your plugin and add a simple JQuery to replace the form encrypt
$('form#your-profile').attr((this.encoding ? 'encoding' : 'enctype') , 'multipart/form-data');
and that way users wont have to edit core files.
Bainternet.
@bainternet:
I haven’t worked on this code for sometime. I should probably update this page to mention that I’ve unfortunately had to abandon this code. Part of the reason is that this code came from project that I now longer work on, the other part is that I just don’t have enough time to maintain this code for free.
If you need help updating the code for a current version of WordPress (which could include implementing jQuery), I am available for hire at very reasonable rates.
I would also encourage you to fork the code and create your own version.
Pingback: User Profiles in WordPress ? I Love WordPress
Pingback: Profil Pengguna di WordPress ? Aku Cinta WordPress
Can i get plugins for this?
Pingback: WordPress Plugins for Multiple Blogger Blogs « Lorelle on WordPress