| @@ -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 ); |
| @@ -175,9 +171,9 @@ | ||
| 175 | 171 | $to = apply_filters( 'frm_to_email', $to, $values, $this->form->id, $args ); |
| 176 | 172 | |
| 177 | 173 | $this->to = array_unique( (array) $to ); |
| 178 | 174 | |
| 179 | - if ( ! $this->to ) { | |
| 175 | + if ( empty( $this->to ) ) { | |
| 180 | 176 | return; |
| 181 | 177 | } |
| 182 | 178 | |
| 183 | 179 | $this->handle_phone_numbers(); |
| @@ -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 ) { |
| @@ -223,11 +215,13 @@ | ||
| 223 | 215 | */ |
| 224 | 216 | private function prepare_additional_recipients( $recipients, $user_id_args ) { |
| 225 | 217 | $recipients = $this->prepare_email_setting( $recipients, $user_id_args ); |
| 226 | 218 | $recipients = $this->explode_emails( $recipients ); |
| 219 | + | |
| 227 | 220 | $recipients = array_unique( (array) $recipients ); |
| 221 | + $recipients = $this->format_recipients( $recipients ); | |
| 228 | 222 | |
| 229 | - return $this->format_recipients( $recipients ); | |
| 223 | + return $recipients; | |
| 230 | 224 | } |
| 231 | 225 | |
| 232 | 226 | /** |
| 233 | 227 | * Set the From addresses |
| @@ -234,14 +228,13 @@ | ||
| 234 | 228 | * |
| 235 | 229 | * @since 2.03.04 |
| 236 | 230 | * |
| 237 | 231 | * @param array $user_id_args |
| 238 | - * | |
| 239 | 232 | * @return void |
| 240 | 233 | */ |
| 241 | 234 | private function set_from( $user_id_args ) { |
| 242 | 235 | if ( empty( $this->settings['from'] ) ) { |
| 243 | - $from = FrmEmailHelper::get_default_from_email(); | |
| 236 | + $from = get_option( 'admin_email' ); | |
| 244 | 237 | } else { |
| 245 | 238 | $from = $this->prepare_email_setting( $this->settings['from'], $user_id_args ); |
| 246 | 239 | } |
| 247 | 240 | |
| @@ -253,10 +246,8 @@ | ||
| 253 | 246 | * |
| 254 | 247 | * @since 2.03.04 |
| 255 | 248 | * |
| 256 | 249 | * @param array $user_id_args |
| 257 | - * | |
| 258 | - * @return void | |
| 259 | 250 | */ |
| 260 | 251 | private function set_reply_to( $user_id_args ) { |
| 261 | 252 | $this->reply_to = trim( $this->settings['reply_to'] ); |
| 262 | 253 | |
| @@ -275,19 +266,13 @@ | ||
| 275 | 266 | * Set the is_plain_text property |
| 276 | 267 | * This should be set before the message |
| 277 | 268 | * |
| 278 | 269 | * @since 2.03.04 |
| 279 | - * | |
| 280 | - * @return void | |
| 281 | 270 | */ |
| 282 | 271 | 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; | |
| 272 | + if ( $this->settings['plain_text'] ) { | |
| 273 | + $this->is_plain_text = true; | |
| 287 | 274 | } |
| 288 | - | |
| 289 | - $this->is_plain_text = 'plain' === $this->settings['email_style']; | |
| 290 | 275 | } |
| 291 | 276 | |
| 292 | 277 | /** |
| 293 | 278 | * Set the include_user_info property |
| @@ -293,10 +278,8 @@ | ||
| 293 | 278 | * Set the include_user_info property |
| 294 | 279 | * This should be set before the message |
| 295 | 280 | * |
| 296 | 281 | * @since 2.03.04 |
| 297 | - * | |
| 298 | - * @return void | |
| 299 | 282 | */ |
| 300 | 283 | private function set_include_user_info() { |
| 301 | 284 | if ( isset( $this->settings['inc_user_info'] ) ) { |
| 302 | 285 | $this->include_user_info = $this->settings['inc_user_info']; |
| @@ -307,11 +290,9 @@ | ||
| 307 | 290 | * Set the is_single_recipient property |
| 308 | 291 | * |
| 309 | 292 | * @since 2.03.04 |
| 310 | 293 | * |
| 311 | - * @param object $action | |
| 312 | - * | |
| 313 | - * @return void | |
| 294 | + * @param $action | |
| 314 | 295 | */ |
| 315 | 296 | private function set_is_single_recipient( $action ) { |
| 316 | 297 | $args = array( |
| 317 | 298 | 'form' => $this->form, |
| @@ -330,10 +311,8 @@ | ||
| 330 | 311 | /** |
| 331 | 312 | * Set the charset |
| 332 | 313 | * |
| 333 | 314 | * @since 2.03.04 |
| 334 | - * | |
| 335 | - * @return void | |
| 336 | 315 | */ |
| 337 | 316 | private function set_charset() { |
| 338 | 317 | $this->charset = get_option( 'blog_charset' ); |
| 339 | 318 | } |
| @@ -341,10 +320,8 @@ | ||
| 341 | 320 | /** |
| 342 | 321 | * Set the content type |
| 343 | 322 | * |
| 344 | 323 | * @since 2.03.04 |
| 345 | - * | |
| 346 | - * @return void | |
| 347 | 324 | */ |
| 348 | 325 | private function set_content_type() { |
| 349 | 326 | if ( $this->is_plain_text ) { |
| 350 | 327 | $this->content_type = 'text/plain'; |
| @@ -381,38 +358,33 @@ | ||
| 381 | 358 | /** |
| 382 | 359 | * Set the email message |
| 383 | 360 | * |
| 384 | 361 | * @since 2.03.04 |
| 385 | - * | |
| 386 | - * @return void | |
| 387 | 362 | */ |
| 388 | 363 | private function set_message() { |
| 389 | 364 | $this->message = $this->settings['email_message']; |
| 390 | 365 | |
| 391 | 366 | if ( ! $this->is_plain_text ) { |
| 392 | - // The decode is to support [default-html] shortcodes. | |
| 393 | - $this->message = html_entity_decode( $this->message ); | |
| 367 | + $this->message = html_entity_decode( $this->message ); // The decode is to support [default-html] shortcodes. | |
| 394 | 368 | } |
| 395 | 369 | |
| 396 | - $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry ); | |
| 370 | + $this->message = FrmFieldsHelper::basic_replace_shortcodes( $this->message, $this->form, $this->entry ); | |
| 371 | + | |
| 397 | 372 | $prev_mail_body = $this->message; |
| 398 | - | |
| 399 | - // Make a copy to prevent changes by reference. | |
| 400 | - $pass_entry = clone $this->entry; | |
| 401 | - $mail_body = FrmEntriesHelper::replace_default_message( | |
| 373 | + $pass_entry = clone $this->entry; // make a copy to prevent changes by reference | |
| 374 | + $mail_body = FrmEntriesHelper::replace_default_message( | |
| 402 | 375 | $prev_mail_body, |
| 403 | 376 | 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'], | |
| 377 | + 'id' => $this->entry->id, | |
| 378 | + 'entry' => $pass_entry, | |
| 379 | + 'plain_text' => $this->is_plain_text, | |
| 380 | + 'user_info' => $this->include_user_info, | |
| 409 | 381 | ) |
| 410 | 382 | ); |
| 411 | 383 | |
| 412 | 384 | // Add the user info if it isn't already included |
| 413 | 385 | if ( $this->include_user_info && $prev_mail_body === $mail_body ) { |
| 414 | - $data = $this->entry->description; | |
| 386 | + $data = $this->entry->description; | |
| 415 | 387 | $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
| 416 | 388 | $this->maybe_add_ip( $mail_body ); |
| 417 | 389 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntriesHelper::get_browser( $data['browser'] ) . "\r\n"; |
| 418 | 390 | $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
| @@ -419,39 +391,19 @@ | ||
| 419 | 391 | } |
| 420 | 392 | |
| 421 | 393 | $this->message = $mail_body; |
| 422 | 394 | |
| 395 | + $this->message = do_shortcode( $this->message ); | |
| 396 | + | |
| 423 | 397 | if ( $this->is_plain_text ) { |
| 424 | 398 | $this->message = wp_specialchars_decode( strip_tags( $this->message ), ENT_QUOTES ); |
| 425 | - $this->message = str_replace( ' ', '', $this->message ); | |
| 426 | 399 | } else { |
| 427 | - $this->add_autop(); | |
| 400 | + $this->message = wpautop( $this->message, false ); // HTML emails should use autop. | |
| 428 | 401 | } |
| 429 | 402 | |
| 430 | 403 | $this->message = apply_filters( 'frm_email_message', $this->message, $this->package_atts() ); |
| 431 | 404 | } |
| 432 | 405 | |
| 433 | - /** | |
| 434 | - * Runs message through autop, extracting the content inside body tag if it has <body>. | |
| 435 | - * | |
| 436 | - * @return void | |
| 437 | - */ | |
| 438 | - private function add_autop() { | |
| 439 | - $message = $this->message; | |
| 440 | - preg_match( '/<body[^>]*>([\s\S]*?)<\/body>/', $message, $match ); | |
| 441 | - | |
| 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 | 406 | private function maybe_add_ip( &$mail_body ) { |
| 455 | 407 | if ( ! empty( $this->entry->ip ) ) { |
| 456 | 408 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $this->entry->ip . "\r\n"; |
| 457 | 409 | } |
| @@ -484,24 +436,28 @@ | ||
| 484 | 436 | * @return bool|mixed|void |
| 485 | 437 | */ |
| 486 | 438 | public function should_send() { |
| 487 | 439 | if ( ! $this->has_recipients() ) { |
| 488 | - return false; | |
| 440 | + $send = false; | |
| 441 | + } else { | |
| 442 | + | |
| 443 | + $filter_args = array( | |
| 444 | + 'message' => $this->message, | |
| 445 | + 'subject' => $this->subject, | |
| 446 | + 'recipient' => $this->to, | |
| 447 | + 'header' => $this->package_header(), | |
| 448 | + ); | |
| 449 | + | |
| 450 | + /** | |
| 451 | + * Stop an email based on the message, subject, recipient, | |
| 452 | + * or any information included in the email header | |
| 453 | + * | |
| 454 | + * @since 2.2.8 | |
| 455 | + */ | |
| 456 | + $send = apply_filters( 'frm_send_email', true, $filter_args ); | |
| 489 | 457 | } |
| 490 | 458 | |
| 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 ); | |
| 459 | + return $send; | |
| 504 | 460 | } |
| 505 | 461 | |
| 506 | 462 | /** |
| 507 | 463 | * Check if an email has any recipients |
| @@ -510,9 +466,13 @@ | ||
| 510 | 466 | * |
| 511 | 467 | * @return bool |
| 512 | 468 | */ |
| 513 | 469 | private function has_recipients() { |
| 514 | - return $this->to || $this->cc || $this->bcc; | |
| 470 | + if ( empty( $this->to ) && empty( $this->cc ) && empty( $this->bcc ) ) { | |
| 471 | + return false; | |
| 472 | + } else { | |
| 473 | + return true; | |
| 474 | + } | |
| 515 | 475 | } |
| 516 | 476 | |
| 517 | 477 | /** |
| 518 | 478 | * Send an email |
| @@ -525,9 +485,8 @@ | ||
| 525 | 485 | $this->remove_buddypress_filters(); |
| 526 | 486 | $this->add_mandrill_filter(); |
| 527 | 487 | |
| 528 | 488 | $sent = false; |
| 529 | - | |
| 530 | 489 | if ( count( $this->to ) > 1 && $this->is_single_recipient ) { |
| 531 | 490 | foreach ( $this->to as $recipient ) { |
| 532 | 491 | $sent = $this->send_single( $recipient ); |
| 533 | 492 | } |
| @@ -559,15 +518,15 @@ | ||
| 559 | 518 | ) |
| 560 | 519 | ); |
| 561 | 520 | |
| 562 | 521 | $subject = $this->encode_subject( $this->subject ); |
| 563 | - $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments ); | |
| 564 | 522 | |
| 523 | + $sent = wp_mail( $recipient, $subject, $this->message, $header, $this->attachments ); | |
| 524 | + | |
| 565 | 525 | if ( ! $sent ) { |
| 566 | 526 | if ( is_array( $header ) ) { |
| 567 | 527 | $header = implode( "\r\n", $header ); |
| 568 | 528 | } |
| 569 | - | |
| 570 | 529 | $recipient = implode( ',', (array) $recipient ); |
| 571 | 530 | $sent = mail( $recipient, $subject, $this->message, $header ); |
| 572 | 531 | } |
| 573 | 532 | |
| @@ -585,13 +544,13 @@ | ||
| 585 | 544 | */ |
| 586 | 545 | private function package_header() { |
| 587 | 546 | $header = array(); |
| 588 | 547 | |
| 589 | - if ( $this->cc ) { | |
| 548 | + if ( ! empty( $this->cc ) ) { | |
| 590 | 549 | $header[] = 'CC: ' . implode( ',', $this->cc ); |
| 591 | 550 | } |
| 592 | 551 | |
| 593 | - if ( $this->bcc ) { | |
| 552 | + if ( ! empty( $this->bcc ) ) { | |
| 594 | 553 | $header[] = 'BCC: ' . implode( ',', $this->bcc ); |
| 595 | 554 | } |
| 596 | 555 | |
| 597 | 556 | $header[] = 'From: ' . $this->from; |
| @@ -605,9 +564,9 @@ | ||
| 605 | 564 | * Get the userID field ID and key for email settings |
| 606 | 565 | * |
| 607 | 566 | * @since 2.03.04 |
| 608 | 567 | * |
| 609 | - * @param int $form_id | |
| 568 | + * @param $form_id | |
| 610 | 569 | * |
| 611 | 570 | * @return array |
| 612 | 571 | */ |
| 613 | 572 | private function get_user_id_args( $form_id ) { |
| @@ -616,9 +575,8 @@ | ||
| 616 | 575 | 'field_key' => '', |
| 617 | 576 | ); |
| 618 | 577 | |
| 619 | 578 | $user_id_args['field_id'] = FrmEmailHelper::get_user_id_field_for_form( $form_id ); |
| 620 | - | |
| 621 | 579 | if ( $user_id_args['field_id'] ) { |
| 622 | 580 | $user_id_args['field_key'] = FrmField::get_key_by_id( $user_id_args['field_id'] ); |
| 623 | 581 | } |
| 624 | 582 | |
| @@ -630,16 +588,16 @@ | ||
| 630 | 588 | * |
| 631 | 589 | * @since 2.03.04 |
| 632 | 590 | * |
| 633 | 591 | * @param string $value |
| 634 | - * @param array $user_id_args | |
| 592 | + * @param array $user_id_args | |
| 635 | 593 | * |
| 636 | 594 | * @return string |
| 637 | 595 | */ |
| 638 | 596 | private function prepare_email_setting( $value, $user_id_args ) { |
| 639 | - if ( str_contains( $value, '[' . $user_id_args['field_id'] . ']' ) ) { | |
| 597 | + if ( strpos( $value, '[' . $user_id_args['field_id'] . ']' ) !== false ) { | |
| 640 | 598 | $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'] . ']' ) ) { | |
| 599 | + } elseif ( strpos( $value, '[' . $user_id_args['field_key'] . ']' ) !== false ) { | |
| 642 | 600 | $value = str_replace( '[' . $user_id_args['field_key'] . ']', '[' . $user_id_args['field_key'] . ' show="user_email"]', $value ); |
| 643 | 601 | } |
| 644 | 602 | |
| 645 | 603 | $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry ); |
| @@ -645,10 +603,11 @@ | ||
| 645 | 603 | $value = FrmFieldsHelper::basic_replace_shortcodes( $value, $this->form, $this->entry ); |
| 646 | 604 | |
| 647 | 605 | // Remove brackets and add a space in case there isn't one |
| 648 | 606 | $value = str_replace( '<', ' ', $value ); |
| 607 | + $value = str_replace( array( '"', '>' ), '', $value ); | |
| 649 | 608 | |
| 650 | - return str_replace( array( '"', '>' ), '', $value ); | |
| 609 | + return $value; | |
| 651 | 610 | } |
| 652 | 611 | |
| 653 | 612 | /** |
| 654 | 613 | * Extract the emails from cc and bcc. Allow separation by , or ;. |
| @@ -657,13 +616,19 @@ | ||
| 657 | 616 | * @since 2.03.04 |
| 658 | 617 | * |
| 659 | 618 | * @param string $emails |
| 660 | 619 | * |
| 661 | - * @return array|string Emails. | |
| 620 | + * @return array|string $emails | |
| 662 | 621 | */ |
| 663 | 622 | private function explode_emails( $emails ) { |
| 664 | - $emails = $emails ? preg_split( '/(,|;)/', $emails ) : ''; | |
| 665 | - return is_array( $emails ) ? array_map( 'trim', $emails ) : trim( $emails ); | |
| 623 | + $emails = ( ! empty( $emails ) ? preg_split( '/(,|;)/', $emails ) : '' ); | |
| 624 | + if ( is_array( $emails ) ) { | |
| 625 | + $emails = array_map( 'trim', $emails ); | |
| 626 | + } else { | |
| 627 | + $emails = trim( $emails ); | |
| 628 | + } | |
| 629 | + | |
| 630 | + return $emails; | |
| 666 | 631 | } |
| 667 | 632 | |
| 668 | 633 | /** |
| 669 | 634 | * Format the recipients( to, cc, bcc) |
| @@ -672,9 +637,9 @@ | ||
| 672 | 637 | * |
| 673 | 638 | * @return array |
| 674 | 639 | */ |
| 675 | 640 | private function format_recipients( $recipients ) { |
| 676 | - if ( ! $recipients ) { | |
| 641 | + if ( empty( $recipients ) ) { | |
| 677 | 642 | return $recipients; |
| 678 | 643 | } |
| 679 | 644 | |
| 680 | 645 | foreach ( $recipients as $key => $val ) { |
| @@ -682,24 +647,24 @@ | ||
| 682 | 647 | |
| 683 | 648 | if ( is_email( $val ) ) { |
| 684 | 649 | // If a plain email is used, no formatting is needed |
| 685 | 650 | continue; |
| 686 | - } | |
| 651 | + } else { | |
| 652 | + $parts = explode( ' ', $val ); | |
| 653 | + $email = end( $parts ); | |
| 687 | 654 | |
| 688 | - $parts = explode( ' ', $val ); | |
| 689 | - $email = end( $parts ); | |
| 690 | - | |
| 691 | - if ( ! is_email( $email ) ) { | |
| 692 | - // If user enters a name without an email | |
| 693 | - unset( $recipients[ $key ] ); | |
| 694 | - continue; | |
| 655 | + if ( is_email( $email ) ) { | |
| 656 | + // If user enters a name and email | |
| 657 | + $name = trim( str_replace( $email, '', $val ) ); | |
| 658 | + } else { | |
| 659 | + // If user enters a name without an email | |
| 660 | + unset( $recipients[ $key ] ); | |
| 661 | + continue; | |
| 662 | + } | |
| 695 | 663 | } |
| 696 | 664 | |
| 697 | - // If user enters a name and email | |
| 698 | - $name = trim( str_replace( $email, '', $val ) ); | |
| 699 | - | |
| 700 | 665 | $recipients[ $key ] = $this->format_from_email( $name, $email ); |
| 701 | - }//end foreach | |
| 666 | + } | |
| 702 | 667 | |
| 703 | 668 | return $recipients; |
| 704 | 669 | } |
| 705 | 670 | |
| @@ -720,14 +685,14 @@ | ||
| 720 | 685 | } else { |
| 721 | 686 | list( $from_name, $from_email ) = $this->get_name_and_email_for_sender( $from ); |
| 722 | 687 | } |
| 723 | 688 | |
| 724 | - // If sending the email from a yahoo address, change it to the WordPress default | |
| 725 | - if ( str_contains( $from_email, '@yahoo.com' ) ) { | |
| 689 | + // if sending the email from a yahoo address, change it to the WordPress default | |
| 690 | + if ( strpos( $from_email, '@yahoo.com' ) ) { | |
| 691 | + | |
| 726 | 692 | // Get the site domain and get rid of www. |
| 727 | 693 | $sitename = strtolower( FrmAppHelper::get_server_value( 'SERVER_NAME' ) ); |
| 728 | - | |
| 729 | - if ( str_starts_with( $sitename, 'www.' ) ) { | |
| 694 | + if ( substr( $sitename, 0, 4 ) === 'www.' ) { | |
| 730 | 695 | $sitename = substr( $sitename, 4 ); |
| 731 | 696 | } |
| 732 | 697 | |
| 733 | 698 | $from_email = 'wordpress@' . $sitename; |
| @@ -749,9 +714,9 @@ | ||
| 749 | 714 | $reply_to = trim( $reply_to ); |
| 750 | 715 | |
| 751 | 716 | if ( ! is_email( $reply_to ) ) { |
| 752 | 717 | list( $name, $email ) = $this->get_name_and_email_for_sender( $reply_to ); |
| 753 | - $reply_to = $this->format_from_email( $name, $email ); | |
| 718 | + $reply_to = $this->format_from_email( $name, $email ); | |
| 754 | 719 | } |
| 755 | 720 | |
| 756 | 721 | return $reply_to; |
| 757 | 722 | } |
| @@ -759,17 +724,12 @@ | ||
| 759 | 724 | /** |
| 760 | 725 | * Get only the email if the name and email have been combined |
| 761 | 726 | * |
| 762 | 727 | * @since 3.0.06 |
| 763 | - * | |
| 764 | - * @param string $name | |
| 765 | - * | |
| 766 | - * @return string | |
| 767 | 728 | */ |
| 768 | 729 | private function get_email_from_name( $name ) { |
| 769 | 730 | $email = trim( trim( $name, '>' ), '<' ); |
| 770 | - | |
| 771 | - if ( str_contains( $email, '<' ) ) { | |
| 731 | + if ( strpos( $email, '<' ) !== false ) { | |
| 772 | 732 | $parts = explode( '<', $email ); |
| 773 | 733 | $email = trim( $parts[1], '>' ); |
| 774 | 734 | } |
| 775 | 735 | |
| @@ -801,16 +761,15 @@ | ||
| 801 | 761 | } |
| 802 | 762 | |
| 803 | 763 | /** |
| 804 | 764 | * @since 3.0.06 |
| 805 | - * | |
| 806 | - * @param string $name | |
| 807 | - * @param string $email | |
| 808 | - * | |
| 809 | - * @return string | |
| 810 | 765 | */ |
| 811 | 766 | private function format_from_email( $name, $email ) { |
| 812 | - return '' !== $name ? $name . ' <' . $email . '>' : $email; | |
| 767 | + if ( '' !== $name ) { | |
| 768 | + $email = $name . ' <' . $email . '>'; | |
| 769 | + } | |
| 770 | + | |
| 771 | + return $email; | |
| 813 | 772 | } |
| 814 | 773 | |
| 815 | 774 | /** |
| 816 | 775 | * Remove phone numbers from To addresses |
| @@ -816,42 +775,38 @@ | ||
| 816 | 775 | * Remove phone numbers from To addresses |
| 817 | 776 | * Send the phone numbers to the frm_send_to_not_email hook |
| 818 | 777 | * |
| 819 | 778 | * @since 2.03.04 |
| 820 | - * | |
| 821 | - * @return void | |
| 822 | 779 | */ |
| 823 | 780 | private function handle_phone_numbers() { |
| 781 | + | |
| 824 | 782 | foreach ( $this->to as $key => $recipient ) { |
| 825 | - if ( '[admin_email]' === $recipient || is_email( $recipient ) ) { | |
| 826 | - continue; | |
| 827 | - } | |
| 783 | + if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) { | |
| 784 | + $recipient = explode( ' ', $recipient ); | |
| 828 | 785 | |
| 829 | - $recipient = explode( ' ', $recipient ); | |
| 786 | + if ( is_email( end( $recipient ) ) ) { | |
| 787 | + continue; | |
| 788 | + } | |
| 830 | 789 | |
| 831 | - if ( is_email( end( $recipient ) ) ) { | |
| 832 | - continue; | |
| 790 | + do_action( | |
| 791 | + 'frm_send_to_not_email', | |
| 792 | + array( | |
| 793 | + 'e' => $recipient, | |
| 794 | + 'subject' => $this->subject, | |
| 795 | + 'mail_body' => $this->message, | |
| 796 | + 'reply_to' => $this->reply_to, | |
| 797 | + 'from' => $this->from, | |
| 798 | + 'plain_text' => $this->is_plain_text, | |
| 799 | + 'attachments' => $this->attachments, | |
| 800 | + 'form' => $this->form, | |
| 801 | + 'email_key' => $key, | |
| 802 | + ) | |
| 803 | + ); | |
| 804 | + | |
| 805 | + // Remove phone number from to addresses | |
| 806 | + unset( $this->to[ $key ] ); | |
| 833 | 807 | } |
| 834 | - | |
| 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 | |
| 853 | - }//end foreach | |
| 808 | + } | |
| 854 | 809 | } |
| 855 | 810 | |
| 856 | 811 | /** |
| 857 | 812 | * Package an array of FrmEmail properties |
| @@ -870,12 +825,10 @@ | ||
| 870 | 825 | 'subject' => $this->subject, |
| 871 | 826 | 'message' => $this->message, |
| 872 | 827 | 'attachments' => $this->attachments, |
| 873 | 828 | 'plain_text' => $this->is_plain_text, |
| 874 | - 'email_key' => $this->email_key, | |
| 875 | 829 | 'form' => $this->form, |
| 876 | 830 | 'entry' => $this->entry, |
| 877 | - 'email_style' => $this->settings['email_style'], | |
| 878 | 831 | ); |
| 879 | 832 | } |
| 880 | 833 | |
| 881 | 834 | /** |
| @@ -881,10 +834,8 @@ | ||
| 881 | 834 | /** |
| 882 | 835 | * Remove the Buddypress email filters |
| 883 | 836 | * |
| 884 | 837 | * @since 2.03.04 |
| 885 | - * | |
| 886 | - * @return void | |
| 887 | 838 | */ |
| 888 | 839 | private function remove_buddypress_filters() { |
| 889 | 840 | remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' ); |
| 890 | 841 | remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' ); |
| @@ -894,10 +845,8 @@ | ||
| 894 | 845 | * Add Mandrill line break filter |
| 895 | 846 | * Remove line breaks in HTML emails to prevent conflicts with Mandrill |
| 896 | 847 | * |
| 897 | 848 | * @since 2.03.04 |
| 898 | - * | |
| 899 | - * @return void | |
| 900 | 849 | */ |
| 901 | 850 | private function add_mandrill_filter() { |
| 902 | 851 | if ( ! $this->is_plain_text ) { |
| 903 | 852 | add_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| @@ -907,10 +856,8 @@ | ||
| 907 | 856 | /** |
| 908 | 857 | * Remove Mandrill line break filter |
| 909 | 858 | * |
| 910 | 859 | * @since 2.03.04 |
| 911 | - * | |
| 912 | - * @return void | |
| 913 | 860 | */ |
| 914 | 861 | private function remove_mandrill_filter() { |
| 915 | 862 | remove_filter( 'mandrill_nl2br', 'FrmEmailHelper::remove_mandrill_br' ); |
| 916 | 863 | } |
| @@ -923,9 +870,9 @@ | ||
| 923 | 870 | * @return string |
| 924 | 871 | */ |
| 925 | 872 | private function encode_subject( $subject ) { |
| 926 | 873 | if ( apply_filters( 'frm_encode_subject', false, $subject ) ) { |
| 927 | - return '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?='; | |
| 874 | + $subject = '=?' . $this->charset . '?B?' . base64_encode( $subject ) . '?='; | |
| 928 | 875 | } |
| 929 | 876 | |
| 930 | 877 | return $subject; |
| 931 | 878 | } |