This topic has 6 replies, 3 voices, and was last updated 7 years by Laura.

  • Author
  • #64126
     Laura
    Moderator

    Hello, this will allow you to have a Default avatar for Female and one for Male, for now works only if you have 2 Genders in I am a field. Please Follow these instructions in order to customize the code.

    Code:

    COPY CODE
    
    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
    	function myavatar_add_default_avatar( $url )
    	{
    		global $bp;
    		$gender = xprofile_get_field_data('I am a', bp_get_member_user_id());
    		if ($gender == "Male") {
    			return $img_url = SECU.'MALE AVATAR URL OF IMAGE';
    		}
    		else {
    			return $img_url = SECU.'FEMALE AVATAR URL OF IMAGE';
    		}
    	}
    	add_filter( 'bp_core_mysteryman_src', 'myavatar_add_default_avatar' );
    	add_filter( 'bp_core_default_avatar_user', 'myavatar_add_default_avatar' );
    

    How to Customize the code
    As you can see, the code its fetching the field I am a, so maybe you have translated this field, so it wont work.
    Just edit “I am a” With the Field Name of Gender Selection.

    Also, change Man for your Gender / Options. Only 2 Are possible for now.

    If you prefer not to use this for Gender, and prefer maybe for Students, Teachers or any other topic, just change the names and the field and it will work.

    Where to change the field:
    IN ->

    COPY CODE
     $gender = xprofile_get_field_data('I am a', bp_get_member_user_id()); 

    Change ONLY I am a for the name of your Field

    Where to change the Gender / Values:
    IN ->

    COPY CODE
    
    if ($gender == "Male") {
    			return $img_url = SECU.'MALE AVATAR URL OF IMAGE';
    		}
    		else {
    			return $img_url = SECU.'FEMALE AVATAR URL OF IMAGE';
    		}
    

    Change Male for ONE of the two Options, automatically the other option will get the SECOND image

    Make Sure to add the url of your images where “MALE AVATAR URL OF IMAGE” and “FEMALE AVATAR URL OF IMAGE” appears.

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy聽to help you 馃檪

    #68019
     adamdale1
    Participant

    Hi Laura,
    Was very interested in the above, reference default avatar for Female/Male. So experimented with it! Have a few questions?

    1. Where is the code supposed to be inserted? Function.php or bp_function.php etc. ?
    2. I keep getting a parse error on the 3rd line of code!
    function myavatar_add_default_avatar( $url ) {

    So, any information on the above would be a great help. Thank you.

    #69013
     Laura
    Moderator

    Hello, sorry, didnt see the reply. The code needs to be inserted in functions.php
    Please make sure you have the urls changed

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy聽to help you 馃檪

    #143462
     Roader
    Participant

    Laura, podr铆as tener la amabilidad de explicarme d贸nde coloco el c贸digo php? O d贸nde debo modificar? M谩s detalles plis!

    #143686
     Laura
    Moderator

    Hola, todo esta muy bien explicado en el post 馃檪 Debes colocarlo en functions.php del child theme

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy聽to help you 馃檪

    #146170
     Roader
    Participant

    Hola Laura. Quiero aplicar este tutorial, pero no quiero cambiar ‘I am a’ por ‘Gender’.
    Quiero mantener las opciones: ‘I am a’ => ‘Man’ , ‘Woman’. Entonces, c贸mo puedo usar este c贸digo para cambiar la imagen si un usuario es Hombre o Mujer?

    #146281
     Laura
    Moderator

    Hola, no tienes que cambiar nada por genero, funciona con cualquier tipo de nombre. Si lo dejas tal y como esta funciona, solo que tendrias que cambiarlo a espa帽ol

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy聽to help you 馃檪

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Log in with your credentials

Forgot your details?