Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/28/2016 07:26:34 PM (10 years ago)
Author:
djpaul
Message:

Emails: update set_to, set_bcc, set_cc to correctly handle multiple recipients.

Also tweaks the PHPDoc to make the intended use of the array argument
clearer.

See #6592

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-email.php

    r10470 r10481  
    520520         *
    521521         * @param string|array|int|WP_User $bcc_address Either a email address, user ID, WP_User object,
    522          *                                              or an array containg the address and name.
     522         *                                              or an array containing any combination of the above.
    523523         * @param string $name Optional. If $bcc_address is a string, this is the recipient's name.
    524524         * @return BP_Email
    525525         */
    526526        public function set_bcc( $bcc_address, $name = '' ) {
    527                 $bcc = array( new BP_Email_Recipient( $bcc_address, $name ) );
     527                $bcc = array();
     528
     529                if ( is_array( $bcc_address ) ) {
     530                        foreach ( $bcc_address as $address ) {
     531                                $bcc[] = new BP_Email_Recipient( $address );
     532                        }
     533
     534                } else {
     535                        $bcc = array( new BP_Email_Recipient( $bcc_address, $name ) );
     536                }
    528537
    529538                /**
     
    534543                 * @param BP_Email_Recipient[] $bcc BCC recipients.
    535544                 * @param string|array|int|WP_User $bcc_address Either a email address, user ID, WP_User object,
    536                  *                                              or an array containg the address and name.
     545                 *                                              or an array containing any combination of the above.
    537546                 * @param string $name Optional. If $bcc_address is a string, this is the recipient's name.
    538547                 * @param BP_Email $this Current instance of the email type class.
     
    555564         *
    556565         * @param string|array|int|WP_User $cc_address Either a email address, user ID, WP_User object,
    557          *                                             or an array containg the address and name.
     566         *                                             or an array containing any combination of the above.
    558567         * @param string $name Optional. If $cc_address is a string, this is the recipient's name.
    559568         * @return BP_Email
    560569         */
    561570        public function set_cc( $cc_address, $name = '' ) {
    562                 $cc = array( new BP_Email_Recipient( $cc_address, $name ) );
     571                $cc = array();
     572
     573                if ( is_array( $cc_address ) ) {
     574                        foreach ( $cc_address as $address ) {
     575                                $cc[] = new BP_Email_Recipient( $address );
     576                        }
     577
     578                } else {
     579                        $cc = array( new BP_Email_Recipient( $cc_address, $name ) );
     580                }
    563581
    564582                /**
     
    569587                 * @param BP_Email_Recipient[] $cc CC recipients.
    570588                 * @param string|array|int|WP_User $cc_address Either a email address, user ID, WP_User object,
    571                  *                                             or an array containg the address and name.
     589                 *                                             or an array containing any combination of the above.
    572590                 * @param string $name Optional. If $cc_address is a string, this is the recipient's name.
    573591                 * @param BP_Email $this Current instance of the email type class.
     
    658676         * @since 2.5.0
    659677         *
    660          * @param string|array|int|WP_User $email_address Either a email address, user ID, WP_User object,
    661          *                                                or an array containg the address and name.
     678         * @param string|array|int|WP_User $email_address Either a email address, user ID, or WP_User object.
    662679         * @param string $name Optional. If $email_address is a string, this is the recipient's name.
    663680         * @return BP_Email
     
    672689                 *
    673690                 * @param BP_Email_Recipient $from Sender details.
    674                  * @param string|array|int|WP_User $email_address Either a email address, user ID, WP_User object,
    675                  *                                                or an array containg the address and name.
     691                 * @param string|array|int|WP_User $email_address Either a email address, user ID, or WP_User object.
    676692                 * @param string $name Optional. If $email_address is a string, this is the recipient's name.
    677693                 * @param BP_Email $this Current instance of the email type class.
     
    727743         *
    728744         * @param string|array|int|WP_User $email_address Either a email address, user ID, WP_User object,
    729          *                                                or an array containg the address and name.
     745         *                                                or an array containing any combination of the above.
    730746         * @param string $name Optional. If $email_address is a string, this is the recipient's name.
    731747         * @return BP_Email
     
    741757                 * @param BP_Email_Recipient $reply_to "Reply to" recipient.
    742758                 * @param string|array|int|WP_User $email_address Either a email address, user ID, WP_User object,
    743                  *                                                or an array containg the address and name.
     759                 *                                                or an array containing any combination of the above.
    744760                 * @param string $name Optional. If $email_address is a string, this is the recipient's name.
    745761                 * @param BP_Email $this Current instance of the email type class.
     
    816832         *
    817833         * @param string|array|int|WP_User $to_address Either a email address, user ID, WP_User object,
    818          *                                             or an array containg the address and name.
     834         *                                             or an array containing any combination of the above.
    819835         * @param string $name Optional. If $to_address is a string, this is the recipient's name.
    820836         * @return BP_Email
    821837         */
    822838        public function set_to( $to_address, $name = '' ) {
    823                 $to = array( new BP_Email_Recipient( $to_address, $name ) );
     839                $to = array();
     840
     841                if ( is_array( $to_address ) ) {
     842                        foreach ( $to_address as $address ) {
     843                                $to[] = new BP_Email_Recipient( $address );
     844                        }
     845
     846                } else {
     847                        $to = array( new BP_Email_Recipient( $to_address, $name ) );
     848                }
    824849
    825850                /**
Note: See TracChangeset for help on using the changeset viewer.