Allows adding a photo to a user profile
- 1.5 (in theory, not tested)
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
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">
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.
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.