Skip to content

Users: Update the edited user's row in signups when changing their email. - #15132

Open
erycson wants to merge 5 commits into
WordPress:trunkfrom
erycson:fix/26805-signups-email-update
Open

erycson wants to merge 5 commits into
WordPress:trunkfrom
erycson:fix/26805-signups-email-update

Conversation

@erycson

@erycson erycson commented Oct 29, 2026

Copy link
Copy Markdown

On multisite, user-edit.php updates wp_signups with $user_login, which is
not set in that scope. In wp-admin it holds the current user's login (set by
setup_userdata() via wp_set_current_user()), so when an admin who has a
signups row edits another user's email, the new address is written into the
admin's row and the edited user's row is left unchanged. If the admin has no
signups row, nothing is updated (as noted in Trac comment:16).

This uses $user->user_login, and unslashes the posted email before
is_email() so addresses with an apostrophe are accepted. Same change as
attachment 26805.fix.diff by boonebgorges.

Tested on a local 7.1.4 multisite (subdirectory): before the change, saving
user2's profile as admin1 changed admin1's signups row; after it, user2's row
is updated and admin1's is untouched.

Trac ticket: https://core.trac.wordpress.org/ticket/26805

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code, with code-intruder (my own static analysis tool)
Model(s): Claude Opus, Claude Haiku
Used for: code-intruder flagged the call path and an AI review noticed the
undefined $user_login. AI helped confirm the behavior on a local multisite
install (real POST to user-edit.php, checking wp_signups before/after) and
check the existing patch. I reviewed and tested the change myself.


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.

…ail.

On multisite, `user-edit.php` updated `wp_signups` using `$user_login`,
which is not set in that scope. In wp-admin it holds the current user's
login (set by `setup_userdata()`), so editing another user's email wrote
the new address into the editor's signups row instead of the edited
user's. Use `$user->user_login`, and unslash the posted email before
validating it so addresses with an apostrophe are accepted.

See #26805.
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props extremsx, huzaifaalmesbah.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up, @erycson! I left a small note inline.

AI Review: Opus 5.5

Comment thread src/wp-admin/user-edit.php Outdated
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['email'], $user_login ) );
$email = isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '';

if ( $user->user_login && $email && is_email( $email ) && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_login ) ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks like a small gap: the update still runs before edit_user() validates the request. If I enter an email that another account already uses, the edit is rejected with email_exists, but it looks like that email would still be written to this user's signups row.

What do you think about moving it into the ! is_wp_error( $errors ) branch further down and using the saved values?

if ( ! is_wp_error( $errors ) ) {
	// Update the email address in signups, if present.
	if ( is_multisite() ) {
		$user = get_userdata( $user_id );

		$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $user->user_login ) );
	}

This also covers the apostrophe case without reading $_POST, and the SELECT can go, since an UPDATE with no matching row does nothing. I tried this placement on multisite with accepted, rejected and apostrophe edits, and the rows stayed consistent: commit.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! You're right, the update ran before edit_user() validated the request, so a rejected email could still end up in the signups row. I've moved it into the ! is_wp_error( $errors ) branch and switched to the saved values as you suggested, which also lets the SELECT and the $_POST read go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants