PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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 +89 -85 6.316.23 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 ( ! $this->to ) {
179 + if ( empty( $this->to ) ) {
180 180 return;
181 181 }
182 182
183 183 $this->handle_phone_numbers();
@@ -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,9 +236,8 @@
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'] ) ) {
@@ -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
@@ -400,13 +397,12 @@
400 397 $pass_entry = clone $this->entry;
401 398 $mail_body = FrmEntriesHelper::replace_default_message(
402 399 $prev_mail_body,
403 400 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'],
401 + 'id' => $this->entry->id,
402 + 'entry' => $pass_entry,
403 + 'plain_text' => $this->is_plain_text,
404 + 'user_info' => $this->include_user_info,
409 405 )
410 406 );
411 407
412 408 // Add the user info if it isn't already included
@@ -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,12 @@
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 + }
516 + return true;
515 517 }
516 518
517 519 /**
518 520 * Send an email
@@ -525,9 +527,8 @@
525 527 $this->remove_buddypress_filters();
526 528 $this->add_mandrill_filter();
527 529
528 530 $sent = false;
529 -
530 531 if ( count( $this->to ) > 1 && $this->is_single_recipient ) {
531 532 foreach ( $this->to as $recipient ) {
532 533 $sent = $this->send_single( $recipient );
533 534 }
@@ -559,15 +560,15 @@
559 560 )
560 561 );
561 562
562 563 $subject = $this->encode_subject( $this->subject );
563 - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
564 564
565 + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments );
566 +
565 567 if ( ! $sent ) {
566 568 if ( is_array( $header ) ) {
567 569 $header = implode( "\r\n", $header );
568 570 }
569 -
570 571 $recipient = implode( ',', (array) $recipient );
571 572 $sent = mail( $recipient, $subject, $this->message, $header );
572 573 }
573 574
@@ -585,13 +586,13 @@
585 586 */
586 587 private function package_header() {
587 588 $header = array();
588 589
589 - if ( $this->cc ) {
590 + if ( ! empty( $this->cc ) ) {
590 591 $header[] = 'CC: ' . implode( ',', $this->cc );
591 592 }
592 593
593 - if ( $this->bcc ) {
594 + if ( ! empty( $this->bcc ) ) {
594 595 $header[] = 'BCC: ' . implode( ',', $this->bcc );
595 596 }
596 597
597 598 $header[] = 'From: ' . $this->from;
@@ -616,9 +617,8 @@
616 617 'field_key' => '',
617 618 );
618 619
619 620 $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id );
620 -
621 621 if ( $user_id_args['field_id'] ) {
622 622 $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] );
623 623 }
624 624
@@ -635,11 +635,11 @@
635 635 *
636 636 * @return string
637 637 */
638 638 private function prepare_email_setting( $value, $user_id_args ) {
639 - if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) {
639 + if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) {
640 640 $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'] . ']' ) ) {
641 + } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) {
642 642 $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value );
643 643 }
644 644
645 645 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
@@ -645,10 +645,11 @@
645 645 $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry );
646 646
647 647 // Remove brackets and add a space in case there isn't one
648 648 $value = str_replace( '<', ' ', $value );
649 + $value = str_replace( array( '"', '>' ), '', $value );
649 650
650 - return str_replace( array( '"', '>' ), '', $value );
651 + return $value;
651 652 }
652 653
653 654 /**
654 655 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -657,13 +658,19 @@
657 658 * @since 2.03.04
658 659 *
659 660 * @param string $emails
660 661 *
661 - * @return array|string Emails.
662 + * @return array|string $emails
662 663 */
663 664 private function explode_emails( $emails ) {
664 - $emails = $emails ? preg_split( '/(,|;)/', $emails ) : '';
665 - return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails );
665 + $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' );
666 + if ( is_array( $emails ) ) {
667 + $emails = array_map( 'trim', $emails );
668 + } else {
669 + $emails = trim( $emails );
670 + }
671 +
672 + return $emails;
666 673 }
667 674
668 675 /**
669 676 * Format the recipients( to, cc, bcc)
@@ -672,9 +679,9 @@
672 679 *
673 680 * @return array
674 681 */
675 682 private function format_recipients( $recipients ) {
676 - if ( ! $recipients ) {
683 + if ( empty( $recipients ) ) {
677 684 return $recipients;
678 685 }
679 686
680 687 foreach ( $recipients as $key => $val ) {
@@ -687,17 +694,17 @@
687 694
688 695 $parts = explode( ' ', $val );
689 696 $email = end( $parts );
690 697
691 - if ( ! is_email( $email ) ) {
698 + if ( is_email( $email ) ) {
699 + // If user enters a name and email
700 + $name = trim( str_replace( $email, '', $val ) );
701 + } else {
692 702 // If user enters a name without an email
693 703 unset( $recipients[ $key ] );
694 704 continue;
695 705 }
696 706
697 - // If user enters a name and email
698 - $name = trim( str_replace( $email, '', $val ) );
699 -
700 707 $recipients[ $key ] = $this->format_from_email( $name, $email );
701 708 }//end foreach
702 709
703 710 return $recipients;
@@ -720,14 +727,14 @@
720 727 } else {
721 728 list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from );
722 729 }
723 730
724 - // If sending the email from a yahoo address, change it to the WordPress default
725 - if ( str_contains( $from_email, '@yahoo.com' ) ) {
731 + // if sending the email from a yahoo address, change it to the WordPress default
732 + if ( strpos( $from_email, '@yahoo.com' ) ) {
733 +
726 734 // Get the site domain and get rid of www.
727 735 $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) );
728 -
729 - if ( str_starts_with( $sitename, 'www.' ) ) {
736 + if ( substr( $sitename, 0, 4 ) === 'www.' ) {
730 737 $sitename = substr( $sitename, 4 );
731 738 }
732 739
733 740 $from_email = 'wordpress@' . $sitename;
@@ -766,10 +773,9 @@
766 773 * @return string
767 774 */
768 775 private function get_email_from_name( $name ) {
769 776 $email = trim( trim( $name, '>' ), '<' );
770 -
771 - if ( str_contains( $email, '<' ) ) {
777 + if ( strpos( $email, '<' ) !== false ) {
772 778 $parts = explode( '<', $email );
773 779 $email = trim( $parts[1], '>' );
774 780 }
775 781
@@ -804,13 +810,15 @@
804 810 * @since 3.0.06
805 811 *
806 812 * @param string $name
807 813 * @param string $email
808 - *
809 - * @return string
810 814 */
811 815 private function format_from_email( $name, $email ) {
812 - return '' !== $name ? $name . ' <' . $email . '>' : $email;
816 + if ( '' !== $name ) {
817 + $email = $name . ' <' . $email . '>';
818 + }
819 +
820 + return $email;
813 821 }
814 822
815 823 /**
816 824 * Remove phone numbers from To addresses
@@ -820,37 +828,35 @@
820 828 *
821 829 * @return void
822 830 */
823 831 private function handle_phone_numbers() {
832 +
824 833 foreach ( $this->to as $key => $recipient ) {
825 - if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
826 - continue;
827 - }
834 + if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
835 + $recipient = explode( ' ', $recipient );
828 836
829 - $recipient = explode( ' ', $recipient );
837 + if ( is_email( end( $recipient ) ) ) {
838 + continue;
839 + }
830 840
831 - if ( is_email( end( $recipient ) ) ) {
832 - continue;
833 - }
841 + do_action(
842 + 'frm_send_to_not_email',
843 + array(
844 + 'e' => $recipient,
845 + 'subject' => $this->subject,
846 + 'mail_body' => $this->message,
847 + 'reply_to' => $this->reply_to,
848 + 'from' => $this->from,
849 + 'plain_text' => $this->is_plain_text,
850 + 'attachments' => $this->attachments,
851 + 'form' => $this->form,
852 + 'email_key' => $key,
853 + )
854 + );
834 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 - );
849 -
850 - // Remove phone number from to addresses
851 - unset( $this->to[ $key ] );
852 - // end if
856 + // Remove phone number from to addresses
857 + unset( $this->to[ $key ] );
858 + }//end if
853 859 }//end foreach
854 860 }
855 861
856 862 /**
@@ -870,12 +876,10 @@
870 876 'subject' => $this->subject,
871 877 'message' => $this->message,
872 878 'attachments' => $this->attachments,
873 879 'plain_text' => $this->is_plain_text,
874 - 'email_key' => $this->email_key,
875 880 'form' => $this->form,
876 881 'entry' => $this->entry,
877 - 'email_style' => $this->settings['email_style'],
878 882 );
879 883 }
880 884
881 885 /**
@@ -923,9 +927,9 @@
923 927 * @return string
924 928 */
925 929 private function encode_subject( $subject ) {
926 930 if ( apply_filters( 'frm_encode_subject', false, $subject ) ) {
927 - return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
931 + $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?=';
928 932 }
929 933
930 934 return $subject;
931 935 }