Skip to:
Content

BuddyPress.org

Ticket #8003: 8003.diff

File 8003.diff, 8.3 KB (added by boonebgorges, 6 years ago)
  • new file src/bp-core/classes/class-bp-email-address.php

    diff --git a/src/bp-core/classes/class-bp-email-address.php b/src/bp-core/classes/class-bp-email-address.php
    new file mode 100644
    index 000000000..2340cc42b
    - +  
     1<?php
     2/**
     3 * Interface for objects that have email address properties (address, name).
     4 *
     5 * @since 5.0.0
     6 */
     7
     8interface BP_Email_Address {
     9        /**
     10         * Gets the email address of the user.
     11         *
     12         * @since 5.0.0
     13         */
     14        public function get_address();
     15
     16        /**
     17         * Gets the display name of the user.
     18         *
     19         * @since 5.0.0
     20         */
     21        public function get_name();
     22
     23        /**
     24         * Sets the email address of the user.
     25         *
     26         * @since 5.0.0
     27         *
     28         * @param string $email_address Email address.
     29         */
     30        public function set_address( $email_address );
     31
     32        /**
     33         * Sets the name of the user.
     34         *
     35         * @since 5.0.0
     36         *
     37         * @param string $name Name.
     38         */
     39        public function set_name( $name );
     40}
  • new file src/bp-core/classes/class-bp-email-person.php

    diff --git a/src/bp-core/classes/class-bp-email-person.php b/src/bp-core/classes/class-bp-email-person.php
    new file mode 100644
    index 000000000..554507318
    - +  
     1<?php
     2/**
     3 * Base class for email "persons" (recipient, sender, Reply-To, etc).
     4 *
     5 * @since 5.0.0
     6 */
     7
     8abstract class BP_Email_Person implements BP_Email_Address {
     9        /**
     10         * Recipient's email address.
     11         *
     12         * @since 5.0.0
     13         *
     14         * @var string
     15         */
     16        protected $address = '';
     17
     18        /**
     19         * Recipient's name.
     20         *
     21         * @since 5.0.0
     22         *
     23         * @var string
     24         */
     25        protected $name = '';
     26
     27        /**
     28         * Gets the email address of the user.
     29         *
     30         * @since 5.0.0
     31         */
     32        public function get_address() {
     33                /**
     34                 * Filters an email user's address before it's returned.
     35                 *
     36                 * @since 5.0.0
     37                 *
     38                 * @param string        $address User's address.
     39                 * @param BP_Email_User $user    Current instance of the email user class.
     40                 */
     41                return apply_filters( 'bp_email_user_get_address', $this->address, $this );
     42        }
     43
     44        /**
     45         * Gets the email name of the user.
     46         *
     47         * @since 5.0.0
     48         *
     49         * @return string
     50         */
     51        public function get_name() {
     52                /**
     53                 * Filters an email user's name before it's returned.
     54                 *
     55                 * @since 5.0.0
     56                 *
     57                 * @param string        $name Recipient's name.
     58                 * @param BP_Email_User $user Current instance of the email user class.
     59                 */
     60                return apply_filters( 'bp_email_recipient_get_name', $this->name, $this );
     61        }
     62
     63        /**
     64         * Sets the email address of the user.
     65         *
     66         * @since 5.0.0
     67         *
     68         * @param string $email_address Email address.
     69         */
     70        public function set_address( $email_address ) {
     71                $this->address = $email_address;
     72        }
     73
     74        /**
     75         * Sets the name of the user.
     76         *
     77         * @since 5.0.0
     78         *
     79         * @param string $name Name.
     80         */
     81        public function set_name( $name ) {
     82                $this->name = $name;
     83        }
     84}
  • src/bp-core/classes/class-bp-email-recipient.php

    diff --git a/src/bp-core/classes/class-bp-email-recipient.php b/src/bp-core/classes/class-bp-email-recipient.php
    index 4cc17c4de..a22e10dda 100644
    a b defined( 'ABSPATH' ) || exit; 
    1414 *
    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_Person {
    3618
    3719        /**
    3820         * Optional. A `WP_User` object relating to this recipient.
    class BP_Email_Recipient { 
    8870
    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
    9476                // Still no user object; try to query user by email address.
    class BP_Email_Recipient { 
    10183                        // This is escaped with esc_html in bp_core_get_user_displayname()
    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                }
    10890
    10991                // Custom name override.
    11092                if ( $name ) {
    111                         $this->name = $name;
     93                        $this->set_name( $name );
    11294                }
    11395
    11496                /**
    class BP_Email_Recipient { 
    132114         * @return string
    133115         */
    134116        public function get_address() {
     117                $address = parent::get_address();
    135118
    136119                /**
    137120                 * Filters the recipient's address before it's returned.
    138121                 *
    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
    147130        /**
    class BP_Email_Recipient { 
    152135         * @return string
    153136         */
    154137        public function get_name() {
     138                $name = parent::get_name();
    155139
    156140                /**
    157141                 * Filters the recipient's name before it's returned.
    158142                 *
    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
    167151        /**
  • new file src/bp-core/classes/class-bp-email-sender.php

    diff --git a/src/bp-core/classes/class-bp-email-sender.php b/src/bp-core/classes/class-bp-email-sender.php
    new file mode 100644
    index 000000000..f4fcfaab6
    - +  
     1<?php
     2/**
     3 * Email sender object (From, Reply-To).
     4 *
     5 * @since 5.0.0
     6 */
     7
     8class BP_Email_Sender extends BP_Email_Person {}
  • src/bp-core/classes/class-bp-email.php

    diff --git a/src/bp-core/classes/class-bp-email.php b/src/bp-core/classes/class-bp-email.php
    index 9112bc8c0..78188fe4e 100644
    a b class BP_Email { 
    6565         *
    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;
    7171
    class BP_Email { 
    101101         *
    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;
    107107
    class BP_Email { 
    430430         *
    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' ) {
    436436                return $this->get( 'from', $transform );
    class BP_Email { 
    738738         * @return BP_Email
    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                /**
    744747                 * Filters the new value of the email's "from" property.
    class BP_Email { 
    810813         * @return BP_Email
    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                /**
    816822                 * Filters the new value of the email's "reply to" property.
  • src/class-buddypress.php

    diff --git a/src/class-buddypress.php b/src/class-buddypress.php
    index 0aba05988..e04620019 100644
    a b class BuddyPress { 
    555555                        'BP_Customizer_Control_Range'  => 'core',
    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_Person'              => 'core',
    559562                        'BP_Email'                     => 'core',
    560563                        'BP_Embed'                     => 'core',
    561564                        'BP_Media_Extractor'           => 'core',