我可能已经找到了解决办法。这似乎有用,但也许我错过了什么?
function custom_user_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
$user = false;
if ( is_numeric( $id_or_email ) ) {
$id = (int) $id_or_email;
$user = get_user_by( \'id\' , $id );
} else if ( is_object( $id_or_email ) ) {
if ( ! empty( $id_or_email->user_id ) ) {
$id = (int) $id_or_email->user_id;
$user = get_user_by( \'id\' , $id );
}
} else {
$user = get_user_by( \'email\', $id_or_email );
}
if ( $user && is_object( $user ) ) {
if ( $user->data->ID == \'1\' ) {
$avatar = sprintf( \'%s/images/avatar/support-male.png\', get_stylesheet_directory_uri() );
$avatar = "<img alt=\'{$alt}\' src=\'{$avatar}\' class=\'avatar avatar-{$size} photo\' height=\'{$size}\' width=\'{$size}\' />";
}
else if ( $user->data->ID == \'200\' ) {
$avatar = sprintf( \'%s/images/avatar/support-female.png\', get_stylesheet_directory_uri() );
$avatar = "<img alt=\'{$alt}\' src=\'{$avatar}\' class=\'avatar avatar-{$size} photo\' height=\'{$size}\' width=\'{$size}\' />";
}
else {
$avatar = sprintf( \'%s/images/avatar/default.png\', get_stylesheet_directory_uri() );
$avatar = "<img alt=\'{$alt}\' src=\'{$avatar}\' class=\'avatar avatar-{$size} photo\' height=\'{$size}\' width=\'{$size}\' />";
}
}
return $avatar;
}
add_filter( \'get_avatar\' , \'custom_user_avatar\' , 1 , 5 );