Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is it possible to check xprofile fields data from within bp-custom.php

  • 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.

    Regards

    Tony

    `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 2 replies - 1 through 2 (of 2 total)
  • Thinking about it, im going about this the wrong way, if i want the avatars to change site wide i need a different approach …

    ** Goes to mull it over **


    julien760
    Member

    @julien760

    hello,

    I try to do the same thing. I want to display a specific picture following the gender of the members.

    I use add_filter and the picture of the profil is the good one but all others pictures from sidebar, for example, are the same…

    Have you finally find a solution for this issue ?

    Thanks in advance,

    My test code :
    function bp_remove_gravatar ($image, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir) {
    $default = get_stylesheet_directory_uri() .’/images/bp_default_avatar.gif’;
    if( $image && strpos( $image, “gravatar.com” ) ){
    if ( bp_get_profile_field_data( ‘field=Gender’ ) == ‘Female’ ) {
    $default = get_stylesheet_directory_uri() .’/images/def_f_avatar.gif’;
    return ‘female‘;
    }
    if ( bp_get_profile_field_data( ‘field=Gender’ ) == ‘Male’ ) {
    $default = get_stylesheet_directory_uri() .’/images/def_m_avatar.gif’;
    return ‘male‘;
    }
    else {
    return $image;
    }
    } else {
    return $image;
    }
    }
    add_filter(‘bp_core_fetch_avatar’, ‘bp_remove_gravatar’, 1, 9 );

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is it possible to check xprofile fields data from within bp-custom.php’ is closed to new replies.
Skip to toolbar