Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter freelaxed

    (@freelaxed)

    After searching for quite some time I posted this issue. Shortly after I found the solutions, so I will post that here for future knowledge.

    I assumed all the field in the form were passed in this function, but only the ones used in the mail body are. So I needed to put [user_file_1] in my mail body to make it work.

    Thread Starter freelaxed

    (@freelaxed)

    I managed to get it work the way I need it!

    I combined ‘wpcf7_mail_tag_replaced’ with ‘wpcf7_after_flamingo’

    add_filter( 'wpcf7_mail_tag_replaced',
     function($replaced, $submitted, $html, $mail_tag) {
    
      $aRewriteTheseFields = array(
       'file_1',
       'file_2',
       'file_3,
       'file_4',
       'file_5',
       'file_6',
       'file_7',
       'file_8',
       'file_9',
       'file_10'
      );
    
      $sFieldName = $mail_tag->field_name();
    
      if(in_array($sFieldName,$aRewriteTheseFields)){
       if(!empty($submitted)){
    
       $form_to_DB = WPCF7_Submission::get_instance();
    
       if($form_to_DB){
    
        $formData = $form_to_DB->get_posted_data();
        $uploaded_files = $form_to_DB->uploaded_files();
        $data_hash = $form_to_DB->get_posted_data_hash();
    
        if(!empty($uploaded_files[$sFieldName])){
    
         $sCurrentDate = date('Y-m-d');
         $sUserName = !empty($data_hash) ? ' '.$data_hash : ' no-hash';
    
         $sUniquUser = md5($sCurrentDate.$sUserName);
         $sWpUploadDir = wp_upload_dir();
         $sWpUploadDirPath = $sWpUploadDir['basedir'].'/archive/';
         $sWpUploadDirUrl = $sWpUploadDir['baseurl'].'/archive/';
    
         $aImagesToParse = false;
    
         if(!empty($uploaded_files[$sFieldName][0])){
          $aImagesToParse = $uploaded_files[$sFieldName][0];
         }
    
         if(!empty($aImagesToParse)){		
    
          if(!is_dir($sWpUploadDirPath.$sUniquUser)) {
           mkdir($sWpUploadDirPath.$sUniquUser , 0777);
          }
    
          $sFileName = basename($aImagesToParse);
          if(copy( $aImagesToParse, $sWpUploadDirPath.$sUniquUser.'/'.$sFileName )){
           global $sFlamingoSavePaths;
    
           if(!is_array($sFlamingoSavePaths)){
            $sFlamingoSavePaths = array();
           }
    
           $sFlamingoKey = str_ireplace('file_', '',$sFieldName);
     
           $sFlamingoSavePaths[$sFlamingoKey] = $sWpUploadDirUrl.$sUniquUser.'/'.$sFileName;
    
           $replaced = '<a href="'.$sWpUploadDirUrl.$sUniquUser.'/'.$sFileName.'">'.$sFileName.'</a>';								
          }					
         }
        }				
       }
      }
     }
    
     return $replaced;
    }, 10, 4);
    function my_add_filepath_to_flamingo($result){
     // get our global var
     global $sFlamingoSavePaths;
    
     $flamingoEntryID = !empty($result['flamingo_inbound_id']) ? $result['flamingo_inbound_id'] : false;
    
     if($flamingoEntryID){
      if(!empty($sFlamingoSavePaths) && is_array($sFlamingoSavePaths)){
       foreach($sFlamingoSavePaths as $key=>$value){	
        update_post_meta( $flamingoEntryID, '_field_file_'.$key, $value);
       }
      }
     }
    }
    
    add_action('wpcf7_after_flamingo', 'my_add_filepath_to_flamingo');
Viewing 2 replies - 1 through 2 (of 2 total)