Advertisement
CodeDropz

Fixes - Multi Step Form (PRO)

Feb 23rd, 2023 (edited)
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. add_action( 'wpcf7_before_send_mail', 'drag_and_drop_cf7', 9, 2 );
  2.  
  3. function drag_and_drop_cf7( $form, $results ){
  4.     $posted_data = WPCF7_Submission::get_instance()->get_posted_data();
  5.     if ( !empty( $posted_data['cf7msm_options'] ) ) {
  6.         $options = json_decode( stripslashes( $posted_data['cf7msm_options'] ), true );
  7.         if ( ! isset( $options['last_step'] ) ) {
  8.             remove_action('wpcf7_before_send_mail','dnd_cf7_before_send_mail', 30, 1);
  9.         }else{
  10.             add_action('wpcf7_before_send_mail', 'drag_and_drop_cf7_files', 30, 1 );
  11.         }
  12.     }
  13. }
  14.  
  15. function drag_and_drop_cf7_files( $wpcf7 ){
  16.  
  17.     $posted_data =  WPCF7_Submission::get_instance()->get_posted_data();
  18.     $uploader_name = 'your-file';
  19.  
  20.     $mail = $wpcf7->prop('mail');
  21.     $mail_2 = $wpcf7->prop('mail_2');
  22.  
  23.     if( isset( $posted_data[ $uploader_name ] ) ){
  24.  
  25.         $uploads_dir = dnd_get_upload_dir();
  26.         $files = array();
  27.  
  28.         if( strpos( $posted_data[ $uploader_name ], ',' ) !== false ){
  29.             $files_array = explode(',', $posted_data[ $uploader_name ] );
  30.             if( $files_array ){
  31.                 foreach( $files_array as $file ){
  32.                     $files[] = trailingslashit( $uploads_dir['upload_url'] ) . wp_basename( $file );
  33.                 }
  34.             }
  35.         }else{
  36.             $files[] = trailingslashit( $uploads_dir['upload_url'] ) . wp_basename( $posted_data[ $uploader_name ] );
  37.         }
  38.  
  39.         // Links - 1
  40.         $mail_links = dnd_cf7_links( $files, $mail['use_html'] );
  41.         $mail['body'] = str_replace( "[$uploader_name]", "\n" . implode( "\n", $mail_links ), $mail['body'] );
  42.  
  43.         // Links - 2
  44.         if( $mail_2['active'] ) {
  45.             $mail_links_2 = dnd_cf7_links( $files, $mail_2['use_html'] );
  46.             $mail_2['body'] = str_replace( "[$uploader_name]", "\n" . implode( "\n", $mail_links_2 ), $mail_2['body'] );
  47.         }
  48.     }
  49.  
  50.     $wpcf7->set_properties( array("mail" => $mail) );
  51.  
  52.     if( $mail_2['active'] ) {
  53.         $wpcf7->set_properties( array("mail_2" => $mail_2) );
  54.     }
  55.  
  56.     return $wpcf7;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement