When using the Ultimate Member plugin on WordPress, I encountered one difficult problem for me. I need the uploaded user image in his profile to turn into a link like: http://example.com/img/%username%.png
The path to %username%.png
is not important (the main thing is that it does not change), but I wanted so that the user’s uploaded image has a name that matches the username value. Tell me how this can be implemented, I’m new to PHP and know everything very superficially.
At the moment the link looks like:
https://example.com/um-download/6287/img/6/93059f79c9?t=1694944149
The only thing I could cling to is that the letter 6
is the user id.
2
Answers
The solution to my problem was literally the only shareware
file-renaming-on-upload
plan with such a functionality. In it, you can automate the renaming of files depending on {port} {username} {date} and so on. https://wordpress.org/plugins/file-renaming-on-upload/You may use the following code to change the filename of a
stream_photo
using the Ultimate Member Form’s Uploader field. This changes the filename to the current logged-in user’suser_login
value when you Upload with the uploader field that has a meta keysecond_profile_photo
:} );
This doesn’t change the download URL displayed in the Profile View but this let’s you generate the uploaded photo with your desired filename.
Further code explanation:
UM()->uploader()->upload_image_type
checks if the current uploading file is astream_photo
.Ultimate Member has 4 upload types:
profile_photo
,cover_photo
,stream_photo
andfile
. In your case, you only need thestream_photo
.This is the part that renames the filename with the current logged-in user’s
user_login
value: