BuddyDev

Search

BuddyPress avatar moderator – Disable placeholder photo?

  • Participant
    Level: Enlightened
    Posts: 42
    r08 on #36481

    BuddyPress avatar moderator –
    This plugin has an option for a placeholder avatar. Is there a way to disable this?

    The reason is that I am using Member Types Pro which already sets up a default avatar if the user doesn’t submit one. Each different Profile Type gets a different default avatar. That’s the avatar that should show up if they don’t have one.

    So if they submit an avatar it should just show that default avatar instead of replacing the default with a temporary avatar (BuddyPress avatar moderator) while their submitted avatar is being approved.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #36485

    Hi,
    Thank you for the post.

    I will ask my team to look into it and see if we can add the compatibility with the member types pro.

    Any update will come on Monday as our offices will be off on the weekend.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 42
    r08 on #36488

    Sounds good and I hope this can be done. I think other users would appreciate this if they run into this problem and are using member types pro.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #36493

    Thank you. We will be glad to so it if feasible.

  • Participant
    Level: Enlightened
    Posts: 42
    r08 on #36621

    Checking in to see if this is feasable. I still think this would be a useful addition.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #36635

    Hi,
    I am sorry, we haven’t been able to check it. Will do it this Saturday and let you knwo within next 24 hours.

    Regards
    Brajesh

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #36690

    Hello,

    Please first upgrade your plugin. Then try the following code.

    It will override placeholder image for user by member type default avatar.

    
    
    /**
     * Override avatar moderator placeholder url by member type associated avatar
     *
     * @param int    $user_id User id.
     * @param string $type    Avatar type.
     *
     * @return mixed
     */
    function buddydev_get_member_type_associated_url( $user_id, $type = 'full' ) {
    	$active_types           = bpmtp_get_active_member_type_entries();
    	$associated_avatar_urls = wp_list_pluck( $active_types, 'associated_avatar_urls', 'member_type' );
    
    	$user_member_types = bp_get_member_type( $user_id, false );
    
    	// Empty member return default url.
    	if ( empty( $user_member_types ) ) {
    		return '';
    	}
    
    	$url = '';
    	foreach ( $user_member_types as $member_type ) {
    
    		if ( empty( $associated_avatar_urls[ $member_type ] ) || empty( $associated_avatar_urls[ $member_type ][ $type ] ) ) {
    			continue;
    		}
    
    		$url = $associated_avatar_urls[ $member_type ][ $type ];
    		break;
    	}
    
    	return $url;
    }
    
    add_filter( 'bpavmod_placeholder_avatar_url', function ( $placeholder_url, $item_type ) {
    
    	if ( ! function_exists( 'bpmtp_member_types_pro' ) || 'user' !== $item_type ) {
    		return $placeholder_url;
    	}
    
    	$user_id = bp_is_user() ? bp_displayed_user_id() : bp_get_member_user_id();
    
    	if ( ! $user_id || ! bpavmod_is_in_moderation( $user_id, 'user' ) ) {
    		return $placeholder_url;
    	}
    
    	$url = buddydev_get_member_type_associated_url( $user_id, 'full' );
    
    	return $url ? $url : $placeholder_url;
    }, 10, 2 );
    
    add_filter( 'get_avatar_url', function ( $avatar_url, $id_or_email ) {
    
    	if ( ! function_exists( 'bpmtp_member_types_pro' ) || ! function_exists( 'bpavmod' ) ) {
    		return $avatar_url;
    	}
    
    	$user = is_email( $id_or_email ) ? get_user_by( 'email', $id_or_email ) : get_user_by( 'id', $id_or_email );
    
    	if ( ! $user || ! bpavmod_is_in_moderation( $user->ID, 'user' ) ) {
    		return $avatar_url;
    	}
    
    	$url = buddydev_get_member_type_associated_url( $user->ID, 'thumb' );
    
    	return $url ? $url : $avatar_url;
    }, 15, 2 );
    
    

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 42
    r08 on #37001

    Thanks, I will test this out in the next couple of weeks and report back. Hope this makes it into the plugin dashboard one of these days 🙂 For now I will add the code.

  • Participant
    Level: Enlightened
    Posts: 42
    r08 on #37081

    Thanks for your work Ravi!
    I tested this out today and it mostly works but has a small bug.

    I think this is because I have your other plugin installed too:
    https://buddydev.com/plugins/buddypress-live-notification/

    When the user is on the Upload Profile Photo page they get a little popup notification that says “The profile photo was approved by admin”. Even though it hasn’t been uploaded yet!

    Also, after upload, the popup comes up and displays the message on every page reload.

    Even after the image is approved the popup messages happen on every page reload 🙁

    SIDE NOTE –
    One more thing. When the moderation plugin is installed I think it would be nice to have a message that lets the user know this. Currently, when you upload a new profile pic the message says that you have successfully uploaded the image. But it doesn’t say anything that tit needs to be moderated.

  • Participant
    Level: Enlightened
    Posts: 42
    r08 on #37083

    Did further testing and this is what I found.

    When the user uploads a new profile photo:

    1) Their profile photo (upper left on the main top section) on their main BP user page is the new photo they uploaded. It skipped the moderation process and shows up there.

    2) The Profile photo in the Activity feed is the old photo they had previously. (it should be showing their default Member Types Pro photo)

    3) The profile photo in the member directory shows the photo from their default Member Types Pro. Seems like this is the only one that is being displayed properly and following the rules.

    1 and 2 are not displaying the correct Member Type Pro photo.
    3 is working correctly.

You must be logged in to reply to this topic.

This topic is: not resolved