Skip to:
Content
Pages
Categories
Search
Top
Bottom

custom set of avatar pics

  • is there a way by which i can create 20-30 custom avatar images and randomly assign them to members who did not upload their profile pics? please… i’ve been looking all over for this with no luck.. any ideas by anyone out there?

Viewing 18 replies - 1 through 18 (of 18 total)
  • sorry to bump guys… but any idea on this at all? creating a custom “set” of avatar pics… (about 5-6 pics which are given by random to different members who havent uploaded their own pics)

    You can certainly replace the default avatar picture, either with a bp_default instruction in wp-config.php or by adding a new function (into functions.php). If you wanted to achieve a random selection from a pool of avatars then I suppose you would need to write some php of javascript to intercept the avatar display and randomly select from an array.

    I’ve not seen anything off-the-shelf for BuddyPress, so you’d probably need to adapt a script and hook it into BuddyPress.

    There was a script I used a while back in a Social Engine 4 implementation that basically presented users with choice of standard avatars on signup, which would be a better way of implementing this, since it’s important to encourage users to personalise their profiles which leads to greater engagement.

    Here’s an example of what I mean – http://webhive.com.ua/store/product.php?id_product=36 – but I’ve not seen this for a BP environment.

    @DoctorDR thanks for the message… will try and do something, and if something works out, will let you know

    No problem. I look forward to hearing how you get on.

    @DoctorDR looks like i’ve found the solution… and i hope everyone out there will find this helpful too.
    Problem Statement: I wanted to have a custom set of 10-15 avatars uploaded into a folder, and buddypress would have to pick from any one of these to assign to members(on random) everytime then login if they havent uploaded their pwn profile pic.
    Why: Lets say am on the members page, and everyone is displayed over there.. we can get different custom pics rather than just one custom pic.
    Solution:
    Step#1: Change the settings to “mystery man” in your buddypress backend.
    Step#2: Upload pics into a folder in your child theme (i uploaded them into wp-content/themes/default/images/avatars/ ).. my theme name is : default, and in it i made a folder for images, and once again another folder called avatars. now… within avatars i put in 10 pics named the following “1avatar.png”, “2avatar.png”, “3avatar.png”… and so on… till “9avatar.png”
    and lastly…
    Step #3: Paste the following code in your functions.php child theme (taken from a combination of other sources)

    `function myavatar_add_default_avatar( $url )
    {
    $length=1;
    $characters=’123456789′;
    $string=”;
    for ($p = 0; $p < $length; $p++) {
    $string .= $characters[mt_rand(0, strlen($characters))];
    }

    return get_stylesheet_directory_uri() .’/images/avatars/’.$string.’avatar.png’;
    }
    add_filter( ‘bp_core_mysteryman_src’, ‘myavatar_add_default_avatar’ );`

    and thats it… give it a shot… worked great for me! i hope this helps others too cause i saw a lot of people asking for this to no avail…

    That’s excellent news @sidjags, I think I might try this out for myself. So you’re essentially building an array of 9 image urls and then cycling through them and returning the latest value each time the function is called.

    Simple and Cute!

    @DoctorDR yup… hope it works for you. I am trying out another improvement, will let u know if that works out too…


    enderandrew
    Member

    @enderandrew

    Stupid question, but what if I had 30 or 40 avatars instead of 10?

    @enderandrew i have personally used 15 or so… but dont think it should matter how many u have in there..


    enderandrew
    Member

    @enderandrew

    I don’t know PHP well, but looking at the code, and it will grab a random character from the string and use that as the name of the file. Since you’re only grabbing one character, you’re limited basically to 10 files with that code. Is that correct? Unless you started using letters as well.


    James
    Participant

    @janismo

    @sidjags
    nice tutorial, tried to make something similar one day (without success).

    for some reason your code always returns red crosses in place of few avatars. Let’s say I have 23 avatars on the page, 21 are displayed as random, but 2 – red crosses with usernames. Don’t know, maybe wider range of $craracters could help.
    Here I have same question as enderandrew.

    thanks.


    James
    Participant

    @janismo

    other small question: if you call them from 1 to 9, then how you get 10 pics, maybe this is the case?

    @Siddharth Jagannath, hi, this is great news, but does anyone know how to randomly assign the Avatars based on sex, let say i uploaded 9 avartars, 5 male, 4 female. so it will assign male Avatars to male users, and female avatars to female users.

    sound hard init?


    enderandrew
    Member

    @enderandrew

    This should allow you to have more than 10 files, or a small string of characters for file names. But I’m curious when you replace the bp_core_mysteryman_src, are you doing it once for each user when they sign up, or randomly every time you display it?

    $tmp = glob(‘avatars/*.gif’);
    if (is_array($tmp))
    {
    $flist = array_merge($flist,$tmp);
    }
    $default_avatar = $flist[array_rand($flist)];
    add_filter( ‘bp_core_mysteryman_src’, $default_avatar );


    enderandrew
    Member

    @enderandrew

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

    Code:
    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’ );

    And all I’m getting is Gravatars. No Mystery Man, and no random avatar either.


    enderandrew
    Member

    @enderandrew

    I have a working version now, but the avatar rotates with every page refresh, so it isn’t really permanently assigning a random avatar to users without one.

    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’ );

    @doctordr I just found this forum and took a look at your Avatar Tools Plugin for social engine. This is exactly the kind of functionality I would like to have with my buddypress site. Do you know of anything out there? I’ve searched but yet to find a solution.


    metalmick
    Participant

    @metalmick

    Fantastic plugin to sort this problem!

    https://wordpress.org/plugins/bp-avatar-suggestions/

Viewing 18 replies - 1 through 18 (of 18 total)
  • The topic ‘custom set of avatar pics’ is closed to new replies.
Skip to toolbar