Site icon Hip-Hop Website Design and Development

Consumer avatar-ACF fields

I am operating wp multisite and utilizing ACF customized discipline (person edit) for my native avatar, in my capabilities.php i added :

add_action('get_avatar', 'tsm_acf_profile_avatar', 10, 3);
perform tsm_acf_profile_avatar( $avatar, $id_or_email, $dimension, $default, $alt ) {

$person = '';

// Get person by id or e-mail
if ( is_numeric( $id_or_email ) ) {

    $id   = (int) $id_or_email;
    $person = get_user_by( 'id' , $id );


} elseif ( is_object( $id_or_email ) ) {

    if ( ! empty( $id_or_email->user_id ) ) {
        $id   = (int) $id_or_email->user_id;
        $person = get_user_by( 'id' , $id );
    }

} else {
    $person = get_user_by( 'e-mail', $id_or_email );
}

if ( ! $person ) {
    return $avatar;
}

// Get the person id
$user_id = $user->ID;

// Get the file id
$image_id = get_user_meta($user_id, 'avatar', true); // CHANGE TO YOUR FIELD NAME

// Bail if we do not have a neighborhood avatar
if ( ! $image_id ) {
    return $avatar;
}

// Get the file dimension
$image_url  = wp_get_attachment_image_src( $image_id, 'thumbnail' ); // Set picture dimension by title
// Get the file url
$avatar_url = $image_url[0];
// Get the img markup
$avatar = '<img alt="' . $alt . '" src="' . $avatar_url . '" class="avatar avatar-' . $dimension . '" peak="' . $dimension . '" width="' . $dimension . '"/>';

// Return our new avatar
return $avatar;
 }

This works nice on foremost weblog (weblog 1), however downside is when i add that customers on subsite(weblog 2), my avatar discipline is empty in weblog 2, additionally after that, if I add avatar on weblog 2, then similar person on weblog 1 get some random picture of some random person.

I’ve no clue why that is taking place, any assistance is welcome.

Thanks