Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/30/2016 08:39:59 PM (4 years ago)
Author:
djpaul
Message:

Emails: new param for set_bcc|cc|to() to add to current values

The default behaviour remains to replace the current value.

This will allow plugin developers to easily append a new email
recipient without having to re-add the existing recipients.

See #6592

File:
1 edited

Legend:

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

    r10481 r10482  
    522522     *                                              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.
    524      * @return BP_Email
    525      */
    526     public function set_bcc( $bcc_address, $name = '' ) {
    527         $bcc = array();
     524     * @param string $operation Optional. If "replace", $to_address replaces current setting (default).
     525     *                          If "add", $to_address is added to the current setting.
     526     * @return BP_Email
     527     */
     528    public function set_bcc( $bcc_address, $name = '', $operation = 'replace' ) {
     529        $bcc = ( $operation !== 'replace' ) ? $this->bcc : array();
    528530
    529531        if ( is_array( $bcc_address ) ) {
     
    533535
    534536        } else {
    535             $bcc = array( new BP_Email_Recipient( $bcc_address, $name ) );
     537            $bcc[] = new BP_Email_Recipient( $bcc_address, $name );
    536538        }
    537539
     
    545547         *                                              or an array containing any combination of the above.
    546548         * @param string $name Optional. If $bcc_address is a string, this is the recipient's name.
    547          * @param BP_Email $this Current instance of the email type class.
    548          */
    549         $this->bcc = apply_filters( 'bp_email_set_bcc', $bcc, $bcc_address, $name, $this );
     549         * @param string $operation If "replace", $to_address replaced previous recipients. If "add",
     550         *                          $to_address was added to the array of recipients.
     551         * @param BP_Email $this Current instance of the email type class.
     552         */
     553        $this->bcc = apply_filters( 'bp_email_set_bcc', $bcc, $bcc_address, $name, $operation, $this );
    550554
    551555        return $this;
     
    566570     *                                             or an array containing any combination of the above.
    567571     * @param string $name Optional. If $cc_address is a string, this is the recipient's name.
    568      * @return BP_Email
    569      */
    570     public function set_cc( $cc_address, $name = '' ) {
    571         $cc = array();
     572     * @param string $operation Optional. If "replace", $to_address replaces current setting (default).
     573     *                          If "add", $to_address is added to the current setting.
     574     * @return BP_Email
     575     */
     576    public function set_cc( $cc_address, $name = '', $operation = 'replace' ) {
     577        $cc = ( $operation !== 'replace' ) ? $this->cc : array();
    572578
    573579        if ( is_array( $cc_address ) ) {
     
    577583
    578584        } else {
    579             $cc = array( new BP_Email_Recipient( $cc_address, $name ) );
     585            $cc[] = new BP_Email_Recipient( $cc_address, $name );
    580586        }
    581587
     
    589595         *                                             or an array containing any combination of the above.
    590596         * @param string $name Optional. If $cc_address is a string, this is the recipient's name.
    591          * @param BP_Email $this Current instance of the email type class.
    592          */
    593         $this->cc = apply_filters( 'bp_email_set_cc', $cc, $cc_address, $name, $this );
     597         * @param string $operation If "replace", $to_address replaced previous recipients. If "add",
     598         *                          $to_address was added to the array of recipients.
     599         * @param BP_Email $this Current instance of the email type class.
     600         */
     601        $this->cc = apply_filters( 'bp_email_set_cc', $cc, $cc_address, $name, $operation, $this );
    594602
    595603        return $this;
     
    834842     *                                             or an array containing any combination of the above.
    835843     * @param string $name Optional. If $to_address is a string, this is the recipient's name.
    836      * @return BP_Email
    837      */
    838     public function set_to( $to_address, $name = '' ) {
    839         $to = array();
     844     * @param string $operation Optional. If "replace", $to_address replaces current setting (default).
     845     *                          If "add", $to_address is added to the current setting.
     846     * @return BP_Email
     847     */
     848    public function set_to( $to_address, $name = '', $operation = 'replace' ) {
     849        $to = ( $operation !== 'replace' ) ? $this->to : array();
    840850
    841851        if ( is_array( $to_address ) ) {
     
    845855
    846856        } else {
    847             $to = array( new BP_Email_Recipient( $to_address, $name ) );
     857            $to[] = new BP_Email_Recipient( $to_address, $name );
    848858        }
    849859
     
    856866         * @param string $to_address "To" address.
    857867         * @param string $name "To" name.
    858          * @param BP_Email $this Current instance of the email type class.
    859          */
    860         $this->to = apply_filters( 'bp_email_set_to', $to, $to_address, $name, $this );
     868         * @param string $operation If "replace", $to_address replaced previous recipients. If "add",
     869         *                          $to_address was added to the array of recipients.
     870         * @param BP_Email $this Current instance of the email type class.
     871         */
     872        $this->to = apply_filters( 'bp_email_set_to', $to, $to_address, $name, $operation, $this );
    861873
    862874        return $this;
Note: See TracChangeset for help on using the changeset viewer.