Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/13/2019 09:25:05 PM (5 years ago)
Author:
johnjamesjacoby
Message:

Users: move _new_email from options to usermeta.

This commit brings bbPress up-to-date with how WordPress tracks changes to email addresses. It includes a small bit of styling to add emphasis to the email address inside the standard notice wrapper.

See #3306. For 2.6.4, branches/2.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/2.6/src/includes/users/functions.php

    r6866 r7031  
    229229
    230230        // Update the option
    231         $key    = $user_id . '_new_email';
    232         $hash   = md5( $_POST['email'] . time() . mt_rand() );
    233231        $option = array(
    234             'hash'     => $hash,
    235             'newemail' => $_POST['email']
     232            'hash'     => md5( $_POST['email'] . time() . wp_rand() ),
     233            'newemail' => $_POST['email'],
    236234        );
    237         update_option( $key, $option );
     235        update_user_meta( $user_id, '_new_email', $option );
    238236
    239237        // Attempt to notify the user of email address change
     
    315313    // Get the displayed user ID & option key
    316314    $user_id     = bbp_get_displayed_user_id();
    317     $key         = $user_id . '_new_email';
     315    $key         = '_new_email';
    318316    $redirect_to = bbp_get_user_profile_edit_url( $user_id );
    319317
     
    322320
    323321        // Check for email address change option
    324         $new_email = get_option( $key );
     322        $new_email = get_user_meta( $user_id, $key, true );
    325323
    326324        // Redirect if *no* email address change exists
     
    331329        // Cleanup & redirect if *invalid* email address change exists
    332330        if ( empty( $new_email['hash'] ) || empty( $new_email['newemail'] ) ) {
    333             delete_option( $key );
     331            delete_user_meta( $user_id, $key );
    334332
    335333            bbp_redirect( $redirect_to );
     
    341339            // Does another user have this email address already?
    342340            if ( email_exists( $new_email['newemail'] ) ) {
    343                 delete_option( $key );
     341                delete_user_meta( $user_id, $key );
    344342
    345343                bbp_add_error( 'bbp_user_email_taken', __( '<strong>ERROR</strong>: That email address is already in use.', 'bbpress' ), array( 'form-field' => 'email' ) );
     
    370368                    }
    371369
    372                     delete_option( $key );
     370                    delete_user_meta( $user_id, $key );
    373371
    374372                    bbp_redirect( add_query_arg( array( 'updated' => 'true' ), $redirect_to ) );
     
    378376
    379377    // Delete new email address from user options
    380     } elseif ( ! empty( $_GET['dismiss'] ) && ( $key === $_GET['dismiss'] ) ) {
    381         if ( ! bbp_verify_nonce_request( "dismiss-{$key}" ) ) {
     378    } elseif ( ! empty( $_GET['dismiss'] ) && ( "{$user_id}{$key}" === $_GET['dismiss'] ) ) {
     379        if ( ! bbp_verify_nonce_request( "dismiss-{$user_id}{$key}" ) ) {
    382380            bbp_add_error( 'bbp_dismiss_new_email_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
    383381            return;
    384382        }
    385383
    386         delete_option( $key );
     384        delete_user_meta( $user_id, $key );
    387385        bbp_redirect( $redirect_to );
    388386    }
Note: See TracChangeset for help on using the changeset viewer.