benecaster_email_changed
Fires after a subscriber’s requested email address change has been verified and written to wp_users.user_email, from AccountController::verify_email().
⚠ Fires on the VERIFIED change only. Requesting a change — saving a new address on the benecaster_account PROFILE section — fires nothing, because the address is unproven at that point. A callback that syncs it to a mailing list or CRM must hook this action, not the request; syncing on request would sync whatever the subscriber mistyped, before they have even proven they can receive mail at it.
Sync a verified email change to your CRM
Keep an external list in step with a subscriber’s email address, using benecaster_email_changed.
Signature: benecaster_email_changed( int $user_id, string $old_email, string $new_email ). Free, never licence-gated.
It fires on the VERIFIED change only, and that is the reason to use it rather than watching profile_update. A subscriber who edits the Email address field on their account page changes nothing yet: the new address gets a single-use link, and wp_users.user_email is untouched until that link is used. A listener that fired on the request would push whatever the subscriber mistyped to your CRM and then have to undo it.
You get the old address as well as the new one, so you can update a record keyed on the old address rather than creating a duplicate.
Nothing else in the plugin writes the address this way, so a change arriving through wp-admin or through wp_update_user() does not fire it. If you need every route, hook WordPress’s own profile_update too and treat this as the subscriber-initiated case.
<?php
add_action(
'benecaster_email_changed',
function ( int $user_id, string $old_email, string $new_email ): void {
// Cheap: the hook fires inside the verification request, which is a
// browser redirect the subscriber is waiting on.
wp_schedule_single_event(
time() + 10,
'my_addon_sync_contact',
[ $user_id, $old_email, $new_email ]
);
},
10,
3
);
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$user_id |
int |
— | WordPress user ID of the subscriber |
$old_email |
string |
— | The address the account had until now |
$new_email |
string |
— | The verified address now on the account |
Example
add_action( 'benecaster_email_changed', function ( int $user_id, string $old_email, string $new_email ): void {
my_crm_update_contact_email( $user_id, $old_email, $new_email );
}, 10, 3 );
Notes
To customize the link mailed to the subscriber before it is clicked, see the benecaster_email_verification_url filter, which fires at request time rather than at verification.
[benecaster_recipe name="sync-a-verified-email-change-to-your-crm"]
Affects
- Subscriber Account Page
Need this built rather than just documented? See our services →