Stop get_password_reset_key() from firing profile_update#12651
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
This PR changes how WordPress persists user_activation_key during password reset / activation key generation so that internal key rotation no longer routes through wp_update_user()/wp_insert_user() and unintentionally fires profile_update for non-profile changes (notably during new user registration flows).
Changes:
- Update
get_password_reset_key()to writeuser_activation_keydirectly via$wpdb->update()and clear user cache. - Add PHPUnit regression tests ensuring
get_password_reset_key()andregister_new_user()do not fireprofile_updatein these flows (while preserving expecteduser_registerbehavior).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/wp-includes/user.php |
Bypasses wp_update_user() when saving user_activation_key to prevent unintended profile_update firing. |
tests/phpunit/tests/user.php |
Adds regression tests to ensure the corrected action-firing behavior and key persistence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $wpdb->update( | ||
| $wpdb->users, | ||
| array( 'user_activation_key' => $hashed ), | ||
| array( 'ID' => $user->ID ) | ||
| ); |
| $updated_user = get_userdata( $user->ID ); | ||
| $this->assertNotEmpty( $updated_user->user_activation_key, 'The user_activation_key should have been persisted.' ); | ||
| } |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
register_new_user()and thewp-login.php?action=lostpasswordflow both callget_password_reset_key()to generate an account-activation / password-reset link. That function saved the internaluser_activation_keycolumn viawp_update_user(), which routes throughwp_insert_user()and unconditionally firesprofile_update— even though nothing about the user's profile actually changed. Since[45714](#45746), this means every brand-new account registration also firesprofile_update, which breaks the long-standing distinction betweenuser_register(a new account) andprofile_update(an existing user editing their own profile) that plugins such as BuddyPress, bbPress, and Easy Digital Downloads rely on for user-facing profile-update integrations.This updates
get_password_reset_key()to writeuser_activation_keydirectly via$wpdb->update()plusclean_user_cache(), the same narrow patternwp_set_password()already uses for its own single-column write, instead of going through the fullwp_insert_user()path. This preserves the cache-consistency fix from[45714]while no longer firingprofile_update(or any of the meta/role writeswp_insert_user()would otherwise perform) for what is only an internal key rotation.Adds two regression tests to
tests/phpunit/tests/user.php: one assertingget_password_reset_key()no longer firesprofile_update(while still persistinguser_activation_key), and one assertingregister_new_user()still firesuser_registerexactly once but no longer firesprofile_update. Both fail on current trunk and pass with this fix. Fulluser(1343 tests) andauth(143 tests) PHPUnit groups pass with no regressions; PHPCS and PHPStan are clean.Trac ticket: https://core.trac.wordpress.org/ticket/62996
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Root cause analysis, implementation, test coverage, and verification. Reviewed and directed by me throughout.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.