Ticket #20043: 20043.diff
File 20043.diff, 2.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-user.php
313 313 } 314 314 315 315 /** 316 * Magic method for unsetting a certain custom field 317 * 318 * @since 4.4.0 319 */ 320 function __unset( $key ) { 321 if ( 'id' == $key ) { 322 _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) ); 323 $key = 'ID'; 324 } 325 326 if ( isset( $this->data->$key ) ) { 327 unset( $this->data->$key ); 328 } 329 330 if ( isset( self::$back_compat_keys[ $key ] ) ) { 331 unset( self::$back_compat_keys[ $key ] ); 332 } 333 } 334 335 /** 316 336 * Determine whether the user exists in the database. 317 337 * 318 338 * @since 3.4.0 -
tests/phpunit/tests/user.php
162 162 } 163 163 } 164 164 165 /** 166 * Test the magic __unset method 167 * 168 * @ticket 20043 169 */ 170 public function test_user_unset() { 171 // New user 172 $user_id = $this->factory->user->create( array( 'role' => 'author' ) ); 173 $user = new WP_User( $user_id ); 174 175 // Test custom fields 176 $user->customField = 123; 177 $this->assertEquals( $user->customField, 123 ); 178 unset( $user->customField ); 179 $this->assertFalse( isset( $user->customField ) ); 180 return $user; 181 } 182 183 /** 184 * @depends test_user_unset 185 * @expectedDeprecated WP_User->id 186 * @ticket 20043 187 */ 188 function test_user_unset_lowercase_id( $user ) { 189 // Test 'id' (lowercase) 190 unset( $user->id ); 191 return $user; 192 } 193 194 /** 195 * @depends test_user_unset_lowercase_id 196 * @ticket 20043 197 */ 198 function test_user_unset_uppercase_id( $user ) { 199 // Test 'ID' 200 $this->assertNotEmpty( $user->ID ); 201 unset( $user->ID ); 202 $this->assertEmpty( $user->ID ); 203 } 204 165 205 // Test meta property magic functions for property get/set/isset. 166 206 function test_user_meta_properties() { 167 207 global $wpdb;