Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ultimate Member - Allow everyone to upload profile and cover photos on front-end pages.
/**
* 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
}
@DaveGarlock

This comment has been minimized.

Copy link

@DaveGarlock DaveGarlock commented Mar 20, 2017

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!

@deadlinkd

This comment has been minimized.

Copy link

@deadlinkd deadlinkd commented Sep 1, 2017

Hi,

  1. Copy the above code in your theme's function.php file. Should be in public_html/wp-content/themes/your-themes-name/function.php
  2. In ultimate member add 'upload image' field in registration form.
  3. Enter meta key as 'userphoto' (i.e same as in the code above)
  4. Profit.
@Tebbott

This comment has been minimized.

Copy link

@Tebbott Tebbott commented Oct 12, 2017

Cant get this working - any ideas if there're changes to the above code, required because of a recent update?

@haydnjames

This comment has been minimized.

Copy link

@haydnjames haydnjames commented Apr 4, 2018

This kinda works, but doesn't. It works on a single registration form, but doesn't work with other forms.

@notechup

This comment has been minimized.

Copy link

@notechup notechup commented May 1, 2018

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!

@champsupertramp

This comment has been minimized.

Copy link
Owner Author

@champsupertramp champsupertramp commented Aug 21, 2018

@gitblair Are you talking about this code snippet?

@luisrafael-octaviano

This comment has been minimized.

Copy link

@luisrafael-octaviano luisrafael-octaviano commented Aug 23, 2018

@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.

@sebastianBreuer

This comment has been minimized.

Copy link

@sebastianBreuer sebastianBreuer commented Aug 27, 2018

@lugioctavio yes it is deprecated. UM changed a lot from 1.x to 2.x.

@TandemBuilt

This comment has been minimized.

Copy link

@TandemBuilt TandemBuilt commented Sep 5, 2018

@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

This comment has been minimized.

Copy link

@gitblair gitblair commented Sep 15, 2018

@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.

@bradfranklin

This comment has been minimized.

Copy link

@bradfranklin bradfranklin commented Sep 26, 2018

Trying to figure this out too

@bradfranklin

This comment has been minimized.

Copy link

@bradfranklin bradfranklin commented Sep 30, 2018

Just posted this question on the UM support forum. Hopefully we’ll get a reply. Will keep everyone posted.

https://wordpress.org/support/topic/um-registration-form-upload-profile-image-background-image-on-registration/

@Carmichaeldb

This comment has been minimized.

Copy link

@Carmichaeldb Carmichaeldb commented Apr 23, 2019

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.

@champsupertramp

This comment has been minimized.

Copy link
Owner Author

@champsupertramp champsupertramp commented Jun 2, 2019

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,

@alybyerly

This comment has been minimized.

Copy link

@alybyerly alybyerly commented Jul 15, 2019

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!!

@champsupertramp

This comment has been minimized.

Copy link
Owner Author

@champsupertramp champsupertramp commented Apr 26, 2020

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,

@askmemobile

This comment has been minimized.

Copy link

@askmemobile askmemobile commented Jul 3, 2020

Can any one send me the code to add cover photo

@nishani7234

This comment has been minimized.

Copy link

@nishani7234 nishani7234 commented Dec 11, 2020

Hi,

  1. Copy the above code in your theme's function.php file. Should be in public_html/wp-content/themes/your-themes-name/function.php
  2. In ultimate member add 'upload image' field in registration form.
  3. Enter meta key as 'userphoto' (i.e same as in the code above)
  4. Profit.

Hi,
This is working fine.
But when updating the ultimate member plugin, user profile picture removed. Please help me.

@AzmayenFayek

This comment has been minimized.

Copy link

@AzmayenFayek AzmayenFayek commented Aug 19, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment