Skip to:
Content

BuddyPress.org

Ticket #8322: 8322.patch

File 8322.patch, 6.5 KB (added by imath, 3 years ago)
  • src/bp-core/classes/class-bp-phpmailer.php

    diff --git src/bp-core/classes/class-bp-phpmailer.php src/bp-core/classes/class-bp-phpmailer.php
    index ab0b3e14e..76b24395d 100644
    class BP_PHPMailer implements BP_Email_Delivery { 
    2626         */
    2727        public function bp_email( BP_Email $email ) {
    2828                static $phpmailer = null;
     29                $phpmailer_is_6_0 = false;
    2930
    3031                /**
    3132                 * Filter PHPMailer object to use.
    class BP_PHPMailer implements BP_Email_Delivery { 
    3839                 */
    3940                $phpmailer = apply_filters( 'bp_phpmailer_object', $phpmailer );
    4041
    41                 if ( ! ( $phpmailer instanceof PHPMailer ) ) {
    42                         if ( ! class_exists( 'PHPMailer' ) ) {
    43                                 require_once ABSPATH . WPINC . '/class-phpmailer.php';
    44                                 require_once ABSPATH . WPINC . '/class-smtp.php';
     42                /**
     43                 * WordPress 5.5 deprecated version 5.2 of PHPMailer
     44                 * and is now using version 6.0 of PHPMailer.
     45                 */
     46                if ( file_exists( ABSPATH . WPINC . '/PHPMailer/PHPMailer.php' ) ) {
     47                        if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
     48                                if ( ! class_exists( 'PHPMailer\\PHPMailer\\PHPMailer' ) ) {
     49                                        require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
     50                                        require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
     51                                        require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
     52                                }
     53
     54                                $phpmailer        = new PHPMailer\PHPMailer\PHPMailer( true );
     55                                $phpmailer_is_6_0 = true;
    4556                        }
     57                } else {
     58                        if ( ! ( $phpmailer instanceof PHPMailer ) ) {
     59                                if ( ! class_exists( 'PHPMailer' ) ) {
     60                                        require_once ABSPATH . WPINC . '/class-phpmailer.php';
     61                                        require_once ABSPATH . WPINC . '/class-smtp.php';
     62                                }
    4663
    47                         $phpmailer = new PHPMailer( true );
     64                                $phpmailer = new PHPMailer( true );
     65                        }
    4866                }
    4967
    50 
    5168                /*
    5269                 * Resets.
    5370                 */
    class BP_PHPMailer implements BP_Email_Delivery { 
    5875                $phpmailer->clearReplyTos();
    5976                $phpmailer->Sender = '';
    6077
    61 
    6278                /*
    6379                 * Set up.
    6480                 */
    65 
    6681                $phpmailer->IsMail();
    6782                $phpmailer->CharSet = bp_get_option( 'blog_charset' );
    6883
    69 
    7084                /*
    7185                 * Content.
    7286                 */
    73 
    7487                $phpmailer->Subject = $email->get_subject( 'replace-tokens' );
    75                 $content_plaintext  = PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) );
     88                if ( $phpmailer_is_6_0 ) {
     89                        $content_plaintext = PHPMailer\PHPMailer\PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) );
     90                } else {
     91                        $content_plaintext = PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) );
     92                }
    7693
    7794                if ( $email->get( 'content_type' ) === 'html' ) {
    7895                        $phpmailer->msgHTML( $email->get_template( 'add-content' ) );
    class BP_PHPMailer implements BP_Email_Delivery { 
    84101                }
    85102
    86103                $recipient = $email->get_from();
    87                 try {
    88                         $phpmailer->SetFrom( $recipient->get_address(), $recipient->get_name(), false );
    89                 } catch ( phpmailerException $e ) {
     104                if ( $phpmailer_is_6_0 ) {
     105                        try {
     106                                $phpmailer->setFrom( $recipient->get_address(), $recipient->get_name(), false );
     107                        } catch ( PHPMailer\PHPMailer\Exception $e ) {
     108                        }
     109                } else {
     110                        try {
     111                                $phpmailer->SetFrom( $recipient->get_address(), $recipient->get_name(), false );
     112                        } catch ( phpmailerException $e ) {
     113                        }
    90114                }
    91115
    92116                $recipient = $email->get_reply_to();
    93                 try {
    94                         $phpmailer->addReplyTo( $recipient->get_address(), $recipient->get_name() );
    95                 } catch ( phpmailerException $e ) {
     117                if ( $phpmailer_is_6_0 ) {
     118                        try {
     119                                $phpmailer->addReplyTo( $recipient->get_address(), $recipient->get_name() );
     120                        } catch ( PHPMailer\PHPMailer\Exception $e ) {
     121                        }
     122                } else {
     123                        try {
     124                                $phpmailer->addReplyTo( $recipient->get_address(), $recipient->get_name() );
     125                        } catch ( phpmailerException $e ) {
     126                        }
    96127                }
    97128
    98129                $recipients = $email->get_to();
    99                 foreach ( $recipients as $recipient ) {
    100                         try {
    101                                 $phpmailer->AddAddress( $recipient->get_address(), $recipient->get_name() );
    102                         } catch ( phpmailerException $e ) {
     130                if ( $phpmailer_is_6_0 ) {
     131                        foreach ( $recipients as $recipient ) {
     132                                try {
     133                                        $phpmailer->AddAddress( $recipient->get_address(), $recipient->get_name() );
     134                                } catch ( PHPMailer\PHPMailer\Exception $e ) {
     135                                }
     136                        }
     137                } else {
     138                        foreach ( $recipients as $recipient ) {
     139                                try {
     140                                        $phpmailer->AddAddress( $recipient->get_address(), $recipient->get_name() );
     141                                } catch ( phpmailerException $e ) {
     142                                }
    103143                        }
    104144                }
    105145
    106146                $recipients = $email->get_cc();
    107                 foreach ( $recipients as $recipient ) {
    108                         try {
    109                                 $phpmailer->AddCc( $recipient->get_address(), $recipient->get_name() );
    110                         } catch ( phpmailerException $e ) {
     147                if ( $phpmailer_is_6_0 ) {
     148                        foreach ( $recipients as $recipient ) {
     149                                try {
     150                                        $phpmailer->AddCc( $recipient->get_address(), $recipient->get_name() );
     151                                } catch ( PHPMailer\PHPMailer\Exception $e ) {
     152                                }
     153                        }
     154                } else {
     155                        foreach ( $recipients as $recipient ) {
     156                                try {
     157                                        $phpmailer->AddCc( $recipient->get_address(), $recipient->get_name() );
     158                                } catch ( phpmailerException $e ) {
     159                                }
    111160                        }
    112161                }
    113162
    114163                $recipients = $email->get_bcc();
    115                 foreach ( $recipients as $recipient ) {
    116                         try {
    117                                 $phpmailer->AddBcc( $recipient->get_address(), $recipient->get_name() );
    118                         } catch ( phpmailerException $e ) {
     164                if ( $phpmailer_is_6_0 ) {
     165                        foreach ( $recipients as $recipient ) {
     166                                try {
     167                                        $phpmailer->AddBcc( $recipient->get_address(), $recipient->get_name() );
     168                                } catch ( PHPMailer\PHPMailer\Exception $e ) {
     169                                }
     170                        }
     171                } else {
     172                        foreach ( $recipients as $recipient ) {
     173                                try {
     174                                        $phpmailer->AddBcc( $recipient->get_address(), $recipient->get_name() );
     175                                } catch ( phpmailerException $e ) {
     176                                }
    119177                        }
    120178                }
    121179
    class BP_PHPMailer implements BP_Email_Delivery { 
    124182                        $phpmailer->AddCustomHeader( $name, $content );
    125183                }
    126184
    127 
    128185                /**
    129186                 * Fires after PHPMailer is initialised.
    130187                 *
    class BP_PHPMailer implements BP_Email_Delivery { 
    137194                /** This filter is documented in wp-includes/pluggable.php */
    138195                do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
    139196
    140                 try {
    141                         return $phpmailer->Send();
    142                 } catch ( phpmailerException $e ) {
    143                         return new WP_Error( $e->getCode(), $e->getMessage(), $email );
     197                if ( $phpmailer_is_6_0 ) {
     198                        try {
     199                                return $phpmailer->Send();
     200                        } catch ( PHPMailer\PHPMailer\Exception $e ) {
     201                                return new WP_Error( $e->getCode(), $e->getMessage(), $email );
     202                        }
     203                } else {
     204                        try {
     205                                return $phpmailer->Send();
     206                        } catch ( phpmailerException $e ) {
     207                                return new WP_Error( $e->getCode(), $e->getMessage(), $email );
     208                        }
    144209                }
    145210        }
    146211
    147 
    148212        /*
    149213         * Utility/helper functions.
    150214         */