I'm using basic user avatars for use local avatar in wordpress. And i have a simple function in my functions.php for getting avatar direct link. My problem is if i use get_avatar function in my functions php it returns gravatar img but if i use get_avatar function in my frontend pages it returns local avatars. Here is plugins's code
public function __construct() {
// Text domain
$this->load_textdomain();
// Actions
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) );
add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) );
add_action( 'personal_options_update', array( $this, 'edit_user_profile_update' ) );
add_action( 'edit_user_profile_update', array( $this, 'edit_user_profile_update' ) );
add_action( 'bbp_user_edit_after_about', array( $this, 'bbpress_user_profile' ) );
// Shortcode
add_shortcode( 'basic-user-avatars', array( $this, 'shortcode' ) );
// Filters
add_filter( 'get_avatar', array( $this, 'get_avatar' ), 10, 5 );
add_filter( 'avatar_defaults', array( $this, 'avatar_defaults' ) );
}
public function get_avatar( $avatar = '', $id_or_email, $size = 96, $default = '', $alt = false ) {
// Determine if we recive an ID or string
if ( is_numeric( $id_or_email ) )
$user_id = (int) $id_or_email;
elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) )
$user_id = $user->ID;
elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) )
$user_id = (int) $id_or_email->user_id;
if ( empty( $user_id ) )
return $avatar;
$local_avatars = get_user_meta( $user_id, 'basic_user_avatar', true );
if ( empty( $local_avatars ) || empty( $local_avatars['full'] ) )
return $avatar;
$size = (int) $size;
if ( empty( $alt ) )
$alt = get_the_author_meta( 'display_name', $user_id );
$author_class = is_author( $user_id ) ? ' current-author' : '' ;
$avatar = "<img alt='" . esc_attr( $alt ) . "' src='" . $local_avatars['full'] . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";
return apply_filters( 'basic_user_avatar', $avatar );
}
I tried to use lower priority in add_filter('get_avatar') but if i use lower priority plugis not working. Probably because apply_filters in return statement. But i don't know what is problem exactly. How can i fix this problem? Thanks