Skip to:
Content

BuddyPress.org

Ticket #8538: 8538.patch

File 8538.patch, 3.5 KB (added by imath, 3 months ago)
  • src/bp-settings/actions/general.php

    diff --git src/bp-settings/actions/general.php src/bp-settings/actions/general.php
    index ba6199fd9..0d3db5b0d 100644
    function bp_settings_verify_email_change() { 
    245245
    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' ) );
     265                        bp_core_redirect( $redirect_to );
     266                }
    249267
    250268                // Bail if the hash provided doesn't match the one saved in the database.
    251269                if ( ! hash_equals( urldecode( $_GET['verify_email_change'] ), $pending_email['hash'] ) ) {
    function bp_settings_verify_email_change() { 
    253271                }
    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.
    266294                        bp_core_add_message( __( 'You have successfully verified your new email address.', 'buddypress' ) );
    function bp_settings_verify_email_change() { 
    270298                }
    271299
    272300                bp_core_redirect( $redirect_to );
    273                 die();
    274301
    275302        // Email change is being dismissed.
    276303        } elseif ( ! empty( $_GET['dismiss_email_change'] ) ) {
    277304                $nonce_check = isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'bp_dismiss_email_change' );
    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}
    288327add_action( 'bp_actions', 'bp_settings_verify_email_change' );