Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mehul0810/cc416a47158045dc34431ba42da46ec6 to your computer and use it in GitHub Desktop.
Save mehul0810/cc416a47158045dc34431ba42da46ec6 to your computer and use it in GitHub Desktop.
<?php
/**
* This code snippet will help you update the email address on donor as well as WP user profiles when donor updates the email address
* using legacy donor profile `[give_profile_editor]`.
*
* @param int $user_id WP User ID.
* @param array $userdata WP User data.
*
* @return void
*/
function custom_prefix_update_donor_email( $user_id, $userdata ) {
// Get GiveWP donor data.
$donor = new Give_Donor( $user_id, true );
// Update email to donor profile only if the email in donor profile doesn't match with the submitted one.
if ( $userdata['user_email'] !== $donor->email ) {
$donor->update( [
'email' => $userdata['user_email'],
] );
}
}
add_action( 'give_user_profile_updated', 'custom_prefix_update_donor_email', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment