WordPress Snippet
-
-
Save ControlledChaos/cd6558219cfbc0a75d6f to your computer and use it in GitHub Desktop.
Use a local avatar with Advanced Custom Fields image field.
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
<?php | |
function ccd_acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) { | |
$user = is_numeric( $id_or_email ) ? get_user_by( 'id', $id_or_email ) : get_user_by( 'email', $id_or_email ); | |
$user_id = $user->ID; | |
$image_id = get_user_meta( $user_id, 'tsm_local_avatar', true ); | |
$avatar_url = get_stylesheet_directory_uri() . '/images/default_avatar.png'; | |
if ( $image_id ) { | |
$image_url = wp_get_attachment_image_src( $image_id, 'thumbnail' ); | |
$avatar_url = $image_url[0]; | |
} | |
$avatar = '<img alt="' . $alt . '" src="' . $avatar_url . '" class="avatar avatar-' . $size . '" height="' . $size . '" width="' . $size . '"/>'; | |
return $avatar; | |
} | |
add_filter( 'get_avatar', 'ccd_acf_profile_avatar', 10, 5 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment