Ticket #8003: 8003.diff
File 8003.diff, 8.3 KB (added by , 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 8 interface 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 8 abstract 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; 14 14 * 15 15 * @since 2.5.0 16 16 */ 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 = ''; 17 class BP_Email_Recipient extends BP_Email_Person { 36 18 37 19 /** 38 20 * Optional. A `WP_User` object relating to this recipient. … … class BP_Email_Recipient { 88 70 89 71 // Set address if we have one. 90 72 if ( ! empty( $address ) ) { 91 $this-> address = sanitize_email( $address);73 $this->set_address( sanitize_email( $address ) ); 92 74 } 93 75 94 76 // Still no user object; try to query user by email address. … … class BP_Email_Recipient { 101 83 // This is escaped with esc_html in bp_core_get_user_displayname() 102 84 $wp_name = wp_specialchars_decode( bp_core_get_user_displayname( $this->user_object->ID ), ENT_QUOTES ); 103 85 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 ); 106 88 107 89 } 108 90 109 91 // Custom name override. 110 92 if ( $name ) { 111 $this-> name = $name;93 $this->set_name( $name ); 112 94 } 113 95 114 96 /** … … class BP_Email_Recipient { 132 114 * @return string 133 115 */ 134 116 public function get_address() { 117 $address = parent::get_address(); 135 118 136 119 /** 137 120 * Filters the recipient's address before it's returned. 138 121 * 139 122 * @since 2.5.0 140 123 * 141 * @param string $addressRecipient's address.142 * @param BP_Email $recipient $thisCurrent 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. 143 126 */ 144 return apply_filters( 'bp_email_recipient_get_address', $ this->address, $this );127 return apply_filters( 'bp_email_recipient_get_address', $address, $this ); 145 128 } 146 129 147 130 /** … … class BP_Email_Recipient { 152 135 * @return string 153 136 */ 154 137 public function get_name() { 138 $name = parent::get_name(); 155 139 156 140 /** 157 141 * Filters the recipient's name before it's returned. 158 142 * 159 143 * @since 2.5.0 160 144 * 161 * @param string $nameRecipient's name.162 * @param BP_Email $recipient $thisCurrent 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. 163 147 */ 164 return apply_filters( 'bp_email_recipient_get_name', $ this->name, $this );148 return apply_filters( 'bp_email_recipient_get_name', $name, $this ); 165 149 } 166 150 167 151 /** -
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 8 class 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 { 65 65 * 66 66 * @since 2.5.0 67 67 * 68 * @var BP_Email_ RecipientSender details.68 * @var BP_Email_Sender Sender details. 69 69 */ 70 70 protected $from = null; 71 71 … … class BP_Email { 101 101 * 102 102 * @since 2.5.0 103 103 * 104 * @var BP_Email_ Recipient"Reply to" details.104 * @var BP_Email_Sender "Reply to" details. 105 105 */ 106 106 protected $reply_to = null; 107 107 … … class BP_Email { 430 430 * 431 431 * @param string $transform Optional. How to transform the return value. 432 432 * Accepts 'raw' (default) or 'replace-tokens'. 433 * @return BP_Email_ Recipient"From" recipient.433 * @return BP_Email_Sender "From" recipient. 434 434 */ 435 435 public function get_from( $transform = 'raw' ) { 436 436 return $this->get( 'from', $transform ); … … class BP_Email { 738 738 * @return BP_Email 739 739 */ 740 740 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 ); 742 745 743 746 /** 744 747 * Filters the new value of the email's "from" property. … … class BP_Email { 810 813 * @return BP_Email 811 814 */ 812 815 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 ); 814 820 815 821 /** 816 822 * 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 { 555 555 'BP_Customizer_Control_Range' => 'core', 556 556 'BP_Date_Query' => 'core', 557 557 'BP_Email_Delivery' => 'core', 558 'BP_Email_Address' => 'core', 558 559 'BP_Email_Recipient' => 'core', 560 'BP_Email_Sender' => 'core', 561 'BP_Email_Person' => 'core', 559 562 'BP_Email' => 'core', 560 563 'BP_Embed' => 'core', 561 564 'BP_Media_Extractor' => 'core',