Changeset 12903
- Timestamp:
- 04/21/2021 07:10:20 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-optout.php
r12898 r12903 213 213 protected static function _insert( $data = array(), $data_format = array() ) { 214 214 global $wpdb; 215 // We must hash the email address at insert. 216 $data['email_address_hash'] = wp_hash( $data['email_address_hash'] ); 215 // We must lowercase and hash the email address at insert. 216 $email = strtolower( $data['email_address_hash'] ); 217 $data['email_address_hash'] = wp_hash( $email ); 217 218 return $wpdb->insert( BP_Optout::get_table_name(), $data, $data_format ); 218 219 } … … 238 239 global $wpdb; 239 240 240 // Ensure that a passed email address is hashed.241 // Ensure that a passed email address is lowercased and hashed. 241 242 if ( ! empty( $data['email_address_hash'] ) && is_email( $data['email_address_hash'] ) ) { 242 $data['email_address_hash'] = wp_hash( $data['email_address_hash'] ); 243 $email = strtolower( $data['email_address_hash'] ); 244 $data['email_address_hash'] = wp_hash( $email ); 243 245 } 244 246 … … 297 299 $email_clean = array(); 298 300 foreach ( $emails as $email ) { 301 $email = strtolower( $email ); 299 302 $email_hash = wp_hash( $email ); 300 303 $email_clean[] = $wpdb->prepare( '%s', $email_hash ); … … 331 334 if ( ! empty( $args['search_terms'] ) ) { 332 335 // Matching email_address is an exact match because of the hashing. 336 $args['search_terms'] = strtolower( $args['search_terms'] ); 333 337 $search_terms_like = wp_hash( $args['search_terms'] ); 334 338 $where_conditions['search_terms'] = $wpdb->prepare( '( email_address_hash LIKE %s )', $search_terms_like ); -
trunk/tests/phpunit/testcases/core/optouts.php
r12898 r12903 101 101 } 102 102 103 public function test_bp_optouts_get_by_email_address_mismatched_case() { 104 $old_current_user = get_current_user_id(); 105 106 $u1 = $this->factory->user->create(); 107 $this->set_current_user( $u1 ); 108 109 // Create a couple of optouts. 110 $args = array( 111 'email_address' => 'ONE@wpfrost.org', 112 'user_id' => $u1, 113 'email_type' => 'annoyance' 114 ); 115 $i1 = bp_add_optout( $args ); 116 $args['email_address'] = 'two@WP.org'; 117 $i2 = bp_add_optout( $args ); 118 119 $get_args = array( 120 'email_address' => 'one@WPfrost.org', 121 'fields' => 'ids', 122 ); 123 $optouts = bp_get_optouts( $get_args ); 124 $this->assertEqualSets( array( $i1 ), $optouts ); 125 126 $this->set_current_user( $old_current_user ); 127 } 128 129 public function test_bp_optouts_get_by_search_terms_mismatched_case() { 130 $old_current_user = get_current_user_id(); 131 132 $u1 = $this->factory->user->create(); 133 $this->set_current_user( $u1 ); 134 135 // Create a couple of optouts. 136 $args = array( 137 'email_address' => 'ONE@wpfrost.org', 138 'user_id' => $u1, 139 'email_type' => 'annoyance' 140 ); 141 $i1 = bp_add_optout( $args ); 142 $args['email_address'] = 'two@WP.org'; 143 $i2 = bp_add_optout( $args ); 144 145 $get_args = array( 146 'search_terms' => 'one@wpfrost.org', 147 'fields' => 'ids', 148 ); 149 $optouts = bp_get_optouts( $get_args ); 150 $this->assertEqualSets( array( $i1 ), $optouts ); 151 152 $this->set_current_user( $old_current_user ); 153 } 154 155 156 public function test_bp_optouts_get_by_email_address_mismatched_case_after_update() { 157 $old_current_user = get_current_user_id(); 158 159 $u1 = $this->factory->user->create(); 160 $this->set_current_user( $u1 ); 161 162 // Create an opt-out. 163 $args = array( 164 'email_address' => 'ONE@wpfrost.org', 165 'user_id' => $u1, 166 'email_type' => 'annoyance' 167 ); 168 $i1 = bp_add_optout( $args ); 169 // Update it. 170 $oo_class = new BP_Optout( $i1 ); 171 $oo_class->email_address = 'One@wpFrost.org'; 172 $oo_class->save(); 173 174 $get_args = array( 175 'email_address' => 'one@WPfrost.org', 176 'fields' => 'ids', 177 ); 178 $optouts = bp_get_optouts( $get_args ); 179 $this->assertEqualSets( array( $i1 ), $optouts ); 180 181 $this->set_current_user( $old_current_user ); 182 } 183 103 184 }
Note: See TracChangeset
for help on using the changeset viewer.