bp_settings_verify_email_change()

Process email change verification or cancel requests.

Description

Source

File: bp-settings/actions/general.php

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
function bp_settings_verify_email_change() {
    if ( ! bp_is_settings_component() ) {
        return;
    }
 
    if ( ! bp_is_my_profile() ) {
        return;
    }
 
    $redirect_to = trailingslashit( bp_displayed_user_domain() . bp_get_settings_slug() );
 
    // Email change is being verified.
    if ( isset( $_GET['verify_email_change'] ) ) {
        $pending_email = bp_get_user_meta( bp_displayed_user_id(), 'pending_email_change', true );
 
        // Bail if the hash provided doesn't match the one saved in the database.
        if ( ! hash_equals( urldecode( $_GET['verify_email_change'] ), $pending_email['hash'] ) ) {
            return;
        }
 
        $email_changed = wp_update_user( array(
            'ID'         => bp_displayed_user_id(),
            'user_email' => trim( $pending_email['newemail'] ),
        ) );
 
        if ( $email_changed ) {
 
            // Delete the pending email change key.
            bp_delete_user_meta( bp_displayed_user_id(), 'pending_email_change' );
 
            // Post a success message and redirect.
            bp_core_add_message( __( 'You have successfully verified your new email address.', 'buddyboss' ) );
        } else {
            // Unknown error.
            bp_core_add_message( __( 'There was a problem verifying your new email address. Please try again.', 'buddyboss' ), 'error' );
        }
 
        bp_core_redirect( $redirect_to );
        die();
 
    // Email change is being dismissed.
    } elseif ( ! empty( $_GET['dismiss_email_change'] ) ) {
        $nonce_check = isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'bp_dismiss_email_change' );
 
        if ( $nonce_check ) {
            bp_delete_user_meta( bp_displayed_user_id(), 'pending_email_change' );
            bp_core_add_message( __( 'You have successfully dismissed your pending email change.', 'buddyboss' ) );
        }
 
        bp_core_redirect( $redirect_to );
        die();
    }
}

Changelog

Changelog
Version Description
BuddyPress 2.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.