forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Users: remove unnecessary writes to the database for use_ssl user meta.
When checking for updates to use_ssl, use strings for the comparison values, matching the stored values. Fixes an issue where calls to wp_update_user updated the database meta value for use_ssl even when the value was missing or unchanged. Props prettyboymp, rajinsharwar, adamsilverstein, johnbillion, rayhatron, mukesh27, joemcgill. Fixes #60299. git-svn-id: https://develop.svn.wordpress.org/trunk@59216 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
f12827a
commit dfe7c18
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2245,4 +2245,46 @@ public function export_additional_user_profile_data_with_dup_name() { | |
|
||
return $additional_profile_data; | ||
} | ||
|
||
/** | ||
* Test that update_user_meta for 'use_ssl' doesn't write to DB unnecessarily. | ||
* | ||
* @ticket 60299 | ||
*/ | ||
public function test_unnecessary_assignment_of_use_ssl_in_meta() { | ||
$user_id = self::$contrib_id; | ||
// Keep track of db writing calls. | ||
$set_db_counts = 0; | ||
|
||
// Track db updates with calls to do_action( "update_user_meta", ... with 'use_ssl' meta key. | ||
add_action( | ||
'update_user_meta', | ||
function ( $meta_id, $object_id, $meta_key ) use ( &$set_db_counts ) { | ||
if ( 'use_ssl' !== $meta_key ) { | ||
return; | ||
} | ||
$set_db_counts++; | ||
}, | ||
10, | ||
3 | ||
); | ||
|
||
$_POST = array( | ||
'nickname' => 'nickname_test', | ||
'email' => '[email protected]', | ||
'use_ssl' => 1, | ||
); | ||
|
||
$user_id = edit_user( $user_id ); | ||
|
||
$this->assertIsInt( $user_id ); | ||
$this->assertEquals( 1, $set_db_counts ); | ||
|
||
// Update the user without changing the 'use_ssl' meta. | ||
$_POST['email'] = '[email protected]'; | ||
$user_id = edit_user( $user_id ); | ||
|
||
// Verify there are no updates to use_ssl user meta. | ||
$this->assertEquals( 1, $set_db_counts ); | ||
} | ||
} |