Skip to:
Content

BuddyPress.org

Changeset 13292


Ignore:
Timestamp:
07/06/2022 09:56:46 AM (2 years ago)
Author:
imath
Message:

Pass the user ID inside the hook fired after settings are saved

This is a reply to a request made in the BuddyPress support forum. See
[https://buddypress.org/support/topic/suggestion-pass-user_id-to-bp_core_general_settings_after_save/
this topic] for more information about it.

Props alexmangini, oztaser, espellcaste.

Fixes #8631

--Cette ligne, et les suivantes

ci-dessous, seront ignorées--

M src/bp-settings/actions/general.php

File:
1 edited

Legend:

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

    r13223 r13292  
    4545
    4646    // Define local defaults
    47     $bp            = buddypress(); // The instance
    48     $email_error   = false;        // invalid|blocked|taken|empty|nochange
    49     $pass_error    = false;        // invalid|mismatch|empty|nochange
    50     $pass_changed  = false;        // true if the user changes their password
    51     $email_changed = false;        // true if the user changes their email
    52     $feedback_type = 'error';      // success|error
    53     $feedback      = array();      // array of strings for feedback.
     47    $bp            = buddypress();           // The instance
     48    $email_error   = false;                  // invalid|blocked|taken|empty|nochange
     49    $pass_error    = false;                  // invalid|mismatch|empty|nochange
     50    $pass_changed  = false;                  // true if the user changes their password
     51    $email_changed = false;                  // true if the user changes their email
     52    $feedback_type = 'error';                // success|error
     53    $feedback      = array();                // array of strings for feedback.
     54    $user_id       = bp_displayed_user_id(); // The ID of the user being displayed.
    5455
    5556    // Nonce check.
    56     check_admin_referer('bp_settings_general');
     57    check_admin_referer( 'bp_settings_general' );
    5758
    5859    // Validate the user again for the current password when making a big change.
    59     if ( ( is_super_admin() ) || ( !empty( $_POST['pwd'] ) && wp_check_password( $_POST['pwd'], $bp->displayed_user->userdata->user_pass, bp_displayed_user_id() ) ) ) {
     60    if ( ( is_super_admin() ) || ( ! empty( $_POST['pwd'] ) && wp_check_password( $_POST['pwd'], $bp->displayed_user->userdata->user_pass, $user_id ) ) ) {
    6061
    6162        $update_user = array(
    62             'ID' => (int) bp_displayed_user_id(),
     63            'ID' => (int) $user_id,
    6364        );
    6465
     
    100101                    );
    101102
    102                     bp_update_user_meta( bp_displayed_user_id(), 'pending_email_change', $pending_email );
     103                    bp_update_user_meta( $user_id, 'pending_email_change', $pending_email );
    103104                    $verify_link = bp_displayed_user_domain() . bp_get_settings_slug() . '/?verify_email_change=' . $hash;
    104105
     
    106107                    $args = array(
    107108                        'tokens' => array(
    108                             'displayname'    => bp_core_get_user_displayname( bp_displayed_user_id() ),
     109                            'displayname'    => bp_core_get_user_displayname( $user_id ),
    109110                            'old-user.email' => $old_user_email,
    110111                            'user.email'     => $user_email,
     
    182183        // on the current page load.
    183184        if ( ( false === $email_error ) && ( false === $pass_error ) && ( wp_update_user( $update_user ) ) ) {
    184             $bp->displayed_user->userdata = bp_core_get_core_userdata( bp_displayed_user_id() );
     185            $bp->displayed_user->userdata = bp_core_get_core_userdata( $user_id );
    185186        }
    186187
     
    227228    }
    228229
    229     // Set the feedback.
    230     bp_core_add_message( implode( "\n", $feedback ), $feedback_type );
     230    // Set the URL to redirect the user to.
     231    $redirect_to = trailingslashit( bp_displayed_user_domain() . bp_get_settings_slug() . '/general' );
    231232
    232233    /**
     
    234235     *
    235236     * @since 1.5.0
     237     * @since 11.0.0 Add the `$user_id` & `$redirect_to` parameters.
     238     *
     239     * @param int    $user_id     The ID of the user being displayed.
     240     * @param string $redirect_to The Default Front-end General Settings Screen URL.
    236241     */
    237     do_action( 'bp_core_general_settings_after_save' );
     242    do_action( 'bp_core_general_settings_after_save', $user_id, $redirect_to );
     243
     244    // Set the feedback.
     245    bp_core_add_message( implode( "\n", $feedback ), $feedback_type );
    238246
    239247    // Redirect to prevent issues with browser back button.
    240     bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_settings_slug() . '/general' ) );
     248    bp_core_redirect( $redirect_to );
    241249}
    242250add_action( 'bp_actions', 'bp_settings_action_general' );
Note: See TracChangeset for help on using the changeset viewer.