Skip Navigation

[Resolved] CRED user form get full link of image field

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by andreaC-10 4 years, 8 months ago.

Author
Posts
#1547957

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

#1548597

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);
        }
    }
}