Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @shayno90,

    I could notice anomalies regarding this. I’m escalating this further to our developer’s attention to check further on what might be causing it and will get back to you via the ticket with a workaround.

    Please do note that developers work on complex queries and have a slow response time. We’ll keep you posted once we get further feedback.

    Kind Regards,
    Nithin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @shayno90,

    Hope you are doing good today.

    Could you please try the following snippet instead of the old one and see whether it works fine or not:
    https://gist.github.com/wpmudev-sls/2d84f4777a108913d3952d8e4ddc21c2

    You can apply it as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Kind Regards,
    Nithin

    Thread Starter shayno90

    (@shayno90)

    Hi Nithin!

    Thank you so much for this. I will give it a try soon and get back to you. I had a quick look through it and I noticed that there is only one mention of “Upload-1” where I have 2 fields (profile photo – Upload-1, and Cover Photo – Upload-2). Does your code support both or do we need to wiggle in another line for Upload-2?

    Thanks so much for the help!

    Thread Starter shayno90

    (@shayno90)

    Hi Nithin, anything here regarding my previous query?

    Thread Starter shayno90

    (@shayno90)

    Hello? Any feedback here?

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @shayno90,

    Extremely sorry for the delay in getting back. Seems like I missed your follow-up.

    The snippet was shared based on your previous ticket, if there are more upload files, then it’ll require further tweaking; however, it would be helpful if you could share your form export so that we could have a better idea.

    Could you please share your form export so that we could check and see if there are any further updates in the snippet required or not?

    Please check the following doc on how to export a form:
    https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export

    You can share the export file via Google Drive, Dropbox or any cloud services in the next reply.

    Looking forward to your response.

    Kind Regards,
    Nithin

    Thread Starter shayno90

    (@shayno90)

    Hi Nithin,

    Sure thing – here is a link to the form export. Thank you so much for your help!

    Cheers,

    Shayne

    link: https://www.dropbox.com/s/v29v6zriq28oeel/forminator-contributor-registration-form-export.txt?dl=1

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @shayno90

    Thank you for response!

    Please try following modification in that new code that we shared recently: replace this part

    if ( '{upload-1}' !== $original_content ) {// Change {upload-1} to your upload field name if needed.
    	return $content;
    }

    with this code

    $my_fields = array( '{upload-1', '{upload-2}' ); // upload fileds IDs
    if ( ! in_array( $origial_content, $my_fields ) ) {
    	return $content;
    }

    I think this should work for you out of the box.

    Best regards,
    Adam

    Thread Starter shayno90

    (@shayno90)

    Hey guys,

    sadly this doesn’t work. No uploaded image is stored in the custom field.

    Cheers,

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello there @shayno90

    I pinged our developers to have another look considering the two Upload fields. We’ll keep you posted here as soon as there’s any development on this. ??

    Thank you,
    Dimitris

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @shayno90

    I hope you are doing well.

    Can you please replace the previous code using this instead?

    <?php
    /**
     * Plugin Name: [Forminator] - Updated version of 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-4029
     * 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, 3 );
    
    function forminator_mu_map_acf_upload_field( $content, $data, $original_content ) {
    	if ( 'registration' === $data['form_type'] && ! empty( $original_content ) ) { // Check if it is registration form.
    		// Check if it is upload field that is mapped to ACF.
            $upload_fields = array( '{upload-1}', '{upload-2}' ); // upload fileds IDs
            if ( ! in_array( $original_content, $upload_fields ) ) {
                return $content;
            }
    
    		$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.
                        $attach_id  = attachment_url_to_postid( $file_url );
    					if( $attach_id ) {
                            $content    = $attach_id; // Get attachment id because ACF file field only accept attachment id.
    						$mime_type  = wp_get_image_mime( $file_url );
    						if ( $mime_type ) {
    							$update_data = array(
    								'ID' => $attach_id,
    								'post_mime_type' => $mime_type,
    							);
    							wp_update_post( $update_data );
    						}
    					}
    				}
    			}
    		}
    	}
    	return $content;
    }

    Best Regards
    Patrick Freitas

    Thread Starter shayno90

    (@shayno90)

    Hi Patrick!

    This works perfectly! Thank you so, so much!

    Cheers,

    Shayne

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Images not being stored in Custom Field’ is closed to new replies.