SHARE
TWEET

Untitled

a guest Oct 14th, 2017 140 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function moometric_dynamic_attachments( $cf7 ) {
  2.     $submission = WPCF7_Submission::get_instance();
  3.  
  4.     if ( !$submission ) {
  5.         return false;
  6.     }
  7.  
  8.     $post_url = $submission->get_meta( 'url' );
  9.     $post_id = url_to_postid( $post_url );
  10.  
  11.     if ( !$post_id ) {
  12.         return false;
  13.     }
  14.  
  15.     $field = get_post_custom( $post_id );
  16.  
  17.     if ( !$field ) {
  18.         return false;
  19.     }
  20.  
  21.     foreach ( $field as $key => $id ) {
  22.         if ( strpos( $key, "_acf_uploadfield", 0 ) === 0 ) {
  23.             $file = get_attached_file( $id[0], false );
  24.  
  25.             if ( !$file ) {
  26.                 continue;
  27.             }
  28.                
  29.             $name = basename( $file );
  30.             $temp = sys_get_temp_dir() . "/" . $name;
  31.             if ( copy( $file, $temp ) ) {
  32.                 $submission->add_uploaded_file($key, $temp );
  33.             }
  34.         }
  35.     }
  36.  
  37.     return true;
  38. }
  39.  
  40. add_action( 'wpcf7_before_send_mail', 'moometric_dynamic_attachments' );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top