Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to properly filter bp_member_avatar


  • adamt19
    Participant

    @adamt19

    Still trying to wrap my head around taking advantage of these built in filters..

    I need to change the alt-text here so that the member’s Full name is not shown. We’re using the “Usernames Only” plugin but it does not cover a few usages of our users’ names, such as in alt-text on /members avatars, as well as in pictures.php.

    So first… avatars. The function in question:

    function bp_member_avatar( $args = '' ) {
    	echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
    }
    	function bp_get_member_avatar( $args = '' ) {
    		global $members_template;
    
    		$fullname = !empty( $members_template->member->fullname ) ? $members_template->member->fullname : $members_template->member->display_name;
    
    		$defaults = array(
    			'type'   => 'thumb',
    			'width'  => false,
    			'height' => false,
    			'class'  => 'avatar',
    			'id'     => false,
    			'alt'    => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname )
    		);
    
    		$r = wp_parse_args( $args, $defaults );
    		extract( $r, EXTR_SKIP );
    
    		return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
    	}

    and what I tried:
    /* Hide FUll Name from member avatar */

    add_filter('bp_member_avatar', 'mm_hide_name_in_alt_text');
    
    function mm_hide_name_in_alt_text() {
      $defaults = array(
        'type'   => 'thumb',
        'width'  => false,
        'height' => false,
        'class'  => 'avatar',
        'id'     => false,
        'alt'    => 'Profile Picture' );
        
        return $defaults;
    }

    Looking to understand why this isn’t working?

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

  • adamt19
    Participant

    @adamt19

    Also – I realized I can just modify the call in members-loop.php and include a static alt text string e.g. &alt=Picture, and I’ve done this in the mean time, since this is a major privacy issue on our site.

    But I would like to know how to filter my way to this modification properly 🙂


    shanebp
    Moderator

    @shanebp

    $defaults aren’t being passed by the filter.

    Try:

    add_filter('bp_member_avatar', 'mm_hide_name_in_alt_text', 1);
    function mm_hide_name_in_alt_text( $var ) {
      var_dump( $var ); 
      return $var;
    }

    Then you should be able to tell what is being passed to the filter and adjust it accordingly.
    You could also use the filters in bp_core_fetch_avatar()


    rodhewitt
    Participant

    @rodhewitt

    hello @adamt19 Have you found any solution?


    adamt19
    Participant

    @adamt19

    will be digging back into this today and I’ll let you know

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to properly filter bp_member_avatar’ is closed to new replies.
Skip to toolbar