• Resolved shayno90

    (@shayno90)


    Hi Team,
    I was advised to write here from you sales rep. I am using the free version and I saw that you include User Registration with the option to add custom data to the user meta. Amazing.

    However, I want my users to upload a profile photo. I have this field created with ACF and attached to the User Meta. However, when I create a file upload field in your form, and link it on your backend, the media file does not attach to the custom field. It uploads fine and is saved in the Media Library, but it’s just not sticking.

    Any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @shayno90

    I hope you are doing good today.

    I pinged our Forminator and SLS Team to review this. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Thread Starter shayno90

    (@shayno90)

    Hi Kris!

    That would be amazing! Thank you so much!

    Hello @shayno90 !

    Our SLS team will be looking into this for you and will check for a fix. I’ve just created a task on their request and as soon as we hear back from them, we’ll update you here as well.

    Warm regards,
    Pawel

    Hello again @shayno90 !

    Got some good news, our SLS team have created a snippet for this case:

    <?php
    /**
     * Plugin Name: [Forminator] - Map ACF to upload field.
     * Plugin URI: https://wpmudev.com/
     * Description: Map ACF fields to upload field of Forminator when adding meta user.
     * Author: Abdoljabbar Bakhshande
     * Author URI: https://wpmudev.com/
     * Task: SLS-3140
     * License: GPLv2 or later
     *
     * @package WordPress
     */
    
    if ( ! defined( 'ABSPATH' ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
    	return;
    }
    add_filter( 'forminator_replace_form_data', 'forminator_mu_map_acf_upload_field', 10, 4 );
    
    function forminator_mu_map_acf_upload_field( $content, $data, $fields, $original_content ) {
    	if ( 'registration' === $data['form_type'] && ! empty( $original_content ) && empty( $content ) ) { // Check if it is registration form.
    		$form_id          = $data['form_id'];
    		$email            = $data['email-1'];
    		$original_content = str_replace( array( '{', '}' ), '', $original_content ); // Remove { and }.
    		$entry_model      = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $form_id ); // Get latest entry.
    		if ( $entry_model->meta_data['email-1']['value'] === $email ) { // Check if email is same.
    			if ( isset( $entry_model->meta_data[ $original_content ] ) ) { // Check if field exists.
    				$content = $entry_model->meta_data[ $original_content ]['value']; // Get value.
    				if ( is_array( $content ) && isset( $content['file'] ) ) { // Check if file exists.
    					$file_url = $content['file']['file_url']; // Get file url.
    					$content  = attachment_url_to_postid( $file_url ); // Get attachment id because ACF file field only accept attachment id.
    				}
    			}
    		}
    	}
    	return $content;
    }

    Please copy the above code to a file and place it in wp-content/mu-plugins – the filename can be anything, but please make sure the extension is .php

    Once that’s done, please also enable the option “Show files in media library” on the upload field on the form as it will be necessary for the snippet to work.

    In ACF you can use any of the field types: image or file.

    Best regards,
    Pawel

    Thread Starter shayno90

    (@shayno90)

    You guys are incredible! Thank you so very much. Did everything as you asked and it works perfectly!!

    Thread Starter shayno90

    (@shayno90)

    Solved ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘File upload to Custom User Meta field (ACF)’ is closed to new replies.