Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author donmik

    (@atallos)

    I believe you can use filters to modify the avatar displayed. With these 2 filters you could use the xprofile field instead of avatar.

    function display_avatar($avatar, $params) {
        $avatar = bp_get_member_profile_data(array('field' => 'IMAGEFIELD', 'user_id' => $params['item_id']));
        return $avatar;
    }
    add_filter('bp_core_fetch_avatar_url', 'display_avatar', 15, 2);
    
    function display_avatar_html($avatar_html, $params) {
        $upload_dir = wp_upload_dir();
        $new_avatar = $upload_dir['baseurl'] . bp_get_member_profile_data(array('field' => 'IMAGEFIELD', 'user_id' => $params['item_id']));
        $parts = explode('"', $avatar_html);
        for ($i=0; $i<count($parts);$i++) {
            if (strpos($parts[$i], 'src=')) {
                break;
            }
        }
        $i++;
        $prev_avatar = $parts[$i];
        return str_replace($prev_avatar, $new_avatar, $avatar_html);
    }
    add_filter('bp_core_fetch_avatar', 'display_avatar_html', 15, 2);

    Replace IMAGEFIELD with the name of your image field.

    Hi @donmil
    I used your function below, and I not sure I correct, my image form field is: field_51, So I have to replace IMAGEFIELD with field_51 then my avatar is gone but on the profile page I saw image that I choose when I register.

    Please Advice.

    Plugin Author donmik

    (@atallos)

    No, IMAGEFIELD is the name of your field ‘Image’ or ‘Avatar’. Not the id.

    Hi @donmik
    I’m apologize to you, Can you please explain more about the Image field, Do you mean mysql field name that I store my avatar url please?

    Thank for your help.

    Plugin Author donmik

    (@atallos)

    I mean the name of your field. When you create a new profile field, you have to write a Field Title. This if what you need to write instead of IMAGEFIELD.

    So, if in Field Title, you write “Avatar”, you need to replace IMAGEFIELD with Avatar.

    Hi @donmik
    Thank you for your answer, but I still can’t find out the solution.
    1. I create filed name Avatar
    2. I copy code above and change IMAGEFIELD to Avatar and put the code in to bp-custom.php
    3. When I login into my WordPress Admin, and click User menu all avatar user is gone.

    Can you help me about this problem please.

    Best Regards.

    Plugin Author donmik

    (@atallos)

    Well, if you just created the field “Avatar” and copy my code, it’s totally normal that the user avatar are not displayed. Until the users don’t upload the avatar using the new field…

    With this code, you are saying to wordpress to show avatar from this field and not from the original avatar, so, until the users don’t reupload the avatar, you will not see any avatars…

    Hi donmik

    Great plugin but im having the same issue! I updated the code above but now all old avatars are missing. If there any way to use old avatar directory for old avatars & your new directory above for all new avatars as members upload them? I have 700 members so cant ask them all to update avatars.

    any help much appreciated

    thanks

    John

    Plugin Author donmik

    (@atallos)

    You can modifying the code and search the avatar in two places. Try to look into my plugin directory and if not show the original avatar.

    function display_avatar($avatar, $params) {
        $bxcft_avatar = bp_get_member_profile_data(array('field' => 'IMAGEFIELD', 'user_id' => $params['item_id']));
        if ($bxcft_avatar != '') {
            $avatar = $bxcft_avatar;
        }
        return $avatar;
    }
    add_filter('bp_core_fetch_avatar_url', 'display_avatar', 15, 2);
    
    function display_avatar_html($avatar_html, $params) {
        $new_avatar = bp_get_member_profile_data(array('field' => 'IMAGEFIELD', 'user_id' => $params['item_id']));
        if ($new_avatar != '') {
            $upload_dir = wp_upload_dir();
            $new_avatar = $upload_dir['baseurl'] . $new_avatar;
            $parts = explode('"', $avatar_html);
            for ($i=0; $i<count($parts);$i++) {
                if (strpos($parts[$i], 'src=')) {
                    break;
                }
            }
           $i++;
           $prev_avatar = $parts[$i];
           $avatar_html = str_replace($prev_avatar, $new_avatar, $avatar_html);
        }
    
        return $avatar_html;
    }
    add_filter('bp_core_fetch_avatar', 'display_avatar_html', 15, 2);

    I didn’t try the code but I hope you get the idea.

    Thanks Ill try that

    Thanks donmik, that worked perfect! ?? I just had to remove a small bit of code to make it work:

    $new_avatar = $upload_dir[‘baseurl‘] . $new_avatar;

    If I left in ‘baseurl’ it was doubling up the url link to image.

    Also just one problem now, the thumbnail of my avatar in the sidebar login widget is just showing a random member avatar not my own one? On the profile page it is correct though.

    thanks
    john

    Plugin Author donmik

    (@atallos)

    mmm, weird…

    I believe sidebar widget is using bp_core_fetch_avatar too. You can write an echo “HI THERE!” inside the code to check if it enters in your filter. I don’t know really why this is happening.

    Try to check the arguments passed to your filter and see what happens inside.

    Ok thanks for help

    Hi Donmik
    This is a really great plugin; just what Buddypress needs. Thank you for the above code to pull the image upon registration to where the Avatar goes.

    However, I would like my users to be able to use ‘edit avatar’ option once registered to upload a new avatar picture. Is there some kind of ‘or’ function to use both options (image field or edit avatar).

    Thanks, much appreciated!

    Plugin Author donmik

    (@atallos)

    Hi,

    Sorry for the delay, I’ve been looking at this but I did not find an easy way to achieve what you want. There is no magic hook to use here. I tried many things but none of them was successful. I’m sorry but I have no solution.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Avatar (Image)’ is closed to new replies.