Skip to:
Content
Pages
Categories
Search
Top
Bottom

Avatar images on 3rd party plugin


  • tkuron
    Participant

    @tkuron

    Hi!

    I’m having an issue; my plugin does use get_avatar_data()-function to get user’s avatar image URL for the GUI – but all I get from that function is URL to user’s Gravatar image. But on users-page (dashboard view) there is a local avatar (from BuddyPress).

    So, how I can get my plugin to show the local avatar instead of Gravatar file?

    I’m gettin a bit frustrated with this issue…

Viewing 6 replies - 1 through 6 (of 6 total)

  • Henry Wright
    Moderator

    @henrywright

    You could disable Gravatar?

    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );


    tkuron
    Participant

    @tkuron

    That does not seems to help me with this issue… I still get the Gravater image. I don’t have a foggiest idea why it does do that on my plugin.


    Henry Wright
    Moderator

    @henrywright

    If it’s a BuddyPress page then I guess the bp_core_fetch_avatar() function should display the local avatar if no Grav exists. Are you saying this doesn’t happen?


    tkuron
    Participant

    @tkuron

    I managed to fix the issue.

    Apparently BuddyPress does not change the avatar url when get_avatar_data() -function is called. I managed to fix the issue by adding following piece of script to my plugin’s source code:

    <?php
    add_filter("get_avatar_data", function($args, $id_or_email){
    	$bp_avatar_url = bp_core_fetch_avatar([
    			"html" => false,
    			"item_id" => $id,
    			"type" => "full",
    			"width" => $args["size"],
    			"height" => $args["size"]
    	]);
    	
    	$bp_avatar_url = htmlspecialchars_decode($bp_avatar_url);
    	$args["url"] = $bp_avatar_url;
    			
    	return $args;
    }, 10, 2);
    ?>

    Henry Wright
    Moderator

    @henrywright

    Nice solution @tkuron!


    Henry Wright
    Moderator

    @henrywright

    Maybe there’s a catch to using that, I haven’t checked but make sure the avatars on this page aren’t impacted:

    https://example.com/wp-admin/options-discussion.php

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar