-
-
Save champsupertramp/6b73195db24eb6650a23b4440b4287c3 to your computer and use it in GitHub Desktop.
/** | |
* Ultimate Member - Customization | |
* Description: Allow everyone to upload profile and cover photos on front-end pages. | |
*/ | |
add_filter("um_user_pre_updating_files_array","um_custom_user_pre_updating_files_array", 10, 1); | |
function um_custom_user_pre_updating_files_array( $arr_files ){ | |
if( is_array( $arr_files ) ){ | |
foreach( $arr_files as $key => $details ){ | |
if( $key == "userphoto" ){ | |
unset( $arr_files[ $key ] ); | |
$arr_files[ "profile_photo" ] = $details; | |
} | |
} | |
} | |
return $arr_files; | |
} | |
add_filter("um_allow_frontend_image_uploads","um_custom_allow_frontend_image_uploads",10, 3); | |
function um_custom_allow_frontend_image_uploads( $allowed, $user_id, $key ){ | |
if( $key == "profile_photo" ){ | |
return true; | |
} | |
return $allowed; // false | |
} |
Hi,
- Copy the above code in your theme's function.php file. Should be in public_html/wp-content/themes/your-themes-name/function.php
- In ultimate member add 'upload image' field in registration form.
- Enter meta key as 'userphoto' (i.e same as in the code above)
- Profit.
Cant get this working - any ideas if there're changes to the above code, required because of a recent update?
This kinda works, but doesn't. It works on a single registration form, but doesn't work with other forms.
I got it to work immediately, thanks!
But I see you also mention upload cover photo, have you done that as well? Would be great to upload that one as well during registration.
Thanks!
@gitblair Are you talking about this code snippet?
@champsupertramp I managed to make it work on ver 1.3.88 for our user registration page.
However, when I updated the plugin to version 2.0.25, the hook stopped working and it only renders the default placeholder photo. I'm not sure if this hook is already deprecated on the current version.
@lugioctavio yes it is deprecated. UM changed a lot from 1.x to 2.x.
@champsupertramp
I would love to hire you to rewrite this code for the newer versions of Ultimate Member (2.0 +). Connect back with me so that we can get this started.
@gitblair Are you talking about this code snippet?
Yes, thank you, this is the one. I'm reading now it's deprecated now because newer versions of UM will not allow it.
Trying to figure this out too
Just posted this question on the UM support forum. Hopefully we’ll get a reply. Will keep everyone posted.
Good Day all, I am using the code linked by @rifkyfu32 and trying to add the ability to change the profile photo to my account general page (where by default you change first name, last name, and email). I added a bunch of new fields to the account general page with the last one being the changing of the profile. The upload button appears and lets you upload a new photo but it isn't able to process it and update the users data under the key "user_photo " Here is the code with how I am doing this.
add_action('um_after_account_general', 'showExtraFields', 100);
function showExtraFields(){
$custom_fields = [
"birth_date" => "Birth Date",
"country" => "Country",
"genre_preference" => "Genre Preference",
"street_address" => "Street Address",
"city" => "City",
"province_state" => "Province or State",
"postal_zip" => "Postal/Zip Code",
"phone_number" => "Phone Number",
"profile_photo" => "Profile Picture",
];
$fields = [];
foreach ($custom_fields as $key => $value) {
$fields[$key] = array(
'title' => $value,
'metakey' => $key,
'type' => 'text',
'label' => $value,
'required' => 1,
'public' => 1,
'editable' => 1,
'validate' => $key
);
}
$id = um_user('ID');
$fields = apply_filters( 'um_account_secure_fields', $fields, $id );
UM()->builtin()->saved_fields = $fields;
UM()->builtin()->set_custom_fields();
foreach( $fields as $key => $data )
$output .= UM()->fields()->edit_field( $key, $data );
echo $output;
}
Ultimately I would love to be able to make the profile image that is on the right nav bar of the account pages to be clickable or have the upload button under it to change it there but after playing with the php code for several hours with no success I thought this was a better alternative in the mean time.
Hello @everyone - Here's the latest version of custom Upload Profile Photo for Ultimate Member 2.0:
https://gist.github.com/champsupertramp/a7ce812c702865cb973445c9fe7a9544
By the way, i will be accepting custom code requests on my website www.champ.ninja
Thank you,
Hey thanks for this code! I am having trouble getting the image to show as the profile image on the general account page. Also, is there a way to add an option on the general account page once you are logged in to change/update the profile image? Thanks!!
Hi Everyone,
I'll be sharing some Ultimate Member customizations & tutorials on my website: www.champ.ninja
Subscribe to my newsletter to get the latest tutorials.
Regards,
Can any one send me the code to add cover photo
Hi,
- Copy the above code in your theme's function.php file. Should be in public_html/wp-content/themes/your-themes-name/function.php
- In ultimate member add 'upload image' field in registration form.
- Enter meta key as 'userphoto' (i.e same as in the code above)
- Profit.
Hi,
This is working fine.
But when updating the ultimate member plugin, user profile picture removed. Please help me.
During upload it’s showing "the image is too large" but actually not a large image at all. I tried many sizes,resulations,formates.
Please help me to fix it.
Thanks in advance
I'm interested in adding profile photos as a field in the Ultimate Member register form, which it seems like this code might allow. However, I'm pretty hopeless when it comes to PHP - could you give any pointers on where to add this code, and if it will do what I want? When I tried adding it and using "profile_photo" as the meta key in an image upload, it gave me an error saying "Your meta key is a predefined reserved key and cannot be used. "Thanks!