Images not being stored in Custom Field
-
Hey Friends,
A little while ago you helped me solve a problem where I could connect the uploaded image via the form to the User custom meta (here: https://wordpress.org/support/topic/file-upload-to-custom-user-meta-field-acf/)
I guess since the latest update, it’s not working anymore. The images upload fine but they just don’t attach to the user custom meta.
Any ideas or suggestions on what we can tweak in the plugin code?
Thanks so much!
The page I need help with: [log in to see the link]
-
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,
NithinHi @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/2d84f4777a108913d3952d8e4ddc21c2You 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-pluginsKind Regards,
NithinHi 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!
Hi Nithin, anything here regarding my previous query?
Hello? Any feedback here?
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-exportYou can share the export file via Google Drive, Dropbox or any cloud services in the next reply.
Looking forward to your response.
Kind Regards,
NithinHi 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
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,
AdamHey guys,
sadly this doesn’t work. No uploaded image is stored in the custom field.
Cheers,
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,
DimitrisHi @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 FreitasHi Patrick!
This works perfectly! Thank you so, so much!
Cheers,
Shayne
The topic ‘Images not being stored in Custom Field’ is closed to new replies.