Changeset 34380
- Timestamp:
- 09/22/2015 04:59:35 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user.php
r34379 r34380 326 326 327 327 /** 328 * Magic method for unsetting a certain custom field 329 * 330 * @since 4.4.0 331 */ 332 function __unset( $key ) { 333 if ( 'id' == $key ) { 334 _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) ); 335 $key = 'ID'; 336 } 337 338 if ( isset( $this->data->$key ) ) { 339 unset( $this->data->$key ); 340 } 341 342 if ( isset( self::$back_compat_keys[ $key ] ) ) { 343 unset( self::$back_compat_keys[ $key ] ); 344 } 345 } 346 347 /** 328 348 * Determine whether the user exists in the database. 329 349 * -
trunk/tests/phpunit/tests/user.php
r34218 r34380 161 161 $this->assertEquals( $value, $user->$key ); 162 162 } 163 } 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 ); 163 203 } 164 204
Note: See TracChangeset
for help on using the changeset viewer.