BuddyDev

Search

[Resolved] Need to set default BuddyPress avatar based on member type; please help!!

  • Participant
    Level: Initiated
    Posts: 12
    J W on #19029

    Hi!

    I read this article here, and followed all the instructions listed…even went to the subsequent forum posting that the comment thread linked to…and used the suggestion in the forum that was linked to at the bottom of the article…

    https://buddydev.com/using-different-default-avatar-buddypress-users-based-profile-fields-member-type/

    …but got 500 errors and had to restore my site. 🙁

    So neither the suggested code and plugins in the article nor the information in the follow-up forum conversation worked for me.

    Brajesh is a certified genius, so I can only assume that this code no longer works on more current versions of WordPress and/or BuddyPress. I’m sure that code/strategy presented in the article worked just fine when written.

    So now I’m looking to use the same idea — set a default BuddyPress user avatar based on member type. And I’ll gladly use any plugin suggested for today’s workaround. I just need to know how to proceed.

    My question, then: what plugins would I need to use today, at this moment, to achieve the ‘default avatar for each member type’ effect? And, what code? Do I need code AND a plugin (or more than one plugin)…? Or can I go without additional code and just use a plugin(s) to accomplish this?

    Please advise.

  • Participant
    Level: Initiated
    Posts: 12
    J W on #19030

    P.S.: I am using WordPress 4.9.8…with the most current version of BuddyPress available at this time.

    I am also using bbPress — also the most current version available at this time. 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #19040

    Hi J W ,
    Thank you for the details and my apologies for the inconvenience caused.

    Since it is 500 error, it is most probably a syntax error or some function being called which is not present.

    Can you please share me the complete code from your bp-custom.php on pastebin and I can look and assist.

    The code is tested on 4.9.8.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 12
    J W on #19042

    Thanks for the response, Brajesh!

    I have nooooo idea how to use pastebin, so I’ll just share my code here.

    I had to create a bp-custom file to do this, by the way; I used only your code in the bp-custom file. Of course I had to use my site’s website addresses (and the link to my media library, etc.)…but I tested it out as closely to your guidelines as I could. Even set up member classes to be ‘male’, ‘female’, and ‘unknown’ in the plugins….just so I could do it as closely to your tutorial as possible.

    For the sake of privacy, because this is a project still under development and I do not wish to share my actual website address, I’ve changed my site name to say ‘sitenameprivate’ instead of the domain’s true name. But everything else is just as the actual bp-custom file is in my website.

    Here goes:

    
    <?php
    
    // turn off gravatars 
    
    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
    
    //set default use of avatar based on member type
    
    function buddydev_set_default_use_avatar_based_on_member_type( $avatar, $params) {
        $user_id = $params['item_id'];
     
        $type = bp_get_member_type( $user_id );
     
        if ( $type == 'male' ) {
            $avatar = 'https://sitenameprivate.com/wp-content/uploads/2018/11/male.png';// get_template_directory_uri() . 'male.png';
        } elseif( $type =='female' ) {
            $avatar = 'https://sitenameprivate.com/wp-content/uploads/2018/11/female.png';//get_template_directory_uri() . 'female.png';
        } else {
            $avatar = 'https://sitenameprivate.com/wp-content/uploads/2018/11/unknown.png';//get_template_directory_uri() . 'unkown.png';;
        }
     
        return $avatar;
    }
     
    add_filter( 'bp_core_default_avatar_user', 'buddydev_set_default_use_avatar_based_on_member_type', 10, 2 );
    
    ?> 

    Please keep in mind that I used the plugins you mentioned in your tutorial (the link I mentioned when I posted my request for assistance). They look like great plugins; very useful. Lots of potential here. I hope I we can find a way for me to use them on my site! 🙂

    Thanks again for all your assistance, Brajesh. I greatly appreciate any help you can provide. 😀

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #19043

    Hi,
    No problem. Thank you for sharing.

    Your code is correct. Is there any chance there were spaces or newline before ‘

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 12
    J W on #19044

    Just checked — the first line, <?php is at the very top of the file…with no spaces above it. And there are no spaces after the ?> either.

  • Participant
    Level: Initiated
    Posts: 12
    J W on #19051

    Uh oh…I think I found the issue.

    I just tried to reproduce the error. Re-downloaded the plugins…hadn’t even uploaded my bp-custom file. Mind you, the site version I’m working with is before I even attempted to make any installations of either plugin or the bp-custom file.

    I was just uploading the plugins and activating them, and had not yet tried to add the bp-custom file. All went well with uploading and activating the ‘BuddyPress Member Type Generator’ plugin. But when I went to activate the ‘BP XProfile Member Type Field’ plugin, my site failed. Got the same 500 error issue I had before. And here I thought it was due to the bp-custom code! Oh man.

    So I had to go into my site via FTP and remove the BP XProfile Member Type Field plugin folder manually….and now my site works again. No more 500 error.

    Can I do any of what I hope to do here — assign particular default avatars for certain member types — without the BP XProfile Member Type Field plugin…? Just by using the code and the BP Member Type Generator plugin?

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #19052

    Hi,
    I am sorry for the issue with the member type field. I will give it a try later ad see what is causing the error.

    For the above, you don’t need the member type field. The purpose of member type field to let users select their member type on registration.

    The above code will work great with BuddyPress Member Type Generator.

    Please give it a try and let me know.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 12
    J W on #19053

    By the way, Brajesh — I have ‘extended profiles’ shut off…and I also have ‘allow users to upload avatars’ shut off. Do I have to have those turned on to use any of these things — the plugins or the bp-custom code I pasted?

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #19054

    Thank you. That makes sense now.

    The Member Type Field assumes that you have Xprofile on.

    No, You don’t need to turn on any of these. Please make sure to not use the Member Type field.

    We might have to slightly tweak the code since the user upload is disabled.

    Please give the above code a try and let me know if it works or not. If not, I can tweak it a little.

    Regards
    Brajesh

The topic ‘ [Resolved] Need to set default BuddyPress avatar based on member type; please help!!’ is closed to new replies.

This topic is: resolved