I have been following goldenapples front end file uploads tutorial, however i do have that working for my frontend posting page, but what i am wanting to accomplish now is to add an image from edit profile page (again this is a frontend file upload scenario.
In theme functions.php i have:
function insert_complogo($file_handler,$user_id,$setthumb='false') {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload( $file_handler, $user_id );
if ($setthumb) update_usermeta($user_id,'_thumbnail_id',$attach_id);
return $attach_id;
}
In my profile-edit.php at the top i have:
if ($_FILES) {
foreach ($_FILES as $file => $array) {
$newupload = insert_complogo($file,$user_id);
}
}
also this:
if ( !empty( $_POST['authorphoto'] ) )
update_usermeta( $current_user->id, 'comp_logo', esc_attr($_POST['comp_logo'] ) );
and my input type is:
<p>
<label><?php _e('Add Company Logo', 'comp_logo') ?></label><br />
<input type="file" name="comp_logo" id="comp_logo" value="Upload Logo" size="50" />
</p>
As you can tell from the first three blocks of code above i have changed post_id references to user_id,
Now the upload of the company logo does work, however even using user_id and update_usermeta the info is being saved into wp_postmeta table which is not where i want it to be as i need to pull the info from wp_usermeta to populate the author.php page.
So my question (got there eventualy) is why when im using update_usermeta is the attachment info going into wp_postmeta, im guessing its because codex says that image attachments are a type of post so no matter what that is where they go, but how can i get that image from wp_postmeta and associate it with the correct author?
the problem is in this line :
when you use media_handle_upload and provide a second parameter (which in your case you do) the the attachment is associated with a post that has that ID, so basically WordPress thinks your are telling it to save this as an attachment to a post which has the same id as the user and that is way it is saved in the postmeta table.
now the quick fix is to remove
$user_id
from that line:next I’m pretty sure that this part does nothing:
since input fields with
type="file"
are not included in$_POST
but in$_FILES
.and to display the image on the author template you can use
wp_get_attachment_image_src
something like this:
Actually got around it by making a plugin that can either shortcode a hook into a user edit page from frontend or by using a seperate shortcode in a sidebar. Below is the crux of it, just need to do some bits and bobs with the error reporting.