custom.php
6 years ago
email.php
6 years ago
option.php
6 years ago
post.php
6 years ago
term.php
6 years ago
user.php
6 years ago
email.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | if(!class_exists('acfe_form_email')): |
| 7 | |
| 8 | class acfe_form_email{ |
| 9 | |
| 10 | function __construct(){ |
| 11 | |
| 12 | add_action('acfe/form/submit/action/email', array($this, 'submit'), 1, 2); |
| 13 | |
| 14 | add_filter('acf/prepare_field/name=acfe_form_email_file', array(acfe()->acfe_form, 'map_fields_deep')); |
| 15 | |
| 16 | } |
| 17 | |
| 18 | function submit($form, $post_id){ |
| 19 | |
| 20 | $form_name = acf_maybe_get($form, 'form_name'); |
| 21 | $form_id = acf_maybe_get($form, 'form_id'); |
| 22 | $post_info = acf_get_post_id_info($post_id); |
| 23 | |
| 24 | $from = get_sub_field('acfe_form_email_from'); |
| 25 | $from = acfe_form_map_field_value($from, $_POST['acf']); |
| 26 | |
| 27 | $to = get_sub_field('acfe_form_email_to'); |
| 28 | $to = acfe_form_map_field_value($to, $_POST['acf']); |
| 29 | |
| 30 | $subject = get_sub_field('acfe_form_email_subject'); |
| 31 | $subject = acfe_form_map_field_value($subject, $_POST['acf']); |
| 32 | |
| 33 | $content = get_sub_field('acfe_form_email_content'); |
| 34 | $content = acfe_form_map_field_value($content, $_POST['acf']); |
| 35 | |
| 36 | $headers = array(); |
| 37 | $attachments = array(); |
| 38 | |
| 39 | if(have_rows('acfe_form_email_files')): |
| 40 | while(have_rows('acfe_form_email_files')): the_row(); |
| 41 | |
| 42 | $file_field_key = get_sub_field('acfe_form_email_file'); |
| 43 | $file_id = acfe_form_map_field_value($file_field_key, $_POST['acf']); |
| 44 | |
| 45 | $field = acf_get_field($file_field_key); |
| 46 | $file = acf_format_value($file_id, 0, $field); |
| 47 | |
| 48 | if(!acf_maybe_get($file, 'ID')) |
| 49 | continue; |
| 50 | |
| 51 | $attachments[] = get_attached_file($file['ID']); |
| 52 | |
| 53 | endwhile; |
| 54 | endif; |
| 55 | |
| 56 | $headers[] = 'From: ' . $from; |
| 57 | $headers[] = 'Content-Type: text/html'; |
| 58 | $headers[] = 'charset=UTF-8'; |
| 59 | |
| 60 | $args = array( |
| 61 | 'from' => $from, |
| 62 | 'to' => $to, |
| 63 | 'subject' => $subject, |
| 64 | 'content' => $content, |
| 65 | 'headers' => $headers, |
| 66 | 'attachments' => $attachments, |
| 67 | ); |
| 68 | |
| 69 | $args = apply_filters('acfe/form/submit/action/mail/args', $args, $form, $post_id); |
| 70 | $args = apply_filters('acfe/form/submit/action/mail/args/name=' . $form_name, $args, $form, $post_id); |
| 71 | $args = apply_filters('acfe/form/submit/action/mail/args/id=' . $form_id, $args, $form, $post_id); |
| 72 | |
| 73 | if(!$args) |
| 74 | return; |
| 75 | |
| 76 | wp_mail($args['to'], $args['subject'], $args['content'], $args['headers'], $args['attachments']); |
| 77 | |
| 78 | } |
| 79 | |
| 80 | } |
| 81 | |
| 82 | new acfe_form_email(); |
| 83 | |
| 84 | endif; |