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 +62 -83 6.26 → 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
@@ -486,28 +484,24 @@
486 484 * @return bool|mixed|void
487 485 */
488 486 public function should_send() {
489 487 if ( ! $this->has_recipients() ) {
490 - $send = false;
491 - } else {
492 -
493 - $filter_args = array(
494 - 'message' => $this->message,
495 - 'subject' => $this->subject,
496 - 'recipient' => $this->to,
497 - 'header' => $this->package_header(),
498 - );
499 -
500 - /**
501 - * Stop an email based on the message, subject, recipient,
502 - * or any information included in the email header
503 - *
504 - * @since 2.2.8
505 - */
506 - $send = apply_filters( 'frm_send_email', true, $filter_args );
488 + return false;
507 489 }
508 490
509 - 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 );
510 504 }
511 505
512 506 /**
513 507 * Check if an email has any recipients
@@ -516,12 +510,9 @@
516 510 *
517 511 * @return bool
518 512 */
519 513 private function has_recipients() {
520 - if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
521 - return false;
522 - }
523 - return true;
514 + return $this->to || $this->cc || $this->bcc;
524 515 }
525 516
526 517 /**
527 518 * Send an email
@@ -568,11 +559,10 @@
568 559 )
569 560 );
570 561
571 562 $subject = $this->encode_subject( $this->subject );
563 + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
572 564
573 - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
574 -
575 565 if ( ! $sent ) {
576 566 if ( is_array( $header ) ) {
577 567 $header = implode( "\r\n", $header );
578 568 }
@@ -595,13 +585,13 @@
595 585 */
596 586 private function package_header() {
597 587 $header = array();
598 588
599 - if ( ! empty( $this->cc ) ) {
589 + if ( $this->cc ) {
600 590 $header[] = 'CC: ' . implode( ',', $this->cc );
601 591 }
602 592
603 - if ( ! empty( $this->bcc ) ) {
593 + if ( $this->bcc ) {
604 594 $header[] = 'BCC: ' . implode( ',', $this->bcc );
605 595 }
606 596
607 597 $header[] = 'From: ' . $this->from;
@@ -645,11 +635,11 @@
645 635 *
646 636 * @return string
647 637 */
648 638 private function prepare_email_setting( $value, $user_id_args ) {
649 - if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) {
639 + if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) {
650 640 $value = str_replace( '[' . $user_id_args['field_id'] . ']', '[' . $user_id_args['field_id'] . ' show="user_email"]', $value );
651 - } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) {
641 + } elseif ( str_contains( $value, '[' . $user_id_args['field_key'] . ']' ) ) {
652 642 $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value );
653 643 }
654 644
655 645 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
@@ -655,11 +645,10 @@
655 645 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
656 646
657 647 // Remove brackets and add a space in case there isn't one
658 648 $value = str_replace( '<', ' ', $value );
659 - $value = str_replace( array( '"', '>' ), '', $value );
660 649
661 - return $value;
650 + return str_replace( array( '"', '>' ), '', $value );
662 651 }
663 652
664 653 /**
665 654 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -668,20 +657,13 @@
668 657 * @since 2.03.04
669 658 *
670 659 * @param string $emails
671 660 *
672 - * @return array|string $emails
661 + * @return array|string Emails.
673 662 */
674 663 private function explode_emails( $emails ) {
675 - $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
676 -
677 - if ( is_array( $emails ) ) {
678 - $emails = array_map( 'trim', $emails );
679 - } else {
680 - $emails = trim( $emails );
681 - }
682 -
683 - return $emails;
664 + $emails = $emails ? preg_split( '/(,|;)/', $emails ) : '';
665 + return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails );
684 666 }
685 667
686 668 /**
687 669 * Format the recipients( to, cc, bcc)
@@ -690,9 +672,9 @@
690 672 *
691 673 * @return array
692 674 */
693 675 private function format_recipients( $recipients ) {
694 - if ( empty( $recipients ) ) {
676 + if ( ! $recipients ) {
695 677 return $recipients;
696 678 }
697 679
698 680 foreach ( $recipients as $key => $val ) {
@@ -705,17 +687,17 @@
705 687
706 688 $parts = explode( ' ', $val );
707 689 $email = end( $parts );
708 690
709 - if ( is_email( $email ) ) {
710 - // If user enters a name and email
711 - $name = trim( str_replace( $email, '', $val ) );
712 - } else {
691 + if ( ! is_email( $email ) ) {
713 692 // If user enters a name without an email
714 693 unset( $recipients[ $key ] );
715 694 continue;
716 695 }
717 696
697 + // If user enters a name and email
698 + $name = trim( str_replace( $email, '', $val ) );
699 +
718 700 $recipients[ $key ] = $this->format_from_email( $name, $email );
719 701 }//end foreach
720 702
721 703 return $recipients;
@@ -738,15 +720,14 @@
738 720 } else {
739 721 list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from );
740 722 }
741 723
742 - // if sending the email from a yahoo address, change it to the WordPress default
743 - if ( strpos( $from_email, '@yahoo.com' ) ) {
744 -
724 + // If sending the email from a yahoo address, change it to the WordPress default
725 + if ( str_contains( $from_email, '@yahoo.com' ) ) {
745 726 // Get the site domain and get rid of www.
746 727 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
747 728
748 - if ( substr( $sitename, 0, 4 ) === 'www.' ) {
729 + if ( str_starts_with( $sitename, 'www.' ) ) {
749 730 $sitename = substr( $sitename, 4 );
750 731 }
751 732
752 733 $from_email = 'wordpress@' . $sitename;
@@ -786,9 +767,9 @@
786 767 */
787 768 private function get_email_from_name( $name ) {
788 769 $email = trim( trim( $name, '>' ), '<' );
789 770
790 - if ( strpos( $email, '<' ) !== false ) {
771 + if ( str_contains( $email, '<' ) ) {
791 772 $parts = explode( '<', $email );
792 773 $email = trim( $parts[1], '>' );
793 774 }
794 775
@@ -827,13 +808,9 @@
827 808 *
828 809 * @return string
829 810 */
830 811 private function format_from_email( $name, $email ) {
831 - if ( '' !== $name ) {
832 - $email = $name . ' <' . $email . '>';
833 - }
834 -
835 - return $email;
812 + return '' !== $name ? $name . ' <' . $email . '>' : $email;
836 813 }
837 814
838 815 /**
839 816 * Remove phone numbers from To addresses
@@ -843,35 +820,37 @@
843 820 *
844 821 * @return void
845 822 */
846 823 private function handle_phone_numbers() {
824 + foreach ( $this->to as $key => $recipient ) {
825 + if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
826 + continue;
827 + }
847 828
848 - foreach ( $this->to as $key => $recipient ) {
849 - if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
850 - $recipient = explode( ' ', $recipient );
829 + $recipient = explode( ' ', $recipient );
851 830
852 - if ( is_email( end( $recipient ) ) ) {
853 - continue;
854 - }
831 + if ( is_email( end( $recipient ) ) ) {
832 + continue;
833 + }
855 834
856 - do_action(
857 - 'frm_send_to_not_email',
858 - array(
859 - 'e' => $recipient,
860 - 'subject' => $this->subject,
861 - 'mail_body' => $this->message,
862 - 'reply_to' => $this->reply_to,
863 - 'from' => $this->from,
864 - 'plain_text' => $this->is_plain_text,
865 - 'attachments' => $this->attachments,
866 - 'form' => $this->form,
867 - 'email_key' => $key,
868 - )
869 - );
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 + );
870 849
871 - // Remove phone number from to addresses
872 - unset( $this->to[ $key ] );
873 - }//end if
850 + // Remove phone number from to addresses
851 + unset( $this->to[ $key ] );
852 + // end if
874 853 }//end foreach
875 854 }
876 855
877 856 /**
@@ -944,9 +923,9 @@
944 923 * @return string
945 924 */
946 925 private function encode_subject( $subject ) {
947 926 if ( apply_filters( 'frm_encode_subject', false, $subject ) ) {
948 - $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
927 + return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
949 928 }
950 929
951 930 return $subject;
952 931 }