-
-
Save rifkyfu32/7ec5b89358469f921fb6b0902ff945ea to your computer and use it in GitHub Desktop.
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! |
Line: 1862-1949, enjoy! Thank you again ;)!
When I paste code into the um-short-functions.php file my site starts throwing a 502 error. Does this code still work with the latest version of ultimate member?
Thanks!
When I paste code into the um-short-functions.php file my site starts throwing a 502 error. Does this code still work with the latest version of ultimate member?
Thanks!
Yes, it works with 2.1.6
Hello there, I am new to PHP, I am also facing some problem. I have followed all steps as it is written, but when I paste code in um_short_functions.php file, my site shows an error which is "There has been a critical error on your website."
i have commented all function in um-short-function.php file and changed with above code. but picture is not uploading there. where i am wrong????
For new version of UM:
function um_get_avatar_uri( $image, $attrs ) {
$uri = false;
$uri_common = false;
$find = false;
$ext = '.' . pathinfo( $image, PATHINFO_EXTENSION );
$custom_profile_photo = get_user_meta(um_user( 'ID' ), 'profile_photo', 'true');
if ( is_multisite() ) {
//multisite fix for old customers
$multisite_fix_dir = UM()->uploader()->get_upload_base_dir();
$multisite_fix_url = UM()->uploader()->get_upload_base_url();
$multisite_fix_dir = str_replace( DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $multisite_fix_dir );
$multisite_fix_url = str_replace( '/sites/' . get_current_blog_id() . '/', '/', $multisite_fix_url );
if ( $attrs == 'original' && file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}";
} elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}";
} elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/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( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}";
} elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}";
} elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
$uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}";
}
}
}
if ( $attrs == 'original' && file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . "/profile_photo{$ext}";
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $custom_profile_photo ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $custom_profile_photo;
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}";
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/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()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}";
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}";
} elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) {
$uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo{$ext}";
}
}
if ( ! empty( $uri_common ) && empty( $uri ) ) {
$uri = $uri_common;
}
$cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) );
if ( ! empty( $cache_time ) ) {
$uri .= "?{$cache_time}";
}
return $uri;
}
Kudos This was extremely helpful. Thank you so much
For new version of UM:
function um_get_avatar_uri( $image, $attrs ) { $uri = false; $uri_common = false; $find = false; $ext = '.' . pathinfo( $image, PATHINFO_EXTENSION ); $custom_profile_photo = get_user_meta(um_user( 'ID' ), 'profile_photo', 'true'); if ( is_multisite() ) { //multisite fix for old customers $multisite_fix_dir = UM()->uploader()->get_upload_base_dir(); $multisite_fix_url = UM()->uploader()->get_upload_base_url(); $multisite_fix_dir = str_replace( DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $multisite_fix_dir ); $multisite_fix_url = str_replace( '/sites/' . get_current_blog_id() . '/', '/', $multisite_fix_url ); if ( $attrs == 'original' && file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}"; } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}"; } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/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( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}"; } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}"; } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}"; } } } if ( $attrs == 'original' && file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . "/profile_photo{$ext}"; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $custom_profile_photo ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $custom_profile_photo; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}"; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/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()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}"; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}"; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo{$ext}"; } } if ( ! empty( $uri_common ) && empty( $uri ) ) { $uri = $uri_common; } $cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) ); if ( ! empty( $cache_time ) ) { $uri .= "?{$cache_time}"; } return $uri; }
I don't know PHP.
I paste this code on 'code snippet' plugin, it shows the error "Cannot redeclare function um_get_avatar_uri"
"The snippet has been deactivated due to an error on line 2:
Cannot redeclare function um_get_avatar_uri"
What's the problem???
For new version of UM:
function um_get_avatar_uri( $image, $attrs ) { $uri = false; $uri_common = false; $find = false; $ext = '.' . pathinfo( $image, PATHINFO_EXTENSION ); $custom_profile_photo = get_user_meta(um_user( 'ID' ), 'profile_photo', 'true'); if ( is_multisite() ) { //multisite fix for old customers $multisite_fix_dir = UM()->uploader()->get_upload_base_dir(); $multisite_fix_url = UM()->uploader()->get_upload_base_url(); $multisite_fix_dir = str_replace( DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $multisite_fix_dir ); $multisite_fix_url = str_replace( '/sites/' . get_current_blog_id() . '/', '/', $multisite_fix_url ); if ( $attrs == 'original' && file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}"; } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}"; } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/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( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}"; } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}"; } elseif ( file_exists( $multisite_fix_dir . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) { $uri_common = $multisite_fix_url . um_user( 'ID' ) . "/profile_photo{$ext}"; } } } if ( $attrs == 'original' && file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . "/profile_photo{$ext}"; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $custom_profile_photo ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . $custom_profile_photo; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$attrs}x{$attrs}{$ext}"; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$attrs}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/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()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}x{$find}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}x{$find}{$ext}"; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo-{$find}{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}"; } elseif ( file_exists( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . "profile_photo{$ext}" ) ) { $uri = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . "/profile_photo{$ext}"; } } if ( ! empty( $uri_common ) && empty( $uri ) ) { $uri = $uri_common; } $cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) ); if ( ! empty( $cache_time ) ) { $uri .= "?{$cache_time}"; } return $uri; }
I don't know PHP.
I paste this code on 'code snippet' plugin, it shows the error "Cannot redeclare function um_get_avatar_uri""The snippet has been deactivated due to an error on line 2:
Cannot redeclare function um_get_avatar_uri"What's the problem???
You must replace existing function, do not add code - replace...
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.
Thank you but could you mention clearly which lines we should replace?