Forminator to ACF big file adding unsuccessfully

  • Unknown's avatar

    Hello,

    I have the problem as this guy:https://wordpress.org/support/topic/image-upload-to-acf-gallery/page/2/
    I saw that my images also comes with “…-scaled”.
    I have tried to use suggested code:

    
    <?php
    add_action( 'forminator_post_data_field_post_saved', function( $post_id ){
     $GLOBALS['forminator_post_id'] = $post_id;
    
    
     add_filter( 'forminator_replace_form_data', function( $content, $data, $fields ){
     if( ! empty( $GLOBALS['forminator_post_id'] ) && false !== strpos( $content, '{post_url}' ) ){
     $content = str_replace( '{post_url}', get_permalink( $GLOBALS['forminator_post_id'] ), $content );
     }
     return $content;
     }, 10, 3 );
    } );
    
    
    add_action( 'forminator_post_data_field_post_saved', 'forminator_acf_check_compat', 10, 3 );
    function forminator_acf_check_compat( $post_id, $field, $data ) {
     
     
     $form_id = 713; // set form ID here
     $acfgal = 'galerija'; // set ACF Gallery custom field name here; same as in "Label" setting of post custom field on form
     
     ########################
     $submitted_data = Forminator_CForm_Front_Action::$prepared_data;
     if ( $submitted_data['form_id'] != $form_id ) {
     return;
     }
     
     $fields_data = $data['post-custom'];
     
     if ( !empty( $fields_data ) && is_array( $fields_data ) ) {
     
     foreach ($fields_data as $key=>$single_field) {
     
     if ($single_field['key'] === $acfgal) {
     
     $images = explode( ',', $single_field['value'] );
     
     foreach ($images as $a=>$b) {
     
     
     $single_image = trim($b);
     $single_image_ext = '.' . preg_match('/./', $single_image) ? preg_replace('/^.*./', '', $single_image) : '';
     
     
     $theimages[$a]=attachment_url_to_postid( $single_image );
     
     if ( $theimages[$a] == 0 ) {
     
     $single_image_scaled = str_ireplace( $single_image_ext, '-scaled'.$single_image_ext, $single_image ); 
     $theimages[$a] = attachment_url_to_postid( $single_image_scaled ); 
     
     }
     
     }
     
     
     
     update_post_meta( $post_id, $acfgal, $theimages );
     
     }
     
     }
     
     
     }
     
     
    }

    But this didn’t help, maybe this code needs modification?

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar

    We can’t help with third party plugins or any scripting. You’ll have to contact ACF support to solve this problem.

  • The topic ‘Forminator to ACF big file adding unsuccessfully’ is closed to new replies.