In my previous topic i tried to find a way to use Google Avatar and Ultimate Member integrated.
This is the code i have so far:
/*##################################################################
# Integrate Ultimate Member and Google Profile Avatars plugins #
##################################################################*/
// Part 1: Add 'google_avatar' user meta with default value of true
// define the um_registration_set_extra_data callback
function my_registration_set_extra_data( $user_id, $args ) {
add_user_meta( $user_id, 'google_avatar', 'Use Google Avatar', true );
return $user_id;
}
// add the action
add_action( 'um_registration_set_extra_data', 'my_registration_set_extra_data', 10, 2 );
// Part 2: Resolve which avatar to return
// define the um_user_avatar_url_filter callback
function filter_um_user_avatar_url_filter( $um_avatar_url, $user_id ) {
$google_avatar_url = get_user_meta( $user_id, 'gpa_user_avatar', true );
$use_google_avatar = ! empty(get_user_meta( $user_id, 'google_avatar', true ));
// user has Google avatar?
if( ! empty( $google_avatar_url ) ){
// user marked 'Use Google Avatar' in profile? (marked true by default)
if( $use_google_avatar ) {
// return Google avatar
return $google_avatar_url;
} else {
// return UM avatar
return $um_avatar_url;
}
}
// return UM avatar
return $um_avatar_url;
};
// add the filter
add_filter( 'um_user_avatar_url_filter', 'filter_um_user_avatar_url_filter', 10, 2 );
Now all i have left to do is to fire an action once the user uploads an avatar via the UM profile page, this action will set the user meta of google_avatar
to false (the default is to use the Google Avatar, but once a user uploads his own avatar it means he would like to use it and not the Google one).
I’m looking for some hook that i can use to do this action once a user uploads an avatar but i couldn’t find it in the hooks list nor the code itself.
Is there a good way to achieve this functionality?