Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to update avatar user meta?


  • Thagintoki
    Participant

    @thagintoki

    Hi according to my last question I have come across a good solution to upload files to buddypress avatars folder, now I want to know how to update user meta to show this avatar in my frontend.

    code I used:

    $avatarPath //is the path where the avatar is uploaded
    update_user_meta( $user->ID, 'author_avatar', $avatarPath );

    thanks in advance.

Viewing 11 replies - 1 through 11 (of 11 total)

  • Henry Wright
    Moderator

    @henrywright

    You can use get_user_meta() for that.


    Thagintoki
    Participant

    @thagintoki

    thanks but couldn’t find the meta used for avatars, I may be wrong so if you know please what is being updated to show avatar for each profile please tell me.


    Henry Wright
    Moderator

    @henrywright

    In your above code you’ve used author_avatar to update so you’d just use that again to retrieve.


    Thagintoki
    Participant

    @thagintoki

    I have got something great that I have been missing all the time ‘BP_Attachment’ is the right class to use if you want to upload an avatar, the only problem is that it depends on a $_FILES variable.


    Henry Wright
    Moderator

    @henrywright

    Yeah the BP_Attachment class is awesome!

    the only problem is that it depends on a $_FILES variable

    I’m wondering why that’s a problem?


    r-a-y
    Keymaster

    @r-a-y

    We do not store avatar data in the database.

    We do a look up at the files level instead.

    If you want to show an avatar based on a custom avatar stored in the database, you’ll need to use the 'bp_core_fetch_avatar' filter to override how BuddyPress shows avatars:
    https://buddypress.trac.wordpress.org/browser/tags/2.4.0/src/bp-core/bp-core-avatars.php?marks=531-546,660-664#L531

    If you just want to display a user avatar, use the bp_core_fetch_avatar() function:

    echo bp_core_fetch_avatar( array(
        'item_id' => USER_ID_TO_GRAB_AVATAR_FOR
    ) );

    Thagintoki
    Participant

    @thagintoki

    not showing the avatar but instead I want to attach the avatar to a specific user so buddypress will take care of showing it,

    the only problem is that it depends on a $_FILES variable

    this means that I can use the function if I had a form, else I can’t because the mother Class has needs as argument the file from ($_FILE) and the name of the form which i don’t have.


    Henry Wright
    Moderator

    @henrywright

    How are you uploading the image?


    Thagintoki
    Participant

    @thagintoki

    I am not uploading any image I’m using a script that gets random users from a RESTFul API then register it as a user that’s all, in the API results I have a url of the avatar I use wp_download and other functions to upload the image from its URL, now I miss just the thing about attaching it to the user, I have all things settled.


    Henry Wright
    Moderator

    @henrywright

    in the API results I have a url of the avatar

    Does the result give you the user ID as well?


    Thagintoki
    Participant

    @thagintoki

    No but once I save the user to the database I get the user ID so I can use it to attach files, images or anything to a user but couldn’t find any solution for attaching avatars to a user so buddy press can ready it

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to update avatar user meta?’ is closed to new replies.
Skip to toolbar