Skip to content

Instantly share code, notes, and snippets.

@max-kk
Created March 13, 2016 11:34
Show Gist options
  • Save max-kk/ace5d63ce5cb724aa1ed to your computer and use it in GitHub Desktop.
Save max-kk/ace5d63ce5cb724aa1ed to your computer and use it in GitHub Desktop.
Wordpress: How to filter & replace user avatar based on meta filed (where saved avatar attachment_id).
<?php
function custom_modify_get_avatar($args, $id_or_email) {
$avatar_att_id = get_user_meta( get_current_user_id(), '_avatar_att_id', true );
if($avatar_att_id) {
$avatar_att_url = wp_get_attachment_image_src($avatar_att_id, array($args['width'], $args['height']));
if ( !empty($avatar_att_url) ) {
$args['url'] = $avatar_att_url[0];
}
}
return $args;
}
add_filter('pre_get_avatar_data', 'custom_modify_get_avatar', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment