WordPress.org

Ready to get started?Download WordPress

Forums

Buddypress Xprofile Custom Fields Type
Avatar (Image) (16 posts)

  1. catyco
    Member
    Posted 12 months ago #

    I added the image file to my register.php and image loads. From my understanding, the images goes to the Your files are uploaded in "YOUR_UPLOAD_DIR / profiles / ID_OF_USER" folder.

    However BP images go to the Avatar directory. How can I get the image be the BP image?

    http://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/

  2. donmik
    Member
    Plugin Author

    Posted 12 months ago #

    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.

  3. ananwebman
    Member
    Posted 11 months ago #

    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.

  4. donmik
    Member
    Plugin Author

    Posted 11 months ago #

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

  5. ananwebman
    Member
    Posted 11 months ago #

    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.

  6. donmik
    Member
    Plugin Author

    Posted 11 months ago #

    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.

  7. ananwebman
    Member
    Posted 11 months ago #

    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.

  8. donmik
    Member
    Plugin Author

    Posted 11 months ago #

    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...

  9. johnegg
    Member
    Posted 9 months ago #

    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

  10. donmik
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  11. johnegg
    Member
    Posted 9 months ago #

    Thanks Ill try that

  12. johnegg
    Member
    Posted 9 months ago #

    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

  13. donmik
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  14. johnegg
    Member
    Posted 9 months ago #

    Ok thanks for help

  15. familysp
    Member
    Posted 8 months ago #

    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!

  16. donmik
    Member
    Plugin Author

    Posted 8 months ago #

    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.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.