PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 +38 -186 6.255.0 View file →
@@ -7,99 +7,30 @@
7 7 * @since 2.03.04
8 8 */
9 9 class FrmEmail {
10 10
11 - /**
12 - * @var string
13 - */
14 11 private $email_key = '';
15 -
16 - /**
17 - * @var array
18 - */
19 12 private $to = array();
20 -
21 - /**
22 - * @var array
23 - */
24 13 private $cc = array();
25 -
26 - /**
27 - * @var array
28 - */
29 14 private $bcc = array();
30 -
31 - /**
32 - * @var string
33 - */
34 15 private $from = '';
35 -
36 - /**
37 - * @var string
38 - */
39 16 private $reply_to = '';
40 -
41 - /**
42 - * @var string
43 - */
44 17 private $subject = '';
45 -
46 - /**
47 - * @var string
48 - */
49 18 private $message = '';
50 -
51 - /**
52 - * @var array
53 - */
54 19 private $attachments = array();
55 20
56 - /**
57 - * @var bool
58 - */
59 21 private $is_plain_text = false;
60 -
61 - /**
62 - * @var bool
63 - */
64 22 private $is_single_recipient = false;
65 -
66 - /**
67 - * @var bool
68 - */
69 23 private $include_user_info = false;
70 24
71 - /**
72 - * @var string
73 - */
74 25 private $charset = '';
75 -
76 - /**
77 - * @var string
78 - */
79 26 private $content_type = 'text/html';
80 27
81 - /**
82 - * @var array
83 - */
84 28 private $settings = array();
85 -
86 - /**
87 - * @var stdClass
88 - */
89 29 private $entry;
90 -
91 - /**
92 - * @var stdClass
93 - */
94 30 private $form;
95 31
96 32 /**
97 - * @var int
98 - */
99 - private $action_id = 0;
100 -
101 - /**
102 33 * FrmEmail constructor
103 34 *
104 35 * @param object $action
105 36 * @param object $entry
@@ -106,12 +37,11 @@
106 37 * @param object $form
107 38 */
108 39 public function __construct( $action, $entry, $form ) {
109 40 $this->set_email_key( $action );
110 - $this->entry = $entry;
111 - $this->form = $form;
112 - $this->settings = $action->post_content;
113 - $this->action_id = (int) $action->ID;
41 + $this->entry = $entry;
42 + $this->form = $form;
43 + $this->settings = $action->post_content;
114 44
115 45 $user_id_args = self::get_user_id_args( $form->id );
116 46 $this->set_to( $user_id_args );
117 47 $this->set_cc( $user_id_args );
@@ -141,10 +71,8 @@
141 71 *
142 72 * @since 2.03.04
143 73 *
144 74 * @param object $action
145 - *
146 - * @return void
147 75 */
148 76 private function set_email_key( $action ) {
149 77 $this->email_key = $action->ID;
150 78 }
@@ -154,10 +82,8 @@
154 82 *
155 83 * @since 2.03.04
156 84 *
157 85 * @param array $user_id_args
158 - *
159 - * @return void
160 86 */
161 87 private function set_to( $user_id_args ) {
162 88 $to = $this->prepare_email_setting( $this->settings['email_to'], $user_id_args );
163 89 $to = $this->explode_emails( $to );
@@ -190,10 +116,8 @@
190 116 *
191 117 * @since 2.03.04
192 118 *
193 119 * @param array $user_id_args
194 - *
195 - * @return void
196 120 */
197 121 private function set_cc( $user_id_args ) {
198 122 $this->cc = $this->prepare_additional_recipients( $this->settings['cc'], $user_id_args );
199 123 }
@@ -203,10 +127,8 @@
203 127 *
204 128 * @since 2.03.04
205 129 *
206 130 * @param array $user_id_args
207 - *
208 - * @return void
209 131 */
210 132 private function set_bcc( $user_id_args ) {
211 133 $this->bcc = $this->prepare_additional_recipients( $this->settings['bcc'], $user_id_args );
212 134 }
@@ -216,9 +138,9 @@
216 138 *
217 139 * @since 2.03.04
218 140 *
219 141 * @param string $recipients
220 - * @param array $user_id_args
142 + * @param array $user_id_args
221 143 *
222 144 * @return array
223 145 */
224 146 private function prepare_additional_recipients( $recipients, $user_id_args ) {
@@ -236,13 +158,12 @@
236 158 *
237 159 * @since 2.03.04
238 160 *
239 161 * @param array $user_id_args
240 - * @return void
241 162 */
242 163 private function set_from( $user_id_args ) {
243 164 if ( empty( $this->settings['from'] ) ) {
244 - $from = FrmEmailHelper::get_default_from_email();
165 + $from = get_option( 'admin_email' );
245 166 } else {
246 167 $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
247 168 }
248 169
@@ -254,10 +175,8 @@
254 175 *
255 176 * @since 2.03.04
256 177 *
257 178 * @param array $user_id_args
258 - *
259 - * @return void
260 179 */
261 180 private function set_reply_to( $user_id_args ) {
262 181 $this->reply_to = trim( $this->settings['reply_to'] );
263 182
@@ -276,19 +195,13 @@
276 195 * Set the is_plain_text property
277 196 * This should be set before the message
278 197 *
279 198 * @since 2.03.04
280 - *
281 - * @return void
282 199 */
283 200 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;
201 + if ( $this->settings['plain_text'] ) {
202 + $this->is_plain_text = true;
288 203 }
289 -
290 - $this->is_plain_text = 'plain' === $this->settings['email_style'];
291 204 }
292 205
293 206 /**
294 207 * Set the include_user_info property
@@ -294,10 +207,8 @@
294 207 * Set the include_user_info property
295 208 * This should be set before the message
296 209 *
297 210 * @since 2.03.04
298 - *
299 - * @return void
300 211 */
301 212 private function set_include_user_info() {
302 213 if ( isset( $this->settings['inc_user_info'] ) ) {
303 214 $this->include_user_info = $this->settings['inc_user_info'];
@@ -308,11 +219,9 @@
308 219 * Set the is_single_recipient property
309 220 *
310 221 * @since 2.03.04
311 222 *
312 - * @param object $action
313 - *
314 - * @return void
223 + * @param $action
315 224 */
316 225 private function set_is_single_recipient( $action ) {
317 226 $args = array(
318 227 'form' => $this->form,
@@ -331,10 +240,8 @@
331 240 /**
332 241 * Set the charset
333 242 *
334 243 * @since 2.03.04
335 - *
336 - * @return void
337 244 */
338 245 private function set_charset() {
339 246 $this->charset = get_option( 'blog_charset' );
340 247 }
@@ -342,10 +249,8 @@
342 249 /**
343 250 * Set the content type
344 251 *
345 252 * @since 2.03.04
346 - *
347 - * @return void
348 253 */
349 254 private function set_content_type() {
350 255 if ( $this->is_plain_text ) {
351 256 $this->content_type = 'text/plain';
@@ -355,10 +260,8 @@
355 260 /**
356 261 * Set the subject
357 262 *
358 263 * @since 2.03.04
359 - *
360 - * @return void
361 264 */
362 265 private function set_subject() {
363 266 if ( empty( $this->settings['email_subject'] ) ) {
364 267 /* translators: %1$s: Form name, %2$s: Site name */
@@ -366,9 +269,8 @@
366 269 } else {
367 270 $this->subject = $this->settings['email_subject'];
368 271 }
369 272
370 - // This also replaces [sitename] shortcode in default.
371 273 $this->subject = FrmFieldsHelper::basic_replace_shortcodes( $this->subject, $this->form, $this->entry );
372 274
373 275 $args = array(
374 276 'form' => $this->form,
@@ -375,8 +277,9 @@
375 277 'entry' => $this->entry,
376 278 'email_key' => $this->email_key,
377 279 );
378 280 $this->subject = apply_filters( 'frm_email_subject', $this->subject, $args );
281 +
379 282 $this->subject = wp_specialchars_decode( strip_tags( stripslashes( $this->subject ) ), ENT_QUOTES );
380 283 }
381 284
382 285 /**
@@ -382,38 +285,27 @@
382 285 /**
383 286 * Set the email message
384 287 *
385 288 * @since 2.03.04
386 - *
387 - * @return void
388 289 */
389 290 private function set_message() {
390 - $this->message = $this->settings['email_message'];
291 + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->settings['email_message'], $this->form, $this->entry );
391 292
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 293 $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(
294 + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference
295 + $mail_body = FrmEntriesHelper::replace_default_message(
403 296 $prev_mail_body,
404 297 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'],
298 + 'id' => $this->entry->id,
299 + 'entry' => $pass_entry,
300 + 'plain_text' => $this->is_plain_text,
301 + 'user_info' => $this->include_user_info,
410 302 )
411 303 );
412 304
413 305 // Add the user info if it isn't already included
414 306 if ( $this->include_user_info && $prev_mail_body === $mail_body ) {
415 - $data = $this->entry->description;
307 + $data = $this->entry->description;
416 308 $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
417 309 $this->maybe_add_ip( $mail_body );
418 310 $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n";
419 311 $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
@@ -420,38 +312,17 @@
420 312 }
421 313
422 314 $this->message = $mail_body;
423 315
316 + $this->message = do_shortcode( $this->message );
317 +
424 318 if ( $this->is_plain_text ) {
425 319 $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 320 }
430 321
431 322 $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() );
432 323 }
433 324
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 325 private function maybe_add_ip( &$mail_body ) {
455 326 if ( ! empty( $this->entry->ip ) ) {
456 327 $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n";
457 328 }
@@ -460,11 +331,8 @@
460 331 /**
461 332 * Set the attachments for an email message
462 333 *
463 334 * @since 2.03.04
464 - * @since 5.0.16 added new action_id key to $args.
465 - *
466 - * @return void
467 335 */
468 336 private function set_attachments() {
469 337 $args = array(
470 338 'entry' => $this->entry,
@@ -469,9 +337,8 @@
469 337 $args = array(
470 338 'entry' => $this->entry,
471 339 'email_key' => $this->email_key,
472 340 'settings' => $this->settings,
473 - 'action_id' => $this->action_id,
474 341 );
475 342
476 343 $this->attachments = apply_filters( 'frm_notification_attachment', array(), $this->form, $args );
477 344 }
@@ -516,10 +383,11 @@
516 383 */
517 384 private function has_recipients() {
518 385 if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) {
519 386 return false;
387 + } else {
388 + return true;
520 389 }
521 - return true;
522 390 }
523 391
524 392 /**
525 393 * Send an email
@@ -611,9 +479,9 @@
611 479 * Get the userID field ID and key for email settings
612 480 *
613 481 * @since 2.03.04
614 482 *
615 - * @param int $form_id
483 + * @param $form_id
616 484 *
617 485 * @return array
618 486 */
619 487 private function get_user_id_args( $form_id ) {
@@ -635,9 +503,9 @@
635 503 *
636 504 * @since 2.03.04
637 505 *
638 506 * @param string $value
639 - * @param array $user_id_args
507 + * @param array $user_id_args
640 508 *
641 509 * @return string
642 510 */
643 511 private function prepare_email_setting( $value, $user_id_args ) {
@@ -694,24 +562,24 @@
694 562
695 563 if ( is_email( $val ) ) {
696 564 // If a plain email is used, no formatting is needed
697 565 continue;
698 - }
566 + } else {
567 + $parts = explode( ' ', $val );
568 + $email = end( $parts );
699 569
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;
570 + if ( is_email( $email ) ) {
571 + // If user enters a name and email
572 + $name = trim( str_replace( $email, '', $val ) );
573 + } else {
574 + // If user enters a name without an email
575 + unset( $recipients[ $key ] );
576 + continue;
577 + }
710 578 }
711 579
712 580 $recipients[ $key ] = $this->format_from_email( $name, $email );
713 - }//end foreach
581 + }
714 582
715 583 return $recipients;
716 584 }
717 585
@@ -761,9 +629,9 @@
761 629 $reply_to = trim( $reply_to );
762 630
763 631 if ( ! is_email( $reply_to ) ) {
764 632 list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to );
765 - $reply_to = $this->format_from_email( $name, $email );
633 + $reply_to = $this->format_from_email( $name, $email );
766 634 }
767 635
768 636 return $reply_to;
769 637 }
@@ -771,12 +639,8 @@
771 639 /**
772 640 * Get only the email if the name and email have been combined
773 641 *
774 642 * @since 3.0.06
775 - *
776 - * @param string $name
777 - *
778 - * @return string
779 643 */
780 644 private function get_email_from_name( $name ) {
781 645 $email = trim( trim( $name, '>' ), '<' );
782 646 if ( strpos( $email, '<' ) !== false ) {
@@ -812,11 +676,8 @@
812 676 }
813 677
814 678 /**
815 679 * @since 3.0.06
816 - *
817 - * @param string $name
818 - * @param string $email
819 680 */
820 681 private function format_from_email( $name, $email ) {
821 682 if ( '' !== $name ) {
822 683 $email = $name . ' <' . $email . '>';
@@ -829,10 +690,8 @@
829 690 * Remove phone numbers from To addresses
830 691 * Send the phone numbers to the frm_send_to_not_email hook
831 692 *
832 693 * @since 2.03.04
833 - *
834 - * @return void
835 694 */
836 695 private function handle_phone_numbers() {
837 696
838 697 foreach ( $this->to as $key => $recipient ) {
@@ -859,10 +718,10 @@
859 718 );
860 719
861 720 // Remove phone number from to addresses
862 721 unset( $this->to[ $key ] );
863 - }//end if
864 - }//end foreach
722 + }
723 + }
865 724 }
866 725
867 726 /**
868 727 * Package an array of FrmEmail properties
@@ -883,9 +742,8 @@
883 742 'attachments' => $this->attachments,
884 743 'plain_text' => $this->is_plain_text,
885 744 'form' => $this->form,
886 745 'entry' => $this->entry,
887 - 'email_style' => $this->settings['email_style'],
888 746 );
889 747 }
890 748
891 749 /**
@@ -891,10 +749,8 @@
891 749 /**
892 750 * Remove the Buddypress email filters
893 751 *
894 752 * @since 2.03.04
895 - *
896 - * @return void
897 753 */
898 754 private function remove_buddypress_filters() {
899 755 remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
900 756 remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
@@ -904,10 +760,8 @@
904 760 * Add Mandrill line break filter
905 761 * Remove line breaks in HTML emails to prevent conflicts with Mandrill
906 762 *
907 763 * @since 2.03.04
908 - *
909 - * @return void
910 764 */
911 765 private function add_mandrill_filter() {
912 766 if ( ! $this->is_plain_text ) {
913 767 add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
@@ -917,10 +771,8 @@
917 771 /**
918 772 * Remove Mandrill line break filter
919 773 *
920 774 * @since 2.03.04
921 - *
922 - * @return void
923 775 */
924 776 private function remove_mandrill_filter() {
925 777 remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' );
926 778 }