Skip to content

Instantly share code, notes, and snippets.

@mauriciogofas
Last active September 25, 2015 11:23
Show Gist options
  • Save mauriciogofas/e8f8a193d6f317c8bc71 to your computer and use it in GitHub Desktop.
Save mauriciogofas/e8f8a193d6f317c8bc71 to your computer and use it in GitHub Desktop.
Custom Avatar via Advanced Custom Fields Image Upload and Front End Profile Image Upload
<?php
// Custom Avatar via Advanced Custom Fields Image Upload
add_filter( 'get_avatar' , 'gofas_custom_avatar', 1, 5 );
function gofas_custom_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
$image_object = get_field('your_image_field_id', 'user_'.$id_or_email);
$image_size = 'thumbnail';
$acf_avatar = $image_object['sizes'][$image_size]; // Configure ACF Image to return Image Object
if ( $image_object ) {
$avatar = $acf_avatar; // ACF Avatar
$avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
return $avatar;
}
// End Custom Avatar via Advanced Custom Fields Image Upload
<?php
// Form Upload in front end for Custom Avatar via Advanced Custom Fields Image Upload
$user_ID = get_current_user_id();
$post_id = 'user_' . $user_ID; // Define Form target to Current User
acf_form(array(
'field_groups' => array( 532 ), // ID For the Group Of Fields
'fields' => 'your_image_field_id',
'submit_value' => __("Update Image", 'acf'),
'updated_message' => __("Image updated", 'acf'),
'post_id' => $post_id,
));
// Form Upload in front end for Custom Avatar via Advanced Custom Fields Image Upload
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment