Skip to:
Content

BuddyPress.org

Changeset 13044


Ignore:
Timestamp:
08/13/2021 01:21:09 PM (2 months ago)
Author:
imath
Message:

Settings: do not try to validate a dismissed email change

If a user clicks on the link to verify and validate an email change he previously dismissed, we need to show him an error feedback instead of trying (and failing) to validate a dismissed email change.

Doing so is also avoiding errors with PHP8.

Props nunks

Fixes #8538 (branch 9.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/9.0/src/bp-settings/actions/general.php

    r13031 r13044  
    246246    // Email change is being verified.
    247247    if ( isset( $_GET['verify_email_change'] ) ) {
    248         $pending_email = bp_get_user_meta( bp_displayed_user_id(), 'pending_email_change', true );
     248        $user_id       = bp_displayed_user_id();
     249        $pending_email = (array) bp_get_user_meta( $user_id, 'pending_email_change', true );
     250
     251        // The user may have dismissed the email change.
     252        if ( ! array_filter( $pending_email ) ) {
     253            /**
     254             * Fires when a Pending Email Change is missing and before
     255             * BuddyPress redirects the user to an error message.
     256             *
     257             * @since 9.1.0
     258             *
     259             * @param int    $user_id     The user ID.
     260             * @param string $redirect_to The Default Front-end Settings Screen URL.
     261             */
     262            do_action( 'bp_settings_missing_pending_email_change_hash', $user_id, $redirect_to );
     263
     264            bp_core_add_message( __( 'There was a problem verifying your new email address. If you haven’t dismissed the pending email change, please request a new email update.', 'buddypress' ), 'error' );
     265            bp_core_redirect( $redirect_to );
     266        }
    249267
    250268        // Bail if the hash provided doesn't match the one saved in the database.
     
    254272
    255273        $email_changed = wp_update_user( array(
    256             'ID'         => bp_displayed_user_id(),
     274            'ID'         => $user_id,
    257275            'user_email' => trim( $pending_email['newemail'] ),
    258276        ) );
    259277
    260278        if ( $email_changed ) {
    261 
    262279            // Delete the pending email change key.
    263             bp_delete_user_meta( bp_displayed_user_id(), 'pending_email_change' );
     280            bp_delete_user_meta( $user_id, 'pending_email_change' );
     281
     282            /**
     283             * Fires when a Pending Email Change has been validated and before
     284             * BuddyPress redirects the user to a success message.
     285             *
     286             * @since 9.1.0
     287             *
     288             * @param int    $user_id     The user ID.
     289             * @param string $redirect_to The Default Front-end Settings Screen URL.
     290             */
     291            do_action( 'bp_settings_email_changed', $user_id, $redirect_to );
    264292
    265293            // Post a success message and redirect.
     
    271299
    272300        bp_core_redirect( $redirect_to );
    273         die();
    274301
    275302    // Email change is being dismissed.
     
    278305
    279306        if ( $nonce_check ) {
    280             bp_delete_user_meta( bp_displayed_user_id(), 'pending_email_change' );
     307            $user_id = bp_displayed_user_id();
     308            bp_delete_user_meta( $user_id, 'pending_email_change' );
     309
     310            /**
     311             * Fires when a Pending Email Change has been dismissed and before
     312             * BuddyPress redirects the user to a success message.
     313             *
     314             * @since 9.1.0
     315             *
     316             * @param int    $user_id     The user ID.
     317             * @param string $redirect_to The Default Front-end Settings Screen URL.
     318             */
     319            do_action( 'bp_settings_email_change_dismissed', $user_id, $redirect_to );
     320
    281321            bp_core_add_message( __( 'You have successfully dismissed your pending email change.', 'buddypress' ) );
    282322        }
    283323
    284324        bp_core_redirect( $redirect_to );
    285         die();
    286325    }
    287326}
Note: See TracChangeset for help on using the changeset viewer.