Skip to:
Content

BuddyPress.org

Changeset 12353


Ignore:
Timestamp:
03/06/2019 04:31:35 PM (3 years ago)
Author:
boonebgorges
Message:

Emails: Improve performance when setting Reply-To and From headers.

The new BP_Email_Participant framework allows the Reply-To and From email
headers to be set without requiring an empty and potentially expensive WP
user lookup.

Fixes #8003.

Location:
trunk/src
Files:
3 added
3 edited

Legend:

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

    r10792 r12353  
    1515 * @since 2.5.0
    1616 */
    17 class BP_Email_Recipient {
    18 
    19     /**
    20      * Recipient's email address.
    21      *
    22      * @since 2.5.0
    23      *
    24      * @var string
    25      */
    26     protected $address = '';
    27 
    28     /**
    29      * Recipient's name.
    30      *
    31      * @since 2.5.0
    32      *
    33      * @var string
    34      */
    35     protected $name = '';
     17class BP_Email_Recipient extends BP_Email_Participant {
    3618
    3719    /**
     
    8971        // Set address if we have one.
    9072        if ( ! empty( $address ) ) {
    91             $this->address = sanitize_email( $address );
     73            $this->set_address( sanitize_email( $address ) );
    9274        }
    9375
     
    10284            $wp_name = wp_specialchars_decode( bp_core_get_user_displayname( $this->user_object->ID ), ENT_QUOTES );
    10385
    104             $this->address = $this->user_object->user_email;
    105             $this->name    = sanitize_text_field( $wp_name );
     86            $this->set_address( $this->user_object->user_email );
     87            $this->set_name( $wp_name );
    10688
    10789        }
     
    10991        // Custom name override.
    11092        if ( $name ) {
    111             $this->name = $name;
     93            $this->set_name( $name );
    11294        }
    11395
     
    133115     */
    134116    public function get_address() {
     117        $address = parent::get_address();
    135118
    136119        /**
     
    139122         * @since 2.5.0
    140123         *
    141          * @param string $address Recipient's address.
    142          * @param BP_Email $recipient $this Current instance of the email recipient class.
     124         * @param string             $address  Recipient's address.
     125         * @param BP_Email_Recipient $recipient Current instance of the email recipient class.
    143126         */
    144         return apply_filters( 'bp_email_recipient_get_address', $this->address, $this );
     127        return apply_filters( 'bp_email_recipient_get_address', $address, $this );
    145128    }
    146129
     
    153136     */
    154137    public function get_name() {
     138        $name = parent::get_name();
    155139
    156140        /**
     
    159143         * @since 2.5.0
    160144         *
    161          * @param string $name Recipient's name.
    162          * @param BP_Email $recipient $this Current instance of the email recipient class.
     145         * @param string             $name      Recipient's name.
     146         * @param BP_Email_Recipient $recipient Current instance of the email recipient class.
    163147         */
    164         return apply_filters( 'bp_email_recipient_get_name', $this->name, $this );
     148        return apply_filters( 'bp_email_recipient_get_name', $name, $this );
    165149    }
    166150
  • trunk/src/bp-core/classes/class-bp-email.php

    r12284 r12353  
    6666     * @since 2.5.0
    6767     *
    68      * @var BP_Email_Recipient Sender details.
     68     * @var BP_Email_Sender Sender details.
    6969     */
    7070    protected $from = null;
     
    102102     * @since 2.5.0
    103103     *
    104      * @var BP_Email_Recipient "Reply to" details.
     104     * @var BP_Email_Sender "Reply to" details.
    105105     */
    106106    protected $reply_to = null;
     
    431431     * @param string $transform Optional. How to transform the return value.
    432432     *                          Accepts 'raw' (default) or 'replace-tokens'.
    433      * @return BP_Email_Recipient "From" recipient.
     433     * @return BP_Email_Sender "From" recipient.
    434434     */
    435435    public function get_from( $transform = 'raw' ) {
     
    739739     */
    740740    public function set_from( $email_address, $name = '' ) {
    741         $from = new BP_Email_Recipient( $email_address, $name );
     741        $from = new BP_Email_Sender();
     742
     743        $from->set_address( $email_address );
     744        $from->set_name( $name );
    742745
    743746        /**
     
    811814     */
    812815    public function set_reply_to( $email_address, $name = '' ) {
    813         $reply_to = new BP_Email_Recipient( $email_address, $name );
     816        $reply_to = new BP_Email_Sender();
     817
     818        $reply_to->set_address( $email_address );
     819        $reply_to->set_name( $name );
    814820
    815821        /**
  • trunk/src/class-buddypress.php

    r12309 r12353  
    556556            'BP_Date_Query'                => 'core',
    557557            'BP_Email_Delivery'            => 'core',
     558            'BP_Email_Address'             => 'core',
    558559            'BP_Email_Recipient'           => 'core',
     560            'BP_Email_Sender'              => 'core',
     561            'BP_Email_Participant'         => 'core',
    559562            'BP_Email'                     => 'core',
    560563            'BP_Embed'                     => 'core',
Note: See TracChangeset for help on using the changeset viewer.