Last active
November 30, 2021 22:03
-
-
Save rifkyfu32/7ec5b89358469f921fb6b0902ff945ea to your computer and use it in GitHub Desktop.
Customization allow everyone to upload profile on registration pages - Ultimate Member 2.0 +
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
1.Copy the bellow code in your theme's function.php file. Should be in public_html/wp-content/themes/your-themes-name/function.php | |
/** | |
* Ultimate Member 2.0 - Customization | |
* Description: Allow everyone to upload profile registration 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 == "user_photo" ){ | |
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 | |
} | |
/* End of customization in your theme's function.php file*/ | |
2. In ultimate member add 'upload image' field in registration form. Enter meta key as 'user_photo' (i.e same as in the code above). | |
3. Edit file um-short-functions.php. Should be in /public_html/wp-content/plugins/ultimate-member/includes/um-short-functions.php. In line 1760 function um_get_avatar_uri( $image, $attrs ) change with code below : | |
/** | |
* Ultimate Member 2.0 - Customization | |
* Description: Change path image with $custom_profile_photo data from get_user_meta. | |
*/ | |
function um_get_avatar_uri( $image, $attrs ) { | |
$uri = false; | |
$find = false; | |
$ext = '.' . pathinfo( $image, PATHINFO_EXTENSION ); | |
$custom_profile_photo = get_user_meta(um_user( 'ID' ), 'profile_photo', 'true'); | |
$cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) ); | |
if( $attrs == 'original' && file_exists( um_user_uploads_dir() . "profile_photo{$ext}" ) ) { | |
$uri = um_user_uploads_uri() . "profile_photo{$ext}"; | |
} else if ( file_exists( um_user_uploads_dir() . $custom_profile_photo ) ) { | |
$uri = um_user_uploads_uri() . $custom_profile_photo; | |
} else if ( file_exists( um_user_uploads_dir() . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) { | |
$uri = um_user_uploads_uri() . "profile_photo-{$attrs}x{$attrs}{$ext}"; | |
} else if ( file_exists( um_user_uploads_dir() . "profile_photo-{$attrs}{$ext}" ) ) { | |
$uri = um_user_uploads_uri() . "profile_photo-{$attrs}{$ext}"; | |
} else { | |
$sizes = UM()->options()->get( 'photo_thumb_sizes' ); | |
if ( is_array( $sizes ) ) $find = um_closest_num( $sizes, $attrs ); | |
if ( file_exists( um_user_uploads_dir() . "profile_photo-{$find}x{$find}{$ext}" ) ) { | |
$uri = um_user_uploads_uri() . "profile_photo-{$find}x{$find}{$ext}"; | |
}else if ( file_exists( um_user_uploads_dir() . "profile_photo-{$find}{$ext}" ) ) { | |
$uri = um_user_uploads_uri() . "profile_photo-{$find}{$ext}"; | |
} else if ( file_exists( um_user_uploads_dir() . "profile_photo{$ext}" ) ) { | |
$uri = um_user_uploads_uri() . "profile_photo{$ext}"; | |
} | |
} | |
if ( !empty( $cache_time ) ) { | |
$uri .= "?{$cache_time}"; | |
} | |
return $uri; | |
} | |
/* End of customization in um-short-functions.php file*/ | |
4. Enjoy it! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I change the directory of profile photos from "wp-content/uploads/ultimatemember" file to wordpress media library during uploading. So that I can use those image later on directly taking from media.