• Resolved aaronmckeon

    (@aaronmckeon)


    I am trying to allow users to upload their avatar on the front-end of the site. Since this plugin does not have that built-in functionality, I’m going to have them upload an image and then I’d like some PHP code to assign it as their avatar afterwards.

    Would this be the most appropriate code to use once the upload completes?

    $avatar_id = **ID OF THE IMAGE FILE UPLOADED ELSEWHERE**;
    $sla = new Simple_Local_Avatars();
    $sla->assign_new_user_avatar( (int) $avatar_id, $user->ID );
    

    Will this work if the user already has an avatar? Thanks for any help!

    – Aaron

    • This topic was modified 2 years, 6 months ago by aaronmckeon.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter aaronmckeon

    (@aaronmckeon)

    I was able to figure this out. I’ll post a separate topic showing people how I was able to allow users to upload on the front-end.

    Plugin Support Darin Kotter

    (@dkotter)

    @aaronmckeon Sounds like you got this working, which is great, but if you’re trying to programmatically set an avatar, that is the right approach.

    I do wonder though if it would be worth having a utility function that can be used to call that assign_new_user_avatar method, similar to our get_simple_local_avatar. This would simplify things a bit, ensuring you don’t have to create a new instance of Simple_Local_Avatars yourself. I’ll put this idea into our roadmap. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Set Avatar Programmatically’ is closed to new replies.