-
The get_avatar filter accepts 6 parameters, not 5.
-
The $id_or_email can also be an instance of
WP_Post
,WP_User
or a md5 hash string. So it’s better to extract$user_id
like this:
if ( is_numeric( $id_or_email ) ) {
$user_id = $id_or_email;
} elseif ( is_string($id_or_email) ) {
if ( is_email($id_or_email) ) {
$user = get_user_by('email', $id_or_email);
$user_id = $user->ID;
} else { // md5 hash string
// Do something.
}
} elseif ( is_object($id_or_email) ) {
if ($id_or_email instanceof \WP_User) {
$user_id = $id_or_email->ID;
} elseif ($id_or_email instanceof \WP_Post) {
$user_id = $id_or_email->post_author;
} else {
$user_id = $id_or_email->user_id;
}
} else {
return $avatar;
}
- Make sure the
get_user_meta( $user_id, 'basic_user_avatar', true )
return something. If nothing is returned, default$avatar
will be used.