Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function moometric_dynamic_attachments( $cf7 ) {
- $submission = WPCF7_Submission::get_instance();
- if ( !$submission ) {
- return false;
- }
- $post_url = $submission->get_meta( 'url' );
- $post_id = url_to_postid( $post_url );
- if ( !$post_id ) {
- return false;
- }
- $field = get_post_custom( $post_id );
- if ( !$field ) {
- return false;
- }
- foreach ( $field as $key => $id ) {
- if ( strpos( $key, "_acf_uploadfield", 0 ) === 0 ) {
- $file = get_attached_file( $id[0], false );
- if ( !$file ) {
- continue;
- }
- $name = basename( $file );
- $temp = sys_get_temp_dir() . "/" . $name;
- if ( copy( $file, $temp ) ) {
- $submission->add_uploaded_file($key, $temp );
- }
- }
- }
- return true;
- }
- add_action( 'wpcf7_before_send_mail', 'moometric_dynamic_attachments' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement