Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change default avatar

  • @igid26

    Participant

    Hi im trying to do a check on a xprofile field “Gender” as i want to have a different default avatar depending on whether the user is male or female, i have the following code which doesnt seem to work (it displays female avatar for both).

    Im guessing you cant check xprofile feilds like this in bp-custom.php, can anyone point me in the right direction on how i can accomplish this?

    Thanks in adavnce for any help.
    `
    function myavatar_add_default_avatar( $url )
    {
    global $bp;
    if (bp_get_profile_field_data(‘field=Gender’) === “Male”) :
    return get_stylesheet_directory_uri() .’/_inc/images/default_avatar_male.jpg’;
    else:
    return get_stylesheet_directory_uri() .’/_inc/images/default_avatar_female.jpg’;
    endif;
    }
    add_filter( ‘bp_core_mysteryman_src’, ‘myavatar_add_default_avatar’ ); `

Viewing 3 replies - 1 through 3 (of 3 total)
  • @modemlooper

    Moderator

    try

    ` $gender = bp_get_profile_field_data(‘field=Gender’);

    if ( $gender === ‘Male’) :`

    @igid26

    Participant

    Thank you for your answer. The member header works great. But when viewing members in Members Directory does not work. Displays all the avatars same. Sorry for my English.I used the code –
    `function myavatar_add_default_avatar( $url )
    {
    global $bp;
    $gender = bp_get_profile_field_data(‘field=Gender’);

    if ( $gender === ‘Male’) :
    return get_stylesheet_directory_uri() .’/images/default_avatar_male.jpg’;
    else:
    return get_stylesheet_directory_uri() .’/images/default_avatar_female.jpg’;
    endif;
    }
    add_filter( ‘bp_core_mysteryman_src’, ‘myavatar_add_default_avatar’ );`

    @igid26

    Participant

    I changed `$gender = bp_get_profile_field_data(‘field=Gender’);`
    to
    `$gender = xprofile_get_field_data(‘Gender’, bp_get_member_user_id());`
    It helped only in Members Directory. Everywhere else it does not work

    Member Profile
    http://www.taraj.sk/member-profil.jpg

    Member Directory
    http://www.taraj.sk/member-directory.jpg

    Forum BBpress
    http://www.taraj.sk/bbpress.jpg

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change default avatar’ is closed to new replies.
Skip to toolbar