Created
June 2, 2019 13:15
-
-
Save champsupertramp/a7ce812c702865cb973445c9fe7a9544 to your computer and use it in GitHub Desktop.
Ultimate Member 2.0 - Add Profile Photo in Register Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add new predefined field "Profile Photo" in UM Form Builder. | |
*/ | |
add_filter("um_predefined_fields_hook","um_predefined_fields_hook_profile_photo", 99999, 1 ); | |
function um_predefined_fields_hook_profile_photo( $arr ){ | |
$arr['profile_photo'] = array( | |
'title' => __('Profile Photo','ultimate-member'), | |
'metakey' => 'profile_photo', | |
'type' => 'image', | |
'label' => __('Change your profile photo','ultimate-member'), | |
'upload_text' => __('Upload your photo here','ultimate-member'), | |
'icon' => 'um-faicon-camera', | |
'crop' => 1, | |
'max_size' => ( UM()->options()->get('profile_photo_max_size') ) ? UM()->options()->get('profile_photo_max_size') : 999999999, | |
'min_width' => str_replace('px','',UM()->options()->get('profile_photosize')), | |
'min_height' => str_replace('px','',UM()->options()->get('profile_photosize')), | |
); | |
return $arr; | |
} | |
/** | |
* Multiply Profile Photo with different sizes | |
*/ | |
add_action( 'um_registration_set_extra_data', 'um_registration_set_profile_photo', 9999, 2 ); | |
function um_registration_set_profile_photo( $user_id, $args ){ | |
if ( empty( $args['custom_fields'] ) ) return; | |
if( ! isset( $args['form_id'] ) ) return; | |
if( ! isset( $args['profile_photo'] ) || empty( $args['profile_photo'] ) ) return; | |
// apply this to specific form | |
//if( $args['form_id'] != 12345 ) return; | |
$files = array(); | |
$fields = unserialize( $args['custom_fields'] ); | |
$user_basedir = UM()->uploader()->get_upload_user_base_dir( $user_id, true ); | |
$profile_photo = get_user_meta( $user_id, 'profile_photo', true ); | |
$image_path = $user_basedir . DIRECTORY_SEPARATOR . $profile_photo; | |
$image = wp_get_image_editor( $image_path ); | |
$file_info = wp_check_filetype_and_ext( $image_path, $profile_photo ); | |
$ext = $file_info['ext']; | |
$new_image_name = str_replace( $profile_photo, "profile_photo.".$ext, $image_path ); | |
$sizes = UM()->options()->get( 'photo_thumb_sizes' ); | |
$quality = UM()->options()->get( 'image_compression' ); | |
if ( ! is_wp_error( $image ) ) { | |
$max_w = UM()->options()->get('image_max_width'); | |
if ( $src_w > $max_w ) { | |
$image->resize( $max_w, $src_h ); | |
} | |
$image->save( $new_image_name ); | |
$image->set_quality( $quality ); | |
$sizes_array = array(); | |
foreach( $sizes as $size ){ | |
$sizes_array[ ] = array ('width' => $size ); | |
} | |
$image->multi_resize( $sizes_array ); | |
delete_user_meta( $user_id, 'synced_profile_photo' ); | |
update_user_meta( $user_id, 'profile_photo', "profile_photo.{$ext}" ); | |
@unlink( $image_path ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello @champsupertramp it show in registration form
but not shown in member direcories frontend no what to do??