Replies
oh hey Brajesh — sorry to ask another question, but how would you write code for more than two types plus an unknown type…? i want to have about 10 different member types plus an unknown type.
so would i just duplicate the ‘elseif’ line for each new member type — use that line as written as a standard for every new type i add? or is there something i need to add that isn’t expressed here?
also, because i have no idea if this is significant, but in the coding example, there’s a space between == and the word “male” but not between == and the word “female”…is that anything that matters, or is it insignificant?
here’s what i’m talking about…from the example:
if ( $type == 'male' ) { $avatar = 'https://sitenameprivate.com/wp-content/uploads/2018/11/male.png';// get_template_directory_uri() . 'male.png'; } elseif( $type =='female' ) {
thanks again for all your assistance!! this plugin is a true miracle for me. thank you once again for creating it. <3
- This reply was modified 6 years, 2 months ago by J W.
OH I think it works now….!! I am cautiously optimistic, as I’ll continue to check for bugs, but….OH MY GOODNESS, for now? It looks like it works!!
I’m SO HAPPY!!!!! <3
Thank you, Brajesh…this seems to be the solution I’ve been searching for. Many thanks and blessings to you! <3 <3 <3
I’ll let you know if I find anything that isn’t working. I’ll also restore my site to an earlier version just in case there are any issues with it going wonky earlier that are hanging around. And I’ll reinstall the Member Type Generator plugin and re-upload the bp-custom file again.
And if there are any issues that arise on the clean re-install, I’ll let you know! 😀
Thank you, so very much. I’m very pleased.
I hope you have a great day, Brajesh! 😀
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?
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. 😀