Tell us what you are trying to do?
Hey there, i try to build a userform in which a user can use the standard wordpress profilpicture.
how can i do this. i found nothing.
Cheers
Hi, as you may know, the WordPress User profile picture is managed with Gravatar, which is an external service. Toolset Forms is not designed to interact with this external service, but you could use a custom image field instead and manage that with Forms. Another ticket discusses this option here: https://toolset.com/forums/topic/insert-custom-photo-to-wp-profile-picture/
Here is the information for the external Gravatar service: https://en.gravatar.com/
hey Christian,
thanks for your reply.
it works with the types fields but the link you posted would be the perfect solution for me.
please check my next post
Cheers
the solution from the link is not exactly clear for me:
You can use a Custom Image User Field instead.
1. Create a user Field (Image)
2. Create a Post Field (image)
3. Create a CRED Form to create (or update) a Post
4. Insert this code (adapt it) to your functions.php:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==44)
{
$image_value = get_post_meta($post_id, 'wpcf-image', true);
$user = wp_get_current_user();
$user_id = $user->ID;
update_user_meta($user_id, 'wpcf-image-user', $image_value);
}
}
Why do i need two image fields? One a post one a user.
I only have a user types image field. does this work as well with only a user upload-image?
cheers
The other ticket involves a separate custom post type, "member-profile", where the User is managing this image. In your case, there is no "member-profile" post so there is no need for a 2nd image custom field, and there is no need for any custom code. Your Users will manage their image in an Edit User Form, and there will be no Edit Post Form.
I hope this helps, let me know if this is confusing and I can give more guidance.
My issue is resolved now. Thank you!
Hey Chris,
at first i thought i had it but now... 🙁
From my Posttype it is the featured-image-field which i want to copy to a user field.
the userfield is called = profilbild
the id of the form is 83.
but i don´t get this running!
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==83) //can i add more than one form?
{
$image_value = get_post_meta($post_id, 'what is the featured image id?', true);
$user = wp_get_current_user();
$user_id = $user->ID;
update_user_meta($user_id, 'wpcf-profilbild', $image_value);
}
}
Thanks a lot.
The featured image is a bit different, because only the image ID is stored as "_thumbnail_id". It's better to use the WP API get_the_post_thumbnail_url:
$image_value = get_the_post_thumbnail_url( $post_id, "full"); // full size, change for a different size
In this code I used the "full" size but you could use "post-thumbnail" or any other registered size.
https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/
thanks a lot chris!! Worked fine for me