strangerstudios / basic-user-avatars

Add an avatar upload field on frontend pages and on the Edit Profile screen so users and admins can manage custom profile pictures without Gravatar.
https://wordpress.org/plugins/basic-user-avatars/
39 stars 34 forks source link

Integration with Gravity Forms User Registration add-on? #6

Closed jackmcconnell closed 9 years ago

jackmcconnell commented 9 years ago

Hi,

I'm using Gravity Forms so that users can update their profiles via the front-end using the 'User Registration' add-on. Unfortunately, this is missing profile photo add/remove/update functionality so i'm using a basic upload field (as part of the Gravity Form) so that users can upload new profile photos and then am mapping this to the 'basic_user_avatar' meta box that Basic User Avatars creates.

Unfortunately, this doesn't result in the image being mapped to this field correctly. Instead, I get a letter 'h' in the src input when viewing a user's broken profile photo in the WordPress admin.

In the database, when searching for 'basic_user_avatar' I can find the row in the wp_usermeta table and can see that the link to the file is listed correctly in the meta_value field. This means the the upload box is working correctly and that the User Registration add-on for Gravity Forms is mapping the URL of the uploaded file to the correct area in the database but it just isn't showing when viewing a profile.

I'm thinking this is something to do with how Basic User Avatars displays the profile image in the user profile. Can you confirm?

Any help much appreciated. Thanks, Jack

jaredatch commented 9 years ago

What format are you storing the user meta in?

It should be stored in an array, which will then in turn be serialized if you are actual viewing the meta_key in the DB directly. Eg:

a:4:{s:4:"full";s:57:"http://wptest/wp-content/uploads/2015/05/admin_avatar.jpg";i:64;s:63:"http://wptest/wp-content/uploads/2015/05/admin_avatar-64x64.jpg";i:26;s:63:"http://wptest/wp-content/uploads/2015/05/admin_avatar-26x26.jpg";i:96;s:63:"http://wptest/wp-content/uploads/2015/05/admin_avatar-96x96.jpg";}

That would by what I would check first as that is the most obvious reason displaying an uploaded gravatar would fail.

The display does some other functions like resizing on the fly, but before it does that it fetches the original which should be easy to debug.

$local_avatars = get_user_meta( $user_id, 'basic_user_avatar', true );
echo $local_avatars['full']; // should echo url to original uploaded image
jackmcconnell commented 9 years ago

Hi jaredatch, Thanks for your reply.

In the database under meta_key, it's just stored as URL string like: http://wptest/wp-content/uploads/2015/05/admin_avatar.jpg It's not serialised so i'm guessing that Gravity Forms will need to do this, is that right?

Jack

jaredatch commented 9 years ago

Correct, that's your issue.

You will need a short function that handles that. GF has hooks and filters all over the place, including post/after submission, so it shouldn't be too much of a problem. Support can probably point you in the right direction if needed.

Essentially you'll want to hook after the submission fires and run:

update_user_meta( $user_id, 'basic_user_avatar', array( 'full' => $avatar_url ) );

jaredatch commented 9 years ago

Since we never heard back I'm going to close this for now. If you still need help on this later just bump this issue.