Last active
September 25, 2015 11:23
-
-
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
This file contains hidden or 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 | |
// 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 |
This file contains hidden or 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 | |
// 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