PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5
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 +52 -123 6.255.5 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 /**
@@ -141,10 +141,8 @@
141 141 *
142 142 * @since 2.03.04
143 143 *
144 144 * @param object $action
145 - *
146 - * @return void
147 145 */
148 146 private function set_email_key( $action ) {
149 147 $this->email_key = $action->ID;
150 148 }
@@ -154,10 +152,8 @@
154 152 *
155 153 * @since 2.03.04
156 154 *
157 155 * @param array $user_id_args
158 - *
159 - * @return void
160 156 */
161 157 private function set_to( $user_id_args ) {
162 158 $to = $this->prepare_email_setting( $this->settings['email_to'], $user_id_args );
163 159 $to = $this->explode_emails( $to );
@@ -190,10 +186,8 @@
190 186 *
191 187 * @since 2.03.04
192 188 *
193 189 * @param array $user_id_args
194 - *
195 - * @return void
196 190 */
197 191 private function set_cc( $user_id_args ) {
198 192 $this->cc = $this->prepare_additional_recipients( $this->settings['cc'], $user_id_args );
199 193 }
@@ -203,10 +197,8 @@
203 197 *
204 198 * @since 2.03.04
205 199 *
206 200 * @param array $user_id_args
207 - *
208 - * @return void
209 201 */
210 202 private function set_bcc( $user_id_args ) {
211 203 $this->bcc = $this->prepare_additional_recipients( $this->settings['bcc'], $user_id_args );
212 204 }
@@ -216,9 +208,9 @@
216 208 *
217 209 * @since 2.03.04
218 210 *
219 211 * @param string $recipients
220 - * @param array $user_id_args
212 + * @param array $user_id_args
221 213 *
222 214 * @return array
223 215 */
224 216 private function prepare_additional_recipients( $recipients, $user_id_args ) {
@@ -240,9 +232,9 @@
240 232 * @return void
241 233 */
242 234 private function set_from( $user_id_args ) {
243 235 if ( empty( $this->settings['from'] ) ) {
244 - $from = FrmEmailHelper::get_default_from_email();
236 + $from = get_option( 'admin_email' );
245 237 } else {
246 238 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
247 239 }
248 240
@@ -254,10 +246,8 @@
254 246 *
255 247 * @since 2.03.04
256 248 *
257 249 * @param array $user_id_args
258 - *
259 - * @return void
260 250 */
261 251 private function set_reply_to( $user_id_args ) {
262 252 $this->reply_to = trim( $this->settings['reply_to'] );
263 253
@@ -276,19 +266,13 @@
276 266 * Set the is_plain_text property
277 267 * This should be set before the message
278 268 *
279 269 * @since 2.03.04
280 - *
281 - * @return void
282 270 */
283 271 private function set_is_plain_text() {
284 - if ( empty( $this->settings['email_style'] ) ) {
285 - // If `email_style` isn't set, use the `plain_text` checkbox.
286 - $this->is_plain_text = ! empty( $this->settings['plain_text'] );
287 - return;
272 + if ( $this->settings['plain_text'] ) {
273 + $this->is_plain_text = true;
288 274 }
289 -
290 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
291 275 }
292 276
293 277 /**
294 278 * Set the include_user_info property
@@ -294,10 +278,8 @@
294 278 * Set the include_user_info property
295 279 * This should be set before the message
296 280 *
297 281 * @since 2.03.04
298 - *
299 - * @return void
300 282 */
301 283 private function set_include_user_info() {
302 284 if ( isset( $this->settings['inc_user_info'] ) ) {
303 285 $this->include_user_info = $this->settings['inc_user_info'];
@@ -308,11 +290,9 @@
308 290 * Set the is_single_recipient property
309 291 *
310 292 * @since 2.03.04
311 293 *
312 - * @param object $action
313 - *
314 - * @return void
294 + * @param $action
315 295 */
316 296 private function set_is_single_recipient( $action ) {
317 297 $args = array(
318 298 'form' => $this->form,
@@ -331,10 +311,8 @@
331 311 /**
332 312 * Set the charset
333 313 *
334 314 * @since 2.03.04
335 - *
336 - * @return void
337 315 */
338 316 private function set_charset() {
339 317 $this->charset = get_option( 'blog_charset' );
340 318 }
@@ -342,10 +320,8 @@
342 320 /**
343 321 * Set the content type
344 322 *
345 323 * @since 2.03.04
346 - *
347 - * @return void
348 324 */
349 325 private function set_content_type() {
350 326 if ( $this->is_plain_text ) {
351 327 $this->content_type = 'text/plain';
@@ -382,38 +358,27 @@
382 358 /**
383 359 * Set the email message
384 360 *
385 361 * @since 2.03.04
386 - *
387 - * @return void
388 362 */
389 363 private function set_message() {
390 - $this->message = $this->settings['email_message'];
364 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry );
391 365
392 - if ( ! $this->is_plain_text ) {
393 - // The decode is to support [default-html] shortcodes.
394 - $this->message = html_entity_decode( $this->message );
395 - }
396 -
397 - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry );
398 366 $prev_mail_body = $this->message;
399 -
400 - // Make a copy to prevent changes by reference.
401 - $pass_entry = clone $this->entry;
402 - $mail_body = FrmEntriesHelper::replace_default_message(
367 + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference
368 + $mail_body = FrmEntriesHelper::replace_default_message(
403 369 $prev_mail_body,
404 370 array(
405 - 'id' => $this->entry->id,
406 - 'entry' => $pass_entry,
407 - 'plain_text' => $this->is_plain_text,
408 - 'user_info' => $this->include_user_info,
409 - 'table_style' => $this->settings['email_style'],
371 + 'id' => $this->entry->id,
372 + 'entry' => $pass_entry,
373 + 'plain_text' => $this->is_plain_text,
374 + 'user_info' => $this->include_user_info,
410 375 )
411 376 );
412 377
413 378 // Add the user info if it isn't already included
414 379 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
415 - $data = $this->entry->description;
380 + $data = $this->entry->description;
416 381 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
417 382 $this->maybe_add_ip( $mail_body );
418 383 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
419 384 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -420,38 +385,17 @@
420 385 }
421 386
422 387 $this->message = $mail_body;
423 388
389 + $this->message = do_shortcode( $this->message );
390 +
424 391 if ( $this->is_plain_text ) {
425 392 $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES );
426 - $this->message = str_replace( ' ', '', $this->message );
427 - } else {
428 - $this->add_autop();
429 393 }
430 394
431 395 $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() );
432 396 }
433 397
434 - /**
435 - * Runs message through autop, extracting the content inside body tag if it has <body>.
436 - *
437 - * @return void
438 - */
439 - private function add_autop() {
440 - $message = $this->message;
441 - $result = preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match );
442 - if ( ! empty( $match[1] ) ) {
443 - $this->message = str_replace( $match[1], trim( wpautop( $match[1] ) ), $message );
444 - } else {
445 - $this->message = trim( wpautop( $message ) );
446 - }
447 - }
448 -
449 - /**
450 - * @param string $mail_body
451 - *
452 - * @return void
453 - */
454 398 private function maybe_add_ip( &$mail_body ) {
455 399 if ( ! empty( $this->entry->ip ) ) {
456 400 $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n";
457 401 }
@@ -516,10 +460,11 @@
516 460 */
517 461 private function has_recipients() {
518 462 if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
519 463 return false;
464 + } else {
465 + return true;
520 466 }
521 - return true;
522 467 }
523 468
524 469 /**
525 470 * Send an email
@@ -611,9 +556,9 @@
611 556 * Get the userID field ID and key for email settings
612 557 *
613 558 * @since 2.03.04
614 559 *
615 - * @param int $form_id
560 + * @param $form_id
616 561 *
617 562 * @return array
618 563 */
619 564 private function get_user_id_args( $form_id ) {
@@ -635,9 +580,9 @@
635 580 *
636 581 * @since 2.03.04
637 582 *
638 583 * @param string $value
639 - * @param array $user_id_args
584 + * @param array $user_id_args
640 585 *
641 586 * @return string
642 587 */
643 588 private function prepare_email_setting( $value, $user_id_args ) {
@@ -694,24 +639,24 @@
694 639
695 640 if ( is_email( $val ) ) {
696 641 // If a plain email is used, no formatting is needed
697 642 continue;
698 - }
643 + } else {
644 + $parts = explode( ' ', $val );
645 + $email = end( $parts );
699 646
700 - $parts = explode( ' ', $val );
701 - $email = end( $parts );
702 -
703 - if ( is_email( $email ) ) {
704 - // If user enters a name and email
705 - $name = trim( str_replace( $email, '', $val ) );
706 - } else {
707 - // If user enters a name without an email
708 - unset( $recipients[ $key ] );
709 - continue;
647 + if ( is_email( $email ) ) {
648 + // If user enters a name and email
649 + $name = trim( str_replace( $email, '', $val ) );
650 + } else {
651 + // If user enters a name without an email
652 + unset( $recipients[ $key ] );
653 + continue;
654 + }
710 655 }
711 656
712 657 $recipients[ $key ] = $this->format_from_email( $name, $email );
713 - }//end foreach
658 + }
714 659
715 660 return $recipients;
716 661 }
717 662
@@ -761,9 +706,9 @@
761 706 $reply_to = trim( $reply_to );
762 707
763 708 if ( ! is_email( $reply_to ) ) {
764 709 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
765 - $reply_to = $this->format_from_email( $name, $email );
710 + $reply_to = $this->format_from_email( $name, $email );
766 711 }
767 712
768 713 return $reply_to;
769 714 }
@@ -771,12 +716,8 @@
771 716 /**
772 717 * Get only the email if the name and email have been combined
773 718 *
774 719 * @since 3.0.06
775 - *
776 - * @param string $name
777 - *
778 - * @return string
779 720 */
780 721 private function get_email_from_name( $name ) {
781 722 $email = trim( trim( $name, '>' ), '<' );
782 723 if ( strpos( $email, '<' ) !== false ) {
@@ -812,11 +753,8 @@
812 753 }
813 754
814 755 /**
815 756 * @since 3.0.06
816 - *
817 - * @param string $name
818 - * @param string $email
819 757 */
820 758 private function format_from_email( $name, $email ) {
821 759 if ( '' !== $name ) {
822 760 $email = $name . ' <' . $email . '>';
@@ -829,10 +767,8 @@
829 767 * Remove phone numbers from To addresses
830 768 * Send the phone numbers to the frm_send_to_not_email hook
831 769 *
832 770 * @since 2.03.04
833 - *
834 - * @return void
835 771 */
836 772 private function handle_phone_numbers() {
837 773
838 774 foreach ( $this->to as $key => $recipient ) {
@@ -859,10 +795,10 @@
859 795 );
860 796
861 797 // Remove phone number from to addresses
862 798 unset( $this->to[ $key ] );
863 - }//end if
864 - }//end foreach
799 + }
800 + }
865 801 }
866 802
867 803 /**
868 804 * Package an array of FrmEmail properties
@@ -883,9 +819,8 @@
883 819 'attachments' => $this->attachments,
884 820 'plain_text' => $this->is_plain_text,
885 821 'form' => $this->form,
886 822 'entry' => $this->entry,
887 - 'email_style' => $this->settings['email_style'],
888 823 );
889 824 }
890 825
891 826 /**
@@ -891,10 +826,8 @@
891 826 /**
892 827 * Remove the Buddypress email filters
893 828 *
894 829 * @since 2.03.04
895 - *
896 - * @return void
897 830 */
898 831 private function remove_buddypress_filters() {
899 832 remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
900 833 remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
@@ -904,10 +837,8 @@
904 837 * Add Mandrill line break filter
905 838 * Remove line breaks in HTML emails to prevent conflicts with Mandrill
906 839 *
907 840 * @since 2.03.04
908 - *
909 - * @return void
910 841 */
911 842 private function add_mandrill_filter() {
912 843 if ( ! $this->is_plain_text ) {
913 844 add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
@@ -917,10 +848,8 @@
917 848 /**
918 849 * Remove Mandrill line break filter
919 850 *
920 851 * @since 2.03.04
921 - *
922 - * @return void
923 852 */
924 853 private function remove_mandrill_filter() {
925 854 remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
926 855 }