PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +72 -83 6.25.1 → trunk View file →
@@ -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();
@@ -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,8 +234,9 @@
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'] ) ) {
@@ -437,9 +436,10 @@
437 436 * @return void
438 437 */
439 438 private function add_autop() {
440 439 $message = $this->message;
441 - $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
440 + preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
441 +
442 442 if ( ! empty( $match[1] ) ) {
443 443 $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
444 444 } else {
445 445 $this->message = trim( wpautop( $message ) );
@@ -484,28 +484,24 @@
484 484 * @return bool|mixed|void
485 485 */
486 486 public function should_send() {
487 487 if ( ! $this->has_recipients() ) {
488 - $send = false;
489 - } else {
490 -
491 - $filter_args = array(
492 - 'message' => $this->message,
493 - 'subject' => $this->subject,
494 - 'recipient' => $this->to,
495 - 'header' => $this->package_header(),
496 - );
497 -
498 - /**
499 - * Stop an email based on the message, subject, recipient,
500 - * or any information included in the email header
501 - *
502 - * @since 2.2.8
503 - */
504 - $send = apply_filters( 'frm_send_email', true, $filter_args );
488 + return false;
505 489 }
506 490
507 - 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 );
508 504 }
509 505
510 506 /**
511 507 * Check if an email has any recipients
@@ -514,12 +510,9 @@
514 510 *
515 511 * @return bool
516 512 */
517 513 private function has_recipients() {
518 - if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
519 - return false;
520 - }
521 - return true;
514 + return $this->to || $this->cc || $this->bcc;
522 515 }
523 516
524 517 /**
525 518 * Send an email
@@ -532,8 +525,9 @@
532 525 $this->remove_buddypress_filters();
533 526 $this->add_mandrill_filter();
534 527
535 528 $sent = false;
529 +
536 530 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
537 531 foreach ( $this->to as $recipient ) {
538 532 $sent = $this->send_single( $recipient );
539 533 }
@@ -565,15 +559,15 @@
565 559 )
566 560 );
567 561
568 562 $subject = $this->encode_subject( $this->subject );
563 + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
569 564
570 - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
571 -
572 565 if ( ! $sent ) {
573 566 if ( is_array( $header ) ) {
574 567 $header = implode( "\r\n", $header );
575 568 }
569 +
576 570 $recipient = implode( ',', (array) $recipient );
577 571 $sent = mail( $recipient, $subject, $this->message, $header );
578 572 }
579 573
@@ -591,13 +585,13 @@
591 585 */
592 586 private function package_header() {
593 587 $header = array();
594 588
595 - if ( ! empty( $this->cc ) ) {
589 + if ( $this->cc ) {
596 590 $header[] = 'CC: ' . implode( ',', $this->cc );
597 591 }
598 592
599 - if ( ! empty( $this->bcc ) ) {
593 + if ( $this->bcc ) {
600 594 $header[] = 'BCC: ' . implode( ',', $this->bcc );
601 595 }
602 596
603 597 $header[] = 'From: ' . $this->from;
@@ -622,8 +616,9 @@
622 616 'field_key' => '',
623 617 );
624 618
625 619 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
620 +
626 621 if ( $user_id_args['field_id'] ) {
627 622 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
628 623 }
629 624
@@ -640,11 +635,11 @@
640 635 *
641 636 * @return string
642 637 */
643 638 private function prepare_email_setting( $value, $user_id_args ) {
644 - if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) {
639 + if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) {
645 640 $value = str_replace( '[' . $user_id_args['field_id'] . ']', '[' . $user_id_args['field_id'] . ' show="user_email"]', $value );
646 - } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) {
641 + } elseif ( str_contains( $value, '[' . $user_id_args['field_key'] . ']' ) ) {
647 642 $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value );
648 643 }
649 644
650 645 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
@@ -650,11 +645,10 @@
650 645 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
651 646
652 647 // Remove brackets and add a space in case there isn't one
653 648 $value = str_replace( '<', ' ', $value );
654 - $value = str_replace( array( '"', '>' ), '', $value );
655 649
656 - return $value;
650 + return str_replace( array( '"', '>' ), '', $value );
657 651 }
658 652
659 653 /**
660 654 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -663,19 +657,13 @@
663 657 * @since 2.03.04
664 658 *
665 659 * @param string $emails
666 660 *
667 - * @return array|string $emails
661 + * @return array|string Emails.
668 662 */
669 663 private function explode_emails( $emails ) {
670 - $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
671 - if ( is_array( $emails ) ) {
672 - $emails = array_map( 'trim', $emails );
673 - } else {
674 - $emails = trim( $emails );
675 - }
676 -
677 - return $emails;
664 + $emails = $emails ? preg_split( '/(,|;)/', $emails ) : '';
665 + return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails );
678 666 }
679 667
680 668 /**
681 669 * Format the recipients( to, cc, bcc)
@@ -684,9 +672,9 @@
684 672 *
685 673 * @return array
686 674 */
687 675 private function format_recipients( $recipients ) {
688 - if ( empty( $recipients ) ) {
676 + if ( ! $recipients ) {
689 677 return $recipients;
690 678 }
691 679
692 680 foreach ( $recipients as $key => $val ) {
@@ -699,17 +687,17 @@
699 687
700 688 $parts = explode( ' ', $val );
701 689 $email = end( $parts );
702 690
703 - if ( is_email( $email ) ) {
704 - // If user enters a name and email
705 - $name = trim( str_replace( $email, '', $val ) );
706 - } else {
691 + if ( ! is_email( $email ) ) {
707 692 // If user enters a name without an email
708 693 unset( $recipients[ $key ] );
709 694 continue;
710 695 }
711 696
697 + // If user enters a name and email
698 + $name = trim( str_replace( $email, '', $val ) );
699 +
712 700 $recipients[ $key ] = $this->format_from_email( $name, $email );
713 701 }//end foreach
714 702
715 703 return $recipients;
@@ -732,14 +720,14 @@
732 720 } else {
733 721 list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from );
734 722 }
735 723
736 - // if sending the email from a yahoo address, change it to the WordPress default
737 - if ( strpos( $from_email, '@yahoo.com' ) ) {
738 -
724 + // If sending the email from a yahoo address, change it to the WordPress default
725 + if ( str_contains( $from_email, '@yahoo.com' ) ) {
739 726 // Get the site domain and get rid of www.
740 727 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
741 - if ( substr( $sitename, 0, 4 ) === 'www.' ) {
728 +
729 + if ( str_starts_with( $sitename, 'www.' ) ) {
742 730 $sitename = substr( $sitename, 4 );
743 731 }
744 732
745 733 $from_email = 'wordpress@' . $sitename;
@@ -778,9 +766,10 @@
778 766 * @return string
779 767 */
780 768 private function get_email_from_name( $name ) {
781 769 $email = trim( trim( $name, '>' ), '<' );
782 - if ( strpos( $email, '<' ) !== false ) {
770 +
771 + if ( str_contains( $email, '<' ) ) {
783 772 $parts = explode( '<', $email );
784 773 $email = trim( $parts[1], '>' );
785 774 }
786 775
@@ -815,15 +804,13 @@
815 804 * @since 3.0.06
816 805 *
817 806 * @param string $name
818 807 * @param string $email
808 + *
809 + * @return string
819 810 */
820 811 private function format_from_email( $name, $email ) {
821 - if ( '' !== $name ) {
822 - $email = $name . ' <' . $email . '>';
823 - }
824 -
825 - return $email;
812 + return '' !== $name ? $name . ' <' . $email . '>' : $email;
826 813 }
827 814
828 815 /**
829 816 * Remove phone numbers from To addresses
@@ -833,35 +820,37 @@
833 820 *
834 821 * @return void
835 822 */
836 823 private function handle_phone_numbers() {
824 + foreach ( $this->to as $key => $recipient ) {
825 + if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
826 + continue;
827 + }
837 828
838 - foreach ( $this->to as $key => $recipient ) {
839 - if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
840 - $recipient = explode( ' ', $recipient );
829 + $recipient = explode( ' ', $recipient );
841 830
842 - if ( is_email( end( $recipient ) ) ) {
843 - continue;
844 - }
831 + if ( is_email( end( $recipient ) ) ) {
832 + continue;
833 + }
845 834
846 - do_action(
847 - 'frm_send_to_not_email',
848 - array(
849 - 'e' => $recipient,
850 - 'subject' => $this->subject,
851 - 'mail_body' => $this->message,
852 - 'reply_to' => $this->reply_to,
853 - 'from' => $this->from,
854 - 'plain_text' => $this->is_plain_text,
855 - 'attachments' => $this->attachments,
856 - 'form' => $this->form,
857 - 'email_key' => $key,
858 - )
859 - );
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 + );
860 849
861 - // Remove phone number from to addresses
862 - unset( $this->to[ $key ] );
863 - }//end if
850 + // Remove phone number from to addresses
851 + unset( $this->to[ $key ] );
852 + // end if
864 853 }//end foreach
865 854 }
866 855
867 856 /**
@@ -934,9 +923,9 @@
934 923 * @return string
935 924 */
936 925 private function encode_subject( $subject ) {
937 926 if ( apply_filters( 'frm_encode_subject', false, $subject ) ) {
938 - $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
927 + return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
939 928 }
940 929
941 930 return $subject;
942 931 }