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