Skip to content

Instantly share code, notes, and snippets.

@kimwhite
Forked from andrewlimaza/default-bua-avatar.php
Created October 26, 2023 12:48
Show Gist options
  • Save kimwhite/e22082236b0c3951be1c6a3238ae7fc5 to your computer and use it in GitHub Desktop.
Save kimwhite/e22082236b0c3951be1c6a3238ae7fc5 to your computer and use it in GitHub Desktop.
Default Basic User Avatar image when none is found
<?php
/**
* This assumes that Gravatar (or one of it's services is set as the default WP avatar option).
* Adjust this code and insert your own URL to the default avatar.
* Add this code to your site by following a guide like - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_bua_default_avatar_image( $avatar, $id_or_email ) {
if ( strpos( $avatar, 'gravatar.com' ) !== false ) {
$default_avatar = "https://URLTOIMAGE.COM/SOME-PATH/IMAGE.png"; // Change this to the URL for the default AVATAR.
$avatar = "<img src='$default_avatar' srcset='$default_avatar' alt='default avatar' class='avatar avatar-64 photo' height='64' width='64' loading='lazy' decoding='async'/>";
}
return $avatar;
}
add_filter( 'basic_user_avatar', 'my_bua_default_avatar_image', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment