Helping you Build Your Own Social Network!

Faster, better and easier!

Avatar Gallery

(7 posts) (3 voices)
  • Started 10 months ago by enderandrew
  • Latest reply from enderandrew

Tags:


  1. Ideally I'd like to have a gallery of avatars that I've uploaded in advance that users can select from, in addition to the option of allowing them to upload a custom avatar of their choosing. I know you're swamped, but I'd love to see a plugin that does this.

    Since that is beyond my ability (I only know enough PHP to get myself in trouble), I'm trying a much simpler solution in the mean time.

    I'm trying to replace the mysteryman with a random avatar from an avatar folder if user's don't have an avatar. This is what I'm trying currently:

    I set the default avatar in Buddypress to the Mystery Man. And I’m trying this:

    function myavatar_add_default_avatar( $url )
    {
    $tmp = glob('avatars/*.png');
    $flist = array();
    if (is_array($tmp))
    {
    $flist = array_merge($flist,$tmp);
    }
    $default_avatar = $flist[array_rand($flist)];
    return $default_avatar;
    }
    add_filter( 'bp_core_mysteryman_src', 'myavatar_add_default_avatar' );

    But I'm not getting mysteryman, or the random avatars. Everyone has the default Gravatar. I thought if I configured Buddypress to use mysteryman, that is what I'd get. I'm not sure why Gravatars are overriding that.

    Posted 10 months ago #
  2. Hi TJ,
    You need to return the absolute url for the avatar.

    I assume your avatars directory is at the same level as wp-content/wp-includes etc. In that case the following code will work(I have just edited last 2 lines of your function)

    function myavatar_add_default_avatar( $url )
    {
    $tmp = glob('avatars/*.png');
    $flist = array();
    if (is_array($tmp))
    {
    $flist = array_merge($flist,$tmp);
    }
    $default_avatar = $flist[array_rand($flist)];
    
    $avatrat_dir_url=get_bloginfo('url');//or what ever is your absolute url for the folder in which you are keeping the avatar
    return  $avatrat_dir_url."/".$default_avatar;
    
    }
    add_filter( 'bp_core_mysteryman_src', 'myavatar_add_default_avatar' );
    Posted 10 months ago #
  3. Outstanding! I'm going to test this out!

    Edit: It works, but more so how I feared it might work, and less how I hoped it would work. Every page refresh gives a new random avatar to anyone who doesn't have one. I was hoping to do a one-time random assign of an avatar to people who don't have one. And ideally, I would prefer a proper avatar gallery of pre-defined avatars that people can choose from that are in line with the site's theme, as well as allowing the typical option of allowing the users to upload their own.

    Posted 10 months ago #
  4. Hi TJ,
    That's right. It is working by providing random avatar.
    I don't think we can fix it to a particular user in bp 1.2(there is no way in 1.2 other than moving avatar) but in bp 1.3, there are the ways to do it. So, please wait for 1.3 to release and Let me know, I will put the code.

    As of the selecting avatar from pool, that will be itself a thing of a plugin domain, let bp1.3 come(In bp 1.2, we can not identify the individual object since the above filter does not pass item id), I will put some code for that.

    Posted 10 months ago #
  5. Thanks, Brajesh.

    I look forward to that.

    Posted 10 months ago #
  6. Hi Brajesh, how about making it a plugin? :-)

    BP Custom Avatars or something which allows Super/Site Admins upload custom avatars into media library or auto-generated folder in server. This could also set the default custom avatar in case the member doesn't chose from the available custom avatars. Would be good if super/site admins can also delete avatar/s already uploaded via this plugin too without any problem i.e. just goes to default custom avatar.

    Have a great weekend.

    Posted 10 months ago #
  7. I actually just renewed my membership in hoping of seeing a plugin like this.

    Posted 2 months ago #

Reply

You must log in to post.