Hi guys,
Trying to apply the script in this thread ( https://toolset.com/forums/topic/cred-user-form-to-include-wpuser-avatar-field/#post-622519 ) to my CRED User Form.
I created a user field as image with slug "immagine-del-profilo"
but I can't get the $imageid from the query $wpdb->get_var()
$imageid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid=%s", $_POST['wpcf-immagine-del-profilo']) );
the value of "$_POST['wpcf-immagine-del-profilo']" return only the filename (profilepic.jpg), not the full url of image.. and the query return null.
Any suggestion?
Thank you
I fixed my issue in another way
getting the full url with "get_user_meta"
$imageUrl = get_user_meta($post_id, 'wpcf-immagine-del-profilo', true);
here the full code
add_action('cred_save_data', 'my_save_user_profile',10,2);
function my_save_user_profile($post_id, $form_data)
{
if ($form_data['id']=='2368')
{
if ( isset($_POST['wpcf-immagine-del-profilo']) )
{
global $blog_id, $wpdb;
// get the url of the custom user field
$imageUrl = get_user_meta($post_id, 'wpcf-immagine-del-profilo', true);
// get the ID of the uploaded image
$imageid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid=%s", $imageUrl) );
// add it to saved post meta
update_user_meta($post_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', $imageid);
}
}
}