dimanche 24 mars 2019

WordPress custom random avatar based on user email

I'm using this snippet to replace default gravatars for users on my WordPress installation.

add_filter( 'pre_option_avatar_default', 'space_default_avatar' );

function space_default_avatar ( $value )
{
    $upload_dir = wp_get_upload_dir();
    return trailingslashit( $upload_dir['baseurl'] ) . '/custom-images/avatares-espacio/avatar-espacio'.rand( 0 , 31 ).'.jpg';
}

But this randomizes the images on every page load.

I need to define an image based on the user email, so it will always look the after reloading the page.

I also tried this other code, but it's not working: https://shibashake.com/wordpress-theme/wordpress-gravatars-use-your-own-default-avatar




Aucun commentaire:

Enregistrer un commentaire