PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmEmail.php +131 -126 6.326.2 View file →
@@ -8,94 +8,94 @@
8 8 */
9 9 class FrmEmail {
10 10
11 11 /**
12 - * @var string
12 + * @var string $email_key
13 13 */
14 14 private $email_key = '';
15 15
16 16 /**
17 - * @var array
17 + * @var array $to
18 18 */
19 19 private $to = array();
20 20
21 21 /**
22 - * @var array
22 + * @var array $cc
23 23 */
24 24 private $cc = array();
25 25
26 26 /**
27 - * @var array
27 + * @var array $bcc
28 28 */
29 29 private $bcc = array();
30 30
31 31 /**
32 - * @var string
32 + * @var string $from
33 33 */
34 34 private $from = '';
35 35
36 36 /**
37 - * @var string
37 + * @var string $reply_to
38 38 */
39 39 private $reply_to = '';
40 40
41 41 /**
42 - * @var string
42 + * @var string $subject
43 43 */
44 44 private $subject = '';
45 45
46 46 /**
47 - * @var string
47 + * @var string $message
48 48 */
49 49 private $message = '';
50 50
51 51 /**
52 - * @var array
52 + * @var array $attachments
53 53 */
54 54 private $attachments = array();
55 55
56 56 /**
57 - * @var bool
57 + * @var bool $is_plain_text
58 58 */
59 59 private $is_plain_text = false;
60 60
61 61 /**
62 - * @var bool
62 + * @var bool $is_single_recipient
63 63 */
64 64 private $is_single_recipient = false;
65 65
66 66 /**
67 - * @var bool
67 + * @var bool $include_user_info
68 68 */
69 69 private $include_user_info = false;
70 70
71 71 /**
72 - * @var string
72 + * @var string $charset
73 73 */
74 74 private $charset = '';
75 75
76 76 /**
77 - * @var string
77 + * @var string $content_type
78 78 */
79 79 private $content_type = 'text/html';
80 80
81 81 /**
82 - * @var array
82 + * @var array $settings
83 83 */
84 84 private $settings = array();
85 85
86 86 /**
87 - * @var stdClass
87 + * @var stdClass $entry
88 88 */
89 89 private $entry;
90 90
91 91 /**
92 - * @var stdClass
92 + * @var stdClass $form
93 93 */
94 94 private $form;
95 95
96 96 /**
97 - * @var int
97 + * @var int $action_id
98 98 */
99 99 private $action_id = 0;
100 100
101 101 /**
@@ -175,9 +175,9 @@
175 175 $to = apply_filters( 'frm_to_email', $to, $values, $this->form->id, $args );
176 176
177 177 $this->to = array_unique( (array) $to );
178 178
179 - if ( ! $this->to ) {
179 + if ( empty( $this->to ) ) {
180 180 return;
181 181 }
182 182
183 183 $this->handle_phone_numbers();
@@ -216,9 +216,9 @@
216 216 *
217 217 * @since 2.03.04
218 218 *
219 219 * @param string $recipients
220 - * @param array $user_id_args
220 + * @param array $user_id_args
221 221 *
222 222 * @return array
223 223 */
224 224 private function prepare_additional_recipients( $recipients, $user_id_args ) {
@@ -223,11 +223,13 @@
223 223 */
224 224 private function prepare_additional_recipients( $recipients, $user_id_args ) {
225 225 $recipients = $this->prepare_email_setting( $recipients, $user_id_args );
226 226 $recipients = $this->explode_emails( $recipients );
227 +
227 228 $recipients = array_unique( (array) $recipients );
229 + $recipients = $this->format_recipients( $recipients );
228 230
229 - return $this->format_recipients( $recipients );
231 + return $recipients;
230 232 }
231 233
232 234 /**
233 235 * Set the From addresses
@@ -234,14 +236,13 @@
234 236 *
235 237 * @since 2.03.04
236 238 *
237 239 * @param array $user_id_args
238 - *
239 240 * @return void
240 241 */
241 242 private function set_from( $user_id_args ) {
242 243 if ( empty( $this->settings['from'] ) ) {
243 - $from = FrmEmailHelper::get_default_from_email();
244 + $from = get_option( 'admin_email' );
244 245 } else {
245 246 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
246 247 }
247 248
@@ -279,15 +280,11 @@
279 280 *
280 281 * @return void
281 282 */
282 283 private function set_is_plain_text() {
283 - if ( empty( $this->settings['email_style'] ) ) {
284 - // If `email_style` isn't set, use the `plain_text` checkbox.
285 - $this->is_plain_text = ! empty( $this->settings['plain_text'] );
286 - return;
284 + if ( $this->settings['plain_text'] ) {
285 + $this->is_plain_text = true;
287 286 }
288 -
289 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
290 287 }
291 288
292 289 /**
293 290 * Set the include_user_info property
@@ -307,8 +304,9 @@
307 304 * Set the is_single_recipient property
308 305 *
309 306 * @since 2.03.04
310 307 *
308 + * @param $action
311 309 * @param object $action
312 310 *
313 311 * @return void
314 312 */
@@ -388,31 +386,28 @@
388 386 private function set_message() {
389 387 $this->message = $this->settings['email_message'];
390 388
391 389 if ( ! $this->is_plain_text ) {
392 - // The decode is to support [default-html] shortcodes.
393 - $this->message = html_entity_decode( $this->message );
390 + $this->message = html_entity_decode( $this->message ); // The decode is to support [default-html] shortcodes.
394 391 }
395 392
396 - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
393 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
394 +
397 395 $prev_mail_body = $this->message;
398 -
399 - // Make a copy to prevent changes by reference.
400 - $pass_entry = clone $this->entry;
401 - $mail_body = FrmEntriesHelper::replace_default_message(
396 + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference
397 + $mail_body = FrmEntriesHelper::replace_default_message(
402 398 $prev_mail_body,
403 399 array(
404 - 'id' => $this->entry->id,
405 - 'entry' => $pass_entry,
406 - 'plain_text' => $this->is_plain_text,
407 - 'user_info' => $this->include_user_info,
408 - 'table_style' => $this->settings['email_style'],
400 + 'id' => $this->entry->id,
401 + 'entry' => $pass_entry,
402 + 'plain_text' => $this->is_plain_text,
403 + 'user_info' => $this->include_user_info,
409 404 )
410 405 );
411 406
412 407 // Add the user info if it isn't already included
413 408 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
414 - $data = $this->entry->description;
409 + $data = $this->entry->description;
415 410 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
416 411 $this->maybe_add_ip( $mail_body );
417 412 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
418 413 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -419,11 +414,12 @@
419 414 }
420 415
421 416 $this->message = $mail_body;
422 417
418 + $this->message = do_shortcode( $this->message );
419 +
423 420 if ( $this->is_plain_text ) {
424 421 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
425 - $this->message = str_replace( ' ', '', $this->message );
426 422 } else {
427 423 $this->add_autop();
428 424 }
429 425
@@ -436,10 +432,9 @@
436 432 * @return void
437 433 */
438 434 private function add_autop() {
439 435 $message = $this->message;
440 - preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
441 -
436 + $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
442 437 if ( ! empty( $match[1] ) ) {
443 438 $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
444 439 } else {
445 440 $this->message = trim( wpautop( $message ) );
@@ -484,24 +479,28 @@
484 479 * @return bool|mixed|void
485 480 */
486 481 public function should_send() {
487 482 if ( ! $this->has_recipients() ) {
488 - return false;
483 + $send = false;
484 + } else {
485 +
486 + $filter_args = array(
487 + 'message' => $this->message,
488 + 'subject' => $this->subject,
489 + 'recipient' => $this->to,
490 + 'header' => $this->package_header(),
491 + );
492 +
493 + /**
494 + * Stop an email based on the message, subject, recipient,
495 + * or any information included in the email header
496 + *
497 + * @since 2.2.8
498 + */
499 + $send = apply_filters( 'frm_send_email', true, $filter_args );
489 500 }
490 501
491 - $filter_args = array(
492 - 'message' => $this->message,
493 - 'subject' => $this->subject,
494 - 'recipient' => $this->to,
495 - 'header' => $this->package_header(),
496 - );
497 - /**
498 - * Stop an email based on the message, subject, recipient,
499 - * or any information included in the email header
500 - *
501 - * @since 2.2.8
502 - */
503 - return apply_filters( 'frm_send_email', true, $filter_args );
502 + return $send;
504 503 }
505 504
506 505 /**
507 506 * Check if an email has any recipients
@@ -510,9 +509,13 @@
510 509 *
511 510 * @return bool
512 511 */
513 512 private function has_recipients() {
514 - return $this->to || $this->cc || $this->bcc;
513 + if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
514 + return false;
515 + } else {
516 + return true;
517 + }
515 518 }
516 519
517 520 /**
518 521 * Send an email
@@ -525,9 +528,8 @@
525 528 $this->remove_buddypress_filters();
526 529 $this->add_mandrill_filter();
527 530
528 531 $sent = false;
529 -
530 532 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
531 533 foreach ( $this->to as $recipient ) {
532 534 $sent = $this->send_single( $recipient );
533 535 }
@@ -559,15 +561,15 @@
559 561 )
560 562 );
561 563
562 564 $subject = $this->encode_subject( $this->subject );
563 - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
564 565
566 + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
567 +
565 568 if ( ! $sent ) {
566 569 if ( is_array( $header ) ) {
567 570 $header = implode( "\r\n", $header );
568 571 }
569 -
570 572 $recipient = implode( ',', (array) $recipient );
571 573 $sent = mail( $recipient, $subject, $this->message, $header );
572 574 }
573 575
@@ -585,13 +587,13 @@
585 587 */
586 588 private function package_header() {
587 589 $header = array();
588 590
589 - if ( $this->cc ) {
591 + if ( ! empty( $this->cc ) ) {
590 592 $header[] = 'CC: ' . implode( ',', $this->cc );
591 593 }
592 594
593 - if ( $this->bcc ) {
595 + if ( ! empty( $this->bcc ) ) {
594 596 $header[] = 'BCC: ' . implode( ',', $this->bcc );
595 597 }
596 598
597 599 $header[] = 'From: ' . $this->from;
@@ -605,9 +607,9 @@
605 607 * Get the userID field ID and key for email settings
606 608 *
607 609 * @since 2.03.04
608 610 *
609 - * @param int $form_id
611 + * @param $form_id
610 612 *
611 613 * @return array
612 614 */
613 615 private function get_user_id_args( $form_id ) {
@@ -616,9 +618,8 @@
616 618 'field_key' => '',
617 619 );
618 620
619 621 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
620 -
621 622 if ( $user_id_args['field_id'] ) {
622 623 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
623 624 }
624 625
@@ -630,16 +631,16 @@
630 631 *
631 632 * @since 2.03.04
632 633 *
633 634 * @param string $value
634 - * @param array $user_id_args
635 + * @param array $user_id_args
635 636 *
636 637 * @return string
637 638 */
638 639 private function prepare_email_setting( $value, $user_id_args ) {
639 - if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) {
640 + if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) {
640 641 $value = str_replace( '[' . $user_id_args['field_id'] . ']', '[' . $user_id_args['field_id'] . ' show="user_email"]', $value );
641 - } elseif ( str_contains( $value, '[' . $user_id_args['field_key'] . ']' ) ) {
642 + } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) {
642 643 $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value );
643 644 }
644 645
645 646 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
@@ -645,10 +646,11 @@
645 646 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
646 647
647 648 // Remove brackets and add a space in case there isn't one
648 649 $value = str_replace( '<', ' ', $value );
650 + $value = str_replace( array( '"', '>' ), '', $value );
649 651
650 - return str_replace( array( '"', '>' ), '', $value );
652 + return $value;
651 653 }
652 654
653 655 /**
654 656 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -657,13 +659,19 @@
657 659 * @since 2.03.04
658 660 *
659 661 * @param string $emails
660 662 *
661 - * @return array|string Emails.
663 + * @return array|string $emails
662 664 */
663 665 private function explode_emails( $emails ) {
664 - $emails = $emails ? preg_split( '/(,|;)/', $emails ) : '';
665 - return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails );
666 + $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
667 + if ( is_array( $emails ) ) {
668 + $emails = array_map( 'trim', $emails );
669 + } else {
670 + $emails = trim( $emails );
671 + }
672 +
673 + return $emails;
666 674 }
667 675
668 676 /**
669 677 * Format the recipients( to, cc, bcc)
@@ -672,9 +680,9 @@
672 680 *
673 681 * @return array
674 682 */
675 683 private function format_recipients( $recipients ) {
676 - if ( ! $recipients ) {
684 + if ( empty( $recipients ) ) {
677 685 return $recipients;
678 686 }
679 687
680 688 foreach ( $recipients as $key => $val ) {
@@ -682,24 +690,24 @@
682 690
683 691 if ( is_email( $val ) ) {
684 692 // If a plain email is used, no formatting is needed
685 693 continue;
686 - }
694 + } else {
695 + $parts = explode( ' ', $val );
696 + $email = end( $parts );
687 697
688 - $parts = explode( ' ', $val );
689 - $email = end( $parts );
690 -
691 - if ( ! is_email( $email ) ) {
692 - // If user enters a name without an email
693 - unset( $recipients[ $key ] );
694 - continue;
698 + if ( is_email( $email ) ) {
699 + // If user enters a name and email
700 + $name = trim( str_replace( $email, '', $val ) );
701 + } else {
702 + // If user enters a name without an email
703 + unset( $recipients[ $key ] );
704 + continue;
705 + }
695 706 }
696 707
697 - // If user enters a name and email
698 - $name = trim( str_replace( $email, '', $val ) );
699 -
700 708 $recipients[ $key ] = $this->format_from_email( $name, $email );
701 - }//end foreach
709 + }
702 710
703 711 return $recipients;
704 712 }
705 713
@@ -720,14 +728,14 @@
720 728 } else {
721 729 list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from );
722 730 }
723 731
724 - // If sending the email from a yahoo address, change it to the WordPress default
725 - if ( str_contains( $from_email, '@yahoo.com' ) ) {
732 + // if sending the email from a yahoo address, change it to the WordPress default
733 + if ( strpos( $from_email, '@yahoo.com' ) ) {
734 +
726 735 // Get the site domain and get rid of www.
727 736 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
728 -
729 - if ( str_starts_with( $sitename, 'www.' ) ) {
737 + if ( substr( $sitename, 0, 4 ) === 'www.' ) {
730 738 $sitename = substr( $sitename, 4 );
731 739 }
732 740
733 741 $from_email = 'wordpress@' . $sitename;
@@ -749,9 +757,9 @@
749 757 $reply_to = trim( $reply_to );
750 758
751 759 if ( ! is_email( $reply_to ) ) {
752 760 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
753 - $reply_to = $this->format_from_email( $name, $email );
761 + $reply_to = $this->format_from_email( $name, $email );
754 762 }
755 763
756 764 return $reply_to;
757 765 }
@@ -766,10 +774,9 @@
766 774 * @return string
767 775 */
768 776 private function get_email_from_name( $name ) {
769 777 $email = trim( trim( $name, '>' ), '<' );
770 -
771 - if ( str_contains( $email, '<' ) ) {
778 + if ( strpos( $email, '<' ) !== false ) {
772 779 $parts = explode( '<', $email );
773 780 $email = trim( $parts[1], '>' );
774 781 }
775 782
@@ -804,13 +811,15 @@
804 811 * @since 3.0.06
805 812 *
806 813 * @param string $name
807 814 * @param string $email
808 - *
809 - * @return string
810 815 */
811 816 private function format_from_email( $name, $email ) {
812 - return '' !== $name ? $name . ' <' . $email . '>' : $email;
817 + if ( '' !== $name ) {
818 + $email = $name . ' <' . $email . '>';
819 + }
820 +
821 + return $email;
813 822 }
814 823
815 824 /**
816 825 * Remove phone numbers from To addresses
@@ -820,38 +829,36 @@
820 829 *
821 830 * @return void
822 831 */
823 832 private function handle_phone_numbers() {
833 +
824 834 foreach ( $this->to as $key => $recipient ) {
825 - if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
826 - continue;
827 - }
835 + if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
836 + $recipient = explode( ' ', $recipient );
828 837
829 - $recipient = explode( ' ', $recipient );
838 + if ( is_email( end( $recipient ) ) ) {
839 + continue;
840 + }
830 841
831 - if ( is_email( end( $recipient ) ) ) {
832 - continue;
842 + do_action(
843 + 'frm_send_to_not_email',
844 + array(
845 + 'e' => $recipient,
846 + 'subject' => $this->subject,
847 + 'mail_body' => $this->message,
848 + 'reply_to' => $this->reply_to,
849 + 'from' => $this->from,
850 + 'plain_text' => $this->is_plain_text,
851 + 'attachments' => $this->attachments,
852 + 'form' => $this->form,
853 + 'email_key' => $key,
854 + )
855 + );
856 +
857 + // Remove phone number from to addresses
858 + unset( $this->to[ $key ] );
833 859 }
834 -
835 - do_action(
836 - 'frm_send_to_not_email',
837 - array(
838 - 'e' => $recipient,
839 - 'subject' => $this->subject,
840 - 'mail_body' => $this->message,
841 - 'reply_to' => $this->reply_to,
842 - 'from' => $this->from,
843 - 'plain_text' => $this->is_plain_text,
844 - 'attachments' => $this->attachments,
845 - 'form' => $this->form,
846 - 'email_key' => $key,
847 - )
848 - );
849 -
850 - // Remove phone number from to addresses
851 - unset( $this->to[ $key ] );
852 - // end if
853 - }//end foreach
860 + }
854 861 }
855 862
856 863 /**
857 864 * Package an array of FrmEmail properties
@@ -870,12 +877,10 @@
870 877 'subject' => $this->subject,
871 878 'message' => $this->message,
872 879 'attachments' => $this->attachments,
873 880 'plain_text' => $this->is_plain_text,
874 - 'email_key' => $this->email_key,
875 881 'form' => $this->form,
876 882 'entry' => $this->entry,
877 - 'email_style' => $this->settings['email_style'],
878 883 );
879 884 }
880 885
881 886 /**
@@ -923,9 +928,9 @@
923 928 * @return string
924 929 */
925 930 private function encode_subject( $subject ) {
926 931 if ( apply_filters( 'frm_encode_subject', false, $subject ) ) {
927 - return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
932 + $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
928 933 }
929 934
930 935 return $subject;
931 936 }