Changeset 3433348
- Timestamp:
- 01/06/2026 08:42:31 AM (3 months ago)
- Location:
- mailgun/trunk
- Files:
-
- 6 edited
-
includes/admin.php (modified) (1 diff)
-
includes/mg-filter.php (modified) (5 diffs)
-
includes/wp-mail-api.php (modified) (7 diffs)
-
mailgun.php (modified) (3 diffs)
-
readme.md (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mailgun/trunk/includes/admin.php
r3251723 r3433348 30 30 * @var array 31 31 */ 32 protected array $options = array();32 protected array $options = []; 33 33 34 34 /** -
mailgun/trunk/includes/mg-filter.php
r3245197 r3433348 163 163 $from_addr 164 164 ); 165 if ( ! is_null($filter_from_addr) || ! empty($filter_from_addr)) {165 if (!is_null($filter_from_addr)) { 166 166 $from_addr = $filter_from_addr; 167 167 } … … 194 194 * @since 1.5.8 195 195 */ 196 function mg_parse_headers( $headers = array()): array {196 function mg_parse_headers( $headers = []): array { 197 197 if (empty($headers)) { 198 return array();198 return []; 199 199 } 200 200 … … 205 205 } 206 206 207 $new_headers = array();207 $new_headers = []; 208 208 if ( ! empty($tmp)) { 209 209 $name = null; … … 233 233 234 234 if ( ! isset($new_headers[ $name ])) { 235 $new_headers[ $name ] = array();235 $new_headers[ $name ] = []; 236 236 } 237 237 … … 265 265 foreach ($headers as $name => $values) { 266 266 $header_string .= sprintf('%s: ', $name); 267 $header_values = array();267 $header_values = []; 268 268 269 269 foreach ($values as $content) { -
mailgun/trunk/includes/wp-mail-api.php
r3317194 r3433348 72 72 73 73 if (has_filter('mg_use_recipient_vars_syntax')) { 74 $rcpt_vars = array();74 $rcpt_vars = []; 75 75 $use_rcpt_vars = apply_filters('mg_use_recipient_vars_syntax', null); 76 76 if ($use_rcpt_vars) { … … 123 123 * @throws \PHPMailer\PHPMailer\Exception 124 124 */ 125 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()) {125 function wp_mail( $to, $subject, $message, $headers = '', $attachments = []) { 126 126 $mailgun = get_option('mailgun'); 127 127 $region = ( defined('MAILGUN_REGION') && MAILGUN_REGION ) ? MAILGUN_REGION : $mailgun['region']; … … 170 170 } 171 171 172 $cc = array();173 $bcc = array();172 $cc = []; 173 $bcc = []; 174 174 175 175 // Headers 176 176 if (empty($headers)) { 177 $headers = array();177 $headers = []; 178 178 } else { 179 179 if ( ! is_array($headers)) { … … 184 184 $tempheaders = $headers; 185 185 } 186 $headers = array();187 $cc = array();188 $bcc = array();186 $headers = []; 187 $cc = []; 188 $bcc = []; 189 189 190 190 // If it's actually got contents … … 274 274 } 275 275 276 $body['o:tag'] = array();276 $body['o:tag'] = []; 277 277 if (defined('MAILGUN_TRACK_CLICKS')) { 278 278 $trackClicks = MAILGUN_TRACK_CLICKS; … … 496 496 497 497 // Email Fallback 498 if (!$isFallbackNeeded) return true; 499 498 500 $isFallbackEnabled = get_option('email_fallback') ?: 'no'; 499 if ($isFallbackNeeded && $isFallbackEnabled === 'yes') { 500 global $phpmailer; 501 502 // (Re)create it, if it's gone missing. 503 if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer )) { 504 require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; 505 require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; 506 require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; 507 $phpmailer = new PHPMailer\PHPMailer\PHPMailer(true); 508 509 $phpmailer::$validator = static function ( $email ) { 510 return (bool) is_email($email); 511 }; 512 } 513 514 // Empty out the values that may be set. 515 $phpmailer->clearAllRecipients(); 516 $phpmailer->clearAttachments(); 517 $phpmailer->clearCustomHeaders(); 518 $phpmailer->clearReplyTos(); 519 $phpmailer->Body = ''; 520 $phpmailer->AltBody = ''; 521 522 // Set "From" name and email. 523 524 // If we don't have a name from the input headers. 525 if ( ! isset($from_name)) { 526 $from_name = 'WordPress'; 527 } 528 529 /* 530 * If we don't have an email from the input headers, default to wordpress@$sitename 531 * Some hosts will block outgoing mail from this address if it doesn't exist, 532 * but there's no easy alternative. Defaulting to admin_email might appear to be 533 * another option, but some hosts may refuse to relay mail from an unknown domain. 534 * See https://core.trac.wordpress.org/ticket/5007. 535 */ 536 if ( ! isset($from_email)) { 537 // Get the site domain and get rid of www. 538 $sitename = wp_parse_url(network_home_url(), PHP_URL_HOST); 539 $from_email = 'wordpress@'; 540 541 if (null !== $sitename) { 542 if (str_starts_with($sitename, 'www.')) { 543 $sitename = substr($sitename, 4); 501 if (!($isFallbackEnabled === 'yes')) return false; 502 503 global $phpmailer; 504 505 // (Re)create it, if it's gone missing. 506 if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer )) { 507 require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; 508 require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; 509 require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; 510 $phpmailer = new PHPMailer\PHPMailer\PHPMailer(true); 511 512 $phpmailer::$validator = static function ( $email ) { 513 return (bool) is_email($email); 514 }; 515 } 516 517 // Empty out the values that may be set. 518 $phpmailer->clearAllRecipients(); 519 $phpmailer->clearAttachments(); 520 $phpmailer->clearCustomHeaders(); 521 $phpmailer->clearReplyTos(); 522 $phpmailer->Body = ''; 523 $phpmailer->AltBody = ''; 524 525 // Set "From" name and email. 526 527 // If we don't have a name from the input headers. 528 if ( ! isset($from_name)) { 529 $from_name = 'WordPress'; 530 } 531 532 /* 533 * If we don't have an email from the input headers, default to wordpress@$sitename 534 * Some hosts will block outgoing mail from this address if it doesn't exist, 535 * but there's no easy alternative. Defaulting to admin_email might appear to be 536 * another option, but some hosts may refuse to relay mail from an unknown domain. 537 * See https://core.trac.wordpress.org/ticket/5007. 538 */ 539 if ( ! isset($from_email)) { 540 // Get the site domain and get rid of www. 541 $sitename = wp_parse_url(network_home_url(), PHP_URL_HOST); 542 $from_email = 'wordpress@'; 543 544 if (null !== $sitename) { 545 if (str_starts_with($sitename, 'www.')) { 546 $sitename = substr($sitename, 4); 547 } 548 549 $from_email .= $sitename; 550 } 551 } 552 553 /** 554 * Filters the email address to send from. 555 * 556 * @param string $from_email Email address to send from. 557 * @since 2.2.0 558 */ 559 $from_email = apply_filters('wp_mail_from', $from_email); 560 561 /** 562 * Filters the name to associate with the "from" email address. 563 * 564 * @param string $from_name Name associated with the "from" email address. 565 * @since 2.3.0 566 */ 567 $from_name = apply_filters('wp_mail_from_name', $from_name); 568 569 try { 570 $phpmailer->setFrom($from_email, $from_name, false); 571 } catch (PHPMailer\PHPMailer\Exception $e) { 572 $mail_error_data = compact('to', 'subject', 'message', 'headers', 'attachments'); 573 $mail_error_data['phpmailer_exception_code'] = $e->getCode(); 574 575 /** This filter is documented in wp-includes/pluggable.php */ 576 do_action('wp_mail_failed', new WP_Error('wp_mail_failed', $e->getMessage(), $mail_error_data)); 577 578 return false; 579 } 580 581 // Set mail's subject and body. 582 $phpmailer->Subject = $subject; 583 $phpmailer->Body = $message; 584 585 // Set destination addresses, using appropriate methods for handling addresses. 586 $address_headers = compact('to', 'cc', 'bcc', 'replyTo'); 587 588 foreach ($address_headers as $address_header => $addresses) { 589 if (empty($addresses)) { 590 continue; 591 } 592 593 foreach ( (array) $addresses as $address) { 594 try { 595 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>". 596 $recipient_name = ''; 597 598 if (preg_match('/(.*)<(.+)>/', $address, $matches)) { 599 if (count($matches) === 3) { 600 $recipient_name = $matches[1]; 601 $address = $matches[2]; 602 } 544 603 } 545 604 546 $from_email .= $sitename; 547 } 548 } 549 550 /** 551 * Filters the email address to send from. 552 * 553 * @param string $from_email Email address to send from. 554 * @since 2.2.0 555 */ 556 $from_email = apply_filters('wp_mail_from', $from_email); 557 558 /** 559 * Filters the name to associate with the "from" email address. 560 * 561 * @param string $from_name Name associated with the "from" email address. 562 * @since 2.3.0 563 */ 564 $from_name = apply_filters('wp_mail_from_name', $from_name); 565 566 try { 567 $phpmailer->setFrom($from_email, $from_name, false); 568 } catch (PHPMailer\PHPMailer\Exception $e) { 569 $mail_error_data = compact('to', 'subject', 'message', 'headers', 'attachments'); 570 $mail_error_data['phpmailer_exception_code'] = $e->getCode(); 571 572 /** This filter is documented in wp-includes/pluggable.php */ 573 do_action('wp_mail_failed', new WP_Error('wp_mail_failed', $e->getMessage(), $mail_error_data)); 574 575 return false; 576 } 577 578 // Set mail's subject and body. 579 $phpmailer->Subject = $subject; 580 $phpmailer->Body = $message; 581 582 // Set destination addresses, using appropriate methods for handling addresses. 583 $address_headers = compact('to', 'cc', 'bcc', 'replyTo'); 584 585 foreach ($address_headers as $address_header => $addresses) { 586 if (empty($addresses)) { 605 switch ($address_header) { 606 case 'to': 607 $phpmailer->addAddress($address, $recipient_name); 608 break; 609 case 'cc': 610 $phpmailer->addCc($address, $recipient_name); 611 break; 612 case 'bcc': 613 $phpmailer->addBcc($address, $recipient_name); 614 break; 615 case 'reply_to': 616 $phpmailer->addReplyTo($address, $recipient_name); 617 break; 618 } 619 } catch (PHPMailer\PHPMailer\Exception $e) { 587 620 continue; 588 621 } 589 590 foreach ( (array) $addresses as $address) { 622 } 623 } 624 625 // Set to use PHP's mail(). 626 $phpmailer->isMail(); 627 628 // Set Content-Type and charset. 629 630 // If we don't have a Content-Type from the input headers. 631 if ( ! isset($content_type)) { 632 $content_type = 'text/plain'; 633 } 634 635 /** 636 * Filters the wp_mail() content type. 637 * 638 * @param string $content_type Default wp_mail() content type. 639 * @since 2.3.0 640 */ 641 $content_type = apply_filters('wp_mail_content_type', $content_type); 642 643 $phpmailer->ContentType = $content_type; 644 645 // Set whether it's plaintext, depending on $content_type. 646 if ('text/html' === $content_type) { 647 $phpmailer->isHTML(true); 648 } 649 650 // If we don't have a charset from the input headers. 651 if ( ! isset($charset)) { 652 $charset = get_bloginfo('charset'); 653 } 654 655 /** 656 * Filters the default wp_mail() charset. 657 * 658 * @param string $charset Default email charset. 659 * @since 2.3.0 660 */ 661 $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset); 662 663 // Set custom headers. 664 if ( ! empty($headers)) { 665 foreach ( (array) $headers as $name => $content) { 666 // Only add custom headers not added automatically by PHPMailer. 667 if ( ! in_array($name, array( 'MIME-Version', 'X-Mailer' ), true)) { 591 668 try { 592 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>". 593 $recipient_name = ''; 594 595 if (preg_match('/(.*)<(.+)>/', $address, $matches)) { 596 if (count($matches) === 3) { 597 $recipient_name = $matches[1]; 598 $address = $matches[2]; 599 } 600 } 601 602 switch ($address_header) { 603 case 'to': 604 $phpmailer->addAddress($address, $recipient_name); 605 break; 606 case 'cc': 607 $phpmailer->addCc($address, $recipient_name); 608 break; 609 case 'bcc': 610 $phpmailer->addBcc($address, $recipient_name); 611 break; 612 case 'reply_to': 613 $phpmailer->addReplyTo($address, $recipient_name); 614 break; 615 } 669 $phpmailer->addCustomHeader(sprintf('%1$s: %2$s', $name, $content)); 616 670 } catch (PHPMailer\PHPMailer\Exception $e) { 617 671 continue; … … 620 674 } 621 675 622 // Set to use PHP's mail(). 623 $phpmailer->isMail(); 624 625 // Set Content-Type and charset. 626 627 // If we don't have a Content-Type from the input headers. 628 if ( ! isset($content_type)) { 629 $content_type = 'text/plain'; 630 } 676 if (false !== stripos($content_type, 'multipart') && ! empty($boundary)) { 677 $phpmailer->addCustomHeader(sprintf('Content-Type: %s; boundary="%s"', $content_type, $boundary)); 678 } 679 } 680 681 if ( ! empty($attachments)) { 682 foreach ($attachments as $filename => $attachment) { 683 $filename = is_string($filename) ? $filename : ''; 684 685 try { 686 $phpmailer->addAttachment($attachment, $filename); 687 } catch (PHPMailer\PHPMailer\Exception $e) { 688 continue; 689 } 690 } 691 } 692 693 /** 694 * Fires after PHPMailer is initialized. 695 * 696 * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference). 697 * @since 2.2.0 698 */ 699 do_action_ref_array('phpmailer_init', array( &$phpmailer )); 700 701 $mail_data = compact('to', 'subject', 'message', 'headers', 'attachments'); 702 703 // Send! 704 try { 705 $send = $phpmailer->send(); 631 706 632 707 /** 633 * Filters the wp_mail() content type. 708 * Fires after PHPMailer has successfully sent an email. 709 * The firing of this action does not necessarily mean that the recipient(s) received the 710 * email successfully. It only means that the `send` method above was able to 711 * process the request without any errors. 634 712 * 635 * @param string $content_type Default wp_mail() content type. 636 * @since 2.3.0 713 * @param array $mail_data { 714 * An array containing the email recipient(s), subject, message, headers, and attachments. 715 * @type string[] $to Email addresses to send message. 716 * @type string $subject Email subject. 717 * @type string $message Message contents. 718 * @type string[] $headers Additional headers. 719 * @type string[] $attachments Paths to files to attach. 720 * } 721 * @since 5.9.0 637 722 */ 638 $content_type = apply_filters('wp_mail_content_type', $content_type); 639 640 $phpmailer->ContentType = $content_type; 641 642 // Set whether it's plaintext, depending on $content_type. 643 if ('text/html' === $content_type) { 644 $phpmailer->isHTML(true); 645 } 646 647 // If we don't have a charset from the input headers. 648 if ( ! isset($charset)) { 649 $charset = get_bloginfo('charset'); 650 } 723 do_action('wp_mail_succeeded', $mail_data); 724 725 return $send; 726 } catch (PHPMailer\PHPMailer\Exception $e) { 727 $mail_data['phpmailer_exception_code'] = $e->getCode(); 651 728 652 729 /** 653 * Fi lters the default wp_mail() charset.730 * Fires after a PHPMailer\PHPMailer\Exception is caught. 654 731 * 655 * @param string $charset Default email charset. 656 * @since 2.3.0 732 * @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array 733 * containing the mail recipient, subject, message, headers, and attachments. 734 * @since 4.4.0 657 735 */ 658 $phpmailer->CharSet = apply_filters('wp_mail_charset', $charset); 659 660 // Set custom headers. 661 if ( ! empty($headers)) { 662 foreach ( (array) $headers as $name => $content) { 663 // Only add custom headers not added automatically by PHPMailer. 664 if ( ! in_array($name, array( 'MIME-Version', 'X-Mailer' ), true)) { 665 try { 666 $phpmailer->addCustomHeader(sprintf('%1$s: %2$s', $name, $content)); 667 } catch (PHPMailer\PHPMailer\Exception $e) { 668 continue; 669 } 670 } 671 } 672 673 if (false !== stripos($content_type, 'multipart') && ! empty($boundary)) { 674 $phpmailer->addCustomHeader(sprintf('Content-Type: %s; boundary="%s"', $content_type, $boundary)); 675 } 676 } 677 678 if ( ! empty($attachments)) { 679 foreach ($attachments as $filename => $attachment) { 680 $filename = is_string($filename) ? $filename : ''; 681 682 try { 683 $phpmailer->addAttachment($attachment, $filename); 684 } catch (PHPMailer\PHPMailer\Exception $e) { 685 continue; 686 } 687 } 688 } 689 690 /** 691 * Fires after PHPMailer is initialized. 692 * 693 * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference). 694 * @since 2.2.0 695 */ 696 do_action_ref_array('phpmailer_init', array( &$phpmailer )); 697 698 $mail_data = compact('to', 'subject', 'message', 'headers', 'attachments'); 699 700 // Send! 701 try { 702 $send = $phpmailer->send(); 703 704 /** 705 * Fires after PHPMailer has successfully sent an email. 706 * The firing of this action does not necessarily mean that the recipient(s) received the 707 * email successfully. It only means that the `send` method above was able to 708 * process the request without any errors. 709 * 710 * @param array $mail_data { 711 * An array containing the email recipient(s), subject, message, headers, and attachments. 712 * @type string[] $to Email addresses to send message. 713 * @type string $subject Email subject. 714 * @type string $message Message contents. 715 * @type string[] $headers Additional headers. 716 * @type string[] $attachments Paths to files to attach. 717 * } 718 * @since 5.9.0 719 */ 720 do_action('wp_mail_succeeded', $mail_data); 721 722 return $send; 723 } catch (PHPMailer\PHPMailer\Exception $e) { 724 $mail_data['phpmailer_exception_code'] = $e->getCode(); 725 726 /** 727 * Fires after a PHPMailer\PHPMailer\Exception is caught. 728 * 729 * @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array 730 * containing the mail recipient, subject, message, headers, and attachments. 731 * @since 4.4.0 732 */ 733 do_action('wp_mail_failed', new WP_Error('wp_mail_failed', $e->getMessage(), $mail_data)); 734 735 return false; 736 } 737 } 738 739 return true; 736 do_action('wp_mail_failed', new WP_Error('wp_mail_failed', $e->getMessage(), $mail_data)); 737 738 return false; 739 } 740 740 } 741 741 } -
mailgun/trunk/mailgun.php
r3317194 r3433348 4 4 * Plugin URI: http://wordpress.org/extend/plugins/mailgun/ 5 5 * Description: Mailgun integration for WordPress 6 * Version: 2.1. 96 * Version: 2.1.10 7 7 * Requires PHP: 7.4 8 * Requires at least: 4.48 * Requires at least: 5.6 9 9 * Author: Mailgun 10 10 * Author URI: http://www.mailgun.com/ … … 214 214 * @return string 215 215 */ 216 public function api_call( string $uri, array $params = array(), string $method = 'POST' ): string {216 public function api_call( string $uri, array $params = [], string $method = 'POST' ): string { 217 217 $options = get_option( 'mailgun' ); 218 218 $getRegion = ( defined( 'MAILGUN_REGION' ) && MAILGUN_REGION ) ? MAILGUN_REGION : $options['region']; … … 370 370 * @throws JsonException 371 371 */ 372 public function list_form( string $list_address, array $args = array()): void {372 public function list_form( string $list_address, array $args = []): void { 373 373 $widgetId = $args['widget_id'] ?? 0; 374 374 $widget_class_id = "mailgun-list-widget-{$widgetId}"; -
mailgun/trunk/readme.md
r3317194 r3433348 5 5 Tags: mailgun, smtp, http, api, mail, email 6 6 Tested up to: 6.8.1 7 Stable tag: 2.1. 97 Stable tag: 2.1.10 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later -
mailgun/trunk/readme.txt
r3317194 r3433348 5 5 Tags: mailgun, smtp, http, api, mail, email 6 6 Tested up to: 6.8.1 7 Stable tag: 2.1. 97 Stable tag: 2.1.10 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.