• Resolved limearts

    (@limearts)


    Hello,

    im new to development with wordpress API and stuck. In one Installation are some plugins where used, that store data not in a user-specific id, but in an emailadress set when saving the settings for the first time.

    When users changing their email-address, some of these plugins can’t get their saved data because they’re simply can’t find the “new” email.

    No big deal i thought. Just update the plugins data with an sql update, at the time the user is changing the saved address. But i can’t find the right hook to update the data with $old_email and $new_email. I think it must be hooked at the moment, a user is loading the url from send_confirmation_on_profile_email? But what is the hook for this savestate?

    • This topic was modified 2 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 2 replies - 1 through 2 (of 2 total)
  • You can try this filter hook email_change_email. It will help you sure.

    function filter_email_change_email( $email_change_email, $user, $userdata ) { 
        // make filter magic happen here... 
        return $email_change_email; 
    }; 
             
    // add the filter 
    add_filter( 'email_change_email', 'filter_email_change_email', 10, 3 );

    —————— OR ——————

    function wpdocs_check_user_email_updated( $user_id, $old_user_data ) {
        $old_user_email = $old_user_data->data->user_email;
     
        $user = get_userdata( $user_id );
        $new_user_email = $user->user_email;
     
        if ( $new_user_email !== $old_user_email ) {
            // Do something if old and new email aren't the same
        }
    }
    add_action( 'profile_update', 'wpdocs_check_user_email_updated', 10, 2 );
    • This reply was modified 2 years, 5 months ago by mdshak.
    Thread Starter limearts

    (@limearts)

    Thanks a lot mdshak!

    Yes the second snippet did the job. It was one of the first codes i used days before, but a simple error mislead me to a longer, more complex journey than necessary.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hook for user when changing their email’ is closed to new replies.