How to get profile user id when uploading image via media uploader on profile page
Question
I have a PlugIn which lets a user upload an image to a user profile in the backend. Now I want to access the user id in the uploader to change the filename of the uploaded image.
On the user profile edit page, I get the id via global $profileuser
. But when I access it in a function I added as a filter to wp_handle_upload
, $profileuser is empty.
Any ideas how to get the profile user (not the logged in user) in this case?
This is my code:
add_filter('wp_handle_upload_prefilter', 'my_pre_upload', 2);
function my_pre_upload($file){
// get current user
global $profileuser;
$myAuthorImg = get_userdata( $profileuser->ID );
$myAuthorImg = 'author-' . $myAuthorImg . '.jpg";
$file['name'] = $myAuthorImg
return $file;
}
0
profiles, uploads, users
4 years
2020-02-23T08:38:33-05:00
2020-02-23T08:38:33-05:00 0 Answers
112 views
0
Leave an answer