/**
 * Handles the changing and saving of user email addressos and passwords
 *
 * We do quite a bit of logic and error handling here to make sure that users
 * do not accidentally lock themselves out of their accounts. We also try to
 * provide as accurate of feedback as possible without exposing anyone else's
 * inforation to them.
 *
 * Special considerations are made for super admins that are able to edit any
 * users accounts already, without knowing their existing password.
 *
 * @global BuddyPress $bp
 */
function bp_settings_action_general()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action
    if (!isset($_POST['submit'])) {
        return;
    }
    // Bail if not in settings
    if (!bp_is_settings_component() || !bp_is_current_action('general')) {
        return;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Define local defaults
    $bp = buddypress();
    // The instance
    $email_error = false;
    // invalid|blocked|taken|empty|nochange
    $pass_error = false;
    // invalid|mismatch|empty|nochange
    $pass_changed = false;
    // true if the user changes their password
    $email_changed = false;
    // true if the user changes their email
    $feedback_type = 'error';
    // success|error
    $feedback = array();
    // array of strings for feedback
    // Nonce check
    check_admin_referer('bp_settings_general');
    // Validate the user again for the current password when making a big change
    if (is_super_admin() || !empty($_POST['pwd']) && wp_check_password($_POST['pwd'], $bp->displayed_user->userdata->user_pass, bp_displayed_user_id())) {
        $update_user = get_userdata(bp_displayed_user_id());
        /** Email Change Attempt ******************************************/
        if (!empty($_POST['email'])) {
            // What is missing from the profile page vs signup - lets double check the goodies
            $user_email = sanitize_email(esc_html(trim($_POST['email'])));
            // User is changing email address
            if ($bp->displayed_user->userdata->user_email != $user_email) {
                // Run some tests on the email address
                $email_checks = bp_core_validate_email_address($user_email);
                if (true !== $email_checks) {
                    if (isset($email_checks['invalid'])) {
                        $email_error = 'invalid';
                    }
                    if (isset($email_checks['domain_banned']) || isset($email_checks['domain_not_allowed'])) {
                        $email_error = 'blocked';
                    }
                    if (isset($email_checks['in_use'])) {
                        $email_error = 'taken';
                    }
                }
                // Yay we made it!
                if (false === $email_error) {
                    $update_user->user_email = $user_email;
                    $email_changed = true;
                }
                // No change
            } else {
                $email_error = false;
            }
            // Email address cannot be empty
        } else {
            $email_error = 'empty';
        }
        /** Password Change Attempt ***************************************/
        if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
            // Password change attempt is successful
            if ($_POST['pass1'] == $_POST['pass2'] && !strpos(" " . $_POST['pass1'], "\\")) {
                $update_user->user_pass = $_POST['pass1'];
                $pass_changed = true;
                // Password change attempt was unsuccessful
            } else {
                $pass_error = 'mismatch';
            }
            // Both password fields were empty
        } elseif (empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = false;
            // One of the password boxes was left empty
        } elseif (empty($_POST['pass1']) && !empty($_POST['pass2']) || !empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = 'empty';
        }
        // The structure of the $update_user object changed in WP 3.3, but
        // wp_update_user() still expects the old format
        if (isset($update_user->data) && is_object($update_user->data)) {
            $update_user = $update_user->data;
            $update_user = get_object_vars($update_user);
            // Unset the password field to prevent it from emptying out the
            // user's user_pass field in the database.
            // @see wp_update_user()
            if (false === $pass_changed) {
                unset($update_user['user_pass']);
            }
        }
        // Clear cached data, so that the changed settings take effect
        // on the current page load
        if (false === $email_error && false === $pass_error && wp_update_user($update_user)) {
            wp_cache_delete('bp_core_userdata_' . bp_displayed_user_id(), 'bp');
            $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id());
        }
        // Password Error
    } else {
        $pass_error = 'invalid';
    }
    // Email feedback
    switch ($email_error) {
        case 'invalid':
            $feedback['email_invalid'] = __('That email address is invalid. Check the formatting and try again.', 'buddypress');
            break;
        case 'blocked':
            $feedback['email_blocked'] = __('That email address is currently unavailable for use.', 'buddypress');
            break;
        case 'taken':
            $feedback['email_taken'] = __('That email address is already taken.', 'buddypress');
            break;
        case 'empty':
            $feedback['email_empty'] = __('Email address cannot be empty.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // Password feedback
    switch ($pass_error) {
        case 'invalid':
            $feedback['pass_error'] = __('Your current password is invalid.', 'buddypress');
            break;
        case 'mismatch':
            $feedback['pass_mismatch'] = __('The new password fields did not match.', 'buddypress');
            break;
        case 'empty':
            $feedback['pass_empty'] = __('One of the password fields was empty.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // No errors so show a simple success message
    if ((false === $email_error || false == $pass_error) && (true === $pass_changed || true === $email_changed)) {
        $feedback[] = __('Your settings have been saved.', 'buddypress');
        $feedback_type = 'success';
        // Some kind of errors occurred
    } elseif ((false === $email_error || false === $pass_error) && (false === $pass_changed || false === $email_changed)) {
        if (bp_is_my_profile()) {
            $feedback['nochange'] = __('No changes were made to your account.', 'buddypress');
        } else {
            $feedback['nochange'] = __('No changes were made to this account.', 'buddypress');
        }
    }
    // Set the feedback
    bp_core_add_message(implode('</p><p>', $feedback), $feedback_type);
    // Execute additional code
    do_action('bp_core_general_settings_after_save');
    // Redirect to prevent issues with browser back button
    bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_settings_slug() . '/general'));
}
Ejemplo n.º 2
0
/**
 * Handles the changing and saving of user email addresses and passwords.
 *
 * We do quite a bit of logic and error handling here to make sure that users
 * do not accidentally lock themselves out of their accounts. We also try to
 * provide as accurate of feedback as possible without exposing anyone else's
 * information to them.
 *
 * Special considerations are made for super admins that are able to edit any
 * users accounts already, without knowing their existing password.
 *
 * @global BuddyPress $bp
 */
function bp_settings_action_general()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action
    if (!isset($_POST['submit'])) {
        return;
    }
    // Bail if not in settings
    if (!bp_is_settings_component() || !bp_is_current_action('general')) {
        return;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Define local defaults
    $bp = buddypress();
    // The instance
    $email_error = false;
    // invalid|blocked|taken|empty|nochange
    $pass_error = false;
    // invalid|mismatch|empty|nochange
    $pass_changed = false;
    // true if the user changes their password
    $email_changed = false;
    // true if the user changes their email
    $feedback_type = 'error';
    // success|error
    $feedback = array();
    // array of strings for feedback
    // Nonce check
    check_admin_referer('bp_settings_general');
    // Validate the user again for the current password when making a big change
    if (is_super_admin() || !empty($_POST['pwd']) && wp_check_password($_POST['pwd'], $bp->displayed_user->userdata->user_pass, bp_displayed_user_id())) {
        $update_user = get_userdata(bp_displayed_user_id());
        /** Email Change Attempt ******************************************/
        if (!empty($_POST['email'])) {
            // What is missing from the profile page vs signup -
            // let's double check the goodies
            $user_email = sanitize_email(esc_html(trim($_POST['email'])));
            $old_user_email = $bp->displayed_user->userdata->user_email;
            // User is changing email address
            if ($old_user_email != $user_email) {
                // Run some tests on the email address
                $email_checks = bp_core_validate_email_address($user_email);
                if (true !== $email_checks) {
                    if (isset($email_checks['invalid'])) {
                        $email_error = 'invalid';
                    }
                    if (isset($email_checks['domain_banned']) || isset($email_checks['domain_not_allowed'])) {
                        $email_error = 'blocked';
                    }
                    if (isset($email_checks['in_use'])) {
                        $email_error = 'taken';
                    }
                }
                // Store a hash to enable email validation
                if (false === $email_error) {
                    $hash = wp_hash($_POST['email']);
                    $pending_email = array('hash' => $hash, 'newemail' => $user_email);
                    bp_update_user_meta(bp_displayed_user_id(), 'pending_email_change', $pending_email);
                    $email_text = sprintf(__('Dear %1$s,

You recently changed the email address associated with your account on %2$s.
If this is correct, please click on the following link to complete the change:
%3$s

You can safely ignore and delete this email if you do not want to take this action or if you have received this email in error.

This email has been sent to %4$s.

Regards,
%5$s
%6$s', 'buddypress'), bp_core_get_user_displayname(bp_displayed_user_id()), bp_get_site_name(), esc_url(bp_displayed_user_domain() . bp_get_settings_slug() . '/?verify_email_change=' . $hash), $user_email, bp_get_site_name(), bp_get_root_domain());
                    /**
                     * Filter the email text sent when a user changes emails.
                     *
                     * @since 2.1.0
                     *
                     * @param string  $email_text     Text of the email.
                     * @param string  $new_user_email New user email that the
                     *                                current user has changed to.
                     * @param string  $old_user_email Existing email address
                     *                                for the current user.
                     * @param WP_User $update_user    Userdata object for the current user.
                     */
                    $content = apply_filters('bp_new_user_email_content', $email_text, $user_email, $old_user_email, $update_user);
                    // Send the verification email
                    wp_mail($user_email, sprintf(__('[%s] Verify your new email address', 'buddypress'), wp_specialchars_decode(bp_get_site_name())), $content);
                    // We mark that the change has taken place so as to ensure a
                    // success message, even though verification is still required
                    $_POST['email'] = $update_user->user_email;
                    $email_changed = true;
                }
                // No change
            } else {
                $email_error = false;
            }
            // Email address cannot be empty
        } else {
            $email_error = 'empty';
        }
        /** Password Change Attempt ***************************************/
        if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
            if ($_POST['pass1'] == $_POST['pass2'] && !strpos(" " . $_POST['pass1'], "\\")) {
                // Password change attempt is successful
                if (!empty($_POST['pwd']) && $_POST['pwd'] != $_POST['pass1'] || is_super_admin()) {
                    $update_user->user_pass = $_POST['pass1'];
                    $pass_changed = true;
                    // The new password is the same as the current password
                } else {
                    $pass_error = 'same';
                }
                // Password change attempt was unsuccessful
            } else {
                $pass_error = 'mismatch';
            }
            // Both password fields were empty
        } elseif (empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = false;
            // One of the password boxes was left empty
        } elseif (empty($_POST['pass1']) && !empty($_POST['pass2']) || !empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = 'empty';
        }
        // The structure of the $update_user object changed in WP 3.3, but
        // wp_update_user() still expects the old format
        if (isset($update_user->data) && is_object($update_user->data)) {
            $update_user = $update_user->data;
            $update_user = get_object_vars($update_user);
            // Unset the password field to prevent it from emptying out the
            // user's user_pass field in the database.
            // @see wp_update_user()
            if (false === $pass_changed) {
                unset($update_user['user_pass']);
            }
        }
        // Clear cached data, so that the changed settings take effect
        // on the current page load
        if (false === $email_error && false === $pass_error && wp_update_user($update_user)) {
            wp_cache_delete('bp_core_userdata_' . bp_displayed_user_id(), 'bp');
            $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id());
        }
        // Password Error
    } else {
        $pass_error = 'invalid';
    }
    // Email feedback
    switch ($email_error) {
        case 'invalid':
            $feedback['email_invalid'] = __('That email address is invalid. Check the formatting and try again.', 'buddypress');
            break;
        case 'blocked':
            $feedback['email_blocked'] = __('That email address is currently unavailable for use.', 'buddypress');
            break;
        case 'taken':
            $feedback['email_taken'] = __('That email address is already taken.', 'buddypress');
            break;
        case 'empty':
            $feedback['email_empty'] = __('Email address cannot be empty.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // Password feedback
    switch ($pass_error) {
        case 'invalid':
            $feedback['pass_error'] = __('Your current password is invalid.', 'buddypress');
            break;
        case 'mismatch':
            $feedback['pass_mismatch'] = __('The new password fields did not match.', 'buddypress');
            break;
        case 'empty':
            $feedback['pass_empty'] = __('One of the password fields was empty.', 'buddypress');
            break;
        case 'same':
            $feedback['pass_same'] = __('The new password must be different from the current password.', 'buddypress');
            break;
        case false:
            // No change
            break;
    }
    // No errors so show a simple success message
    if ((false === $email_error || false == $pass_error) && (true === $pass_changed || true === $email_changed)) {
        $feedback[] = __('Your settings have been saved.', 'buddypress');
        $feedback_type = 'success';
        // Some kind of errors occurred
    } elseif ((false === $email_error || false === $pass_error) && (false === $pass_changed || false === $email_changed)) {
        if (bp_is_my_profile()) {
            $feedback['nochange'] = __('No changes were made to your account.', 'buddypress');
        } else {
            $feedback['nochange'] = __('No changes were made to this account.', 'buddypress');
        }
    }
    // Set the feedback
    bp_core_add_message(implode("\n", $feedback), $feedback_type);
    /**
     * Fires after the general settings have been saved, and before redirect.
     *
     * @since 1.5.0
     */
    do_action('bp_core_general_settings_after_save');
    // Redirect to prevent issues with browser back button
    bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_settings_slug() . '/general'));
}
/**
 * Validate a user name and email address when creating a new user.
 *
 * @param string $user_name Username to validate
 * @param string $user_email Email address to validate
 * @return array Results of user validation including errors, if any
 */
function bp_core_validate_user_signup($user_name, $user_email)
{
    $errors = new WP_Error();
    // Apply any user_login filters added by BP or other plugins before validating
    $user_name = apply_filters('pre_user_login', $user_name);
    if (empty($user_name)) {
        $errors->add('user_name', __('Please enter a username', 'buddypress'));
    }
    // Make sure illegal names include BuddyPress slugs and values
    bp_core_flush_illegal_names();
    $illegal_names = get_site_option('illegal_names');
    if (in_array($user_name, (array) $illegal_names)) {
        $errors->add('user_name', __('That username is not allowed', 'buddypress'));
    }
    if (!validate_username($user_name)) {
        $errors->add('user_name', __('Usernames can contain only letters, numbers, ., -, *, and @', 'buddypress'));
    }
    if (strlen($user_name) < 4) {
        $errors->add('user_name', __('Username must be at least 4 characters', 'buddypress'));
    }
    if (strpos(' ' . $user_name, '_') != false) {
        $errors->add('user_name', __('Sorry, usernames may not contain the character "_"!', 'buddypress'));
    }
    // Is the user_name all numeric?
    $match = array();
    preg_match('/[0-9]*/', $user_name, $match);
    if ($match[0] == $user_name) {
        $errors->add('user_name', __('Sorry, usernames must have letters too!', 'buddypress'));
    }
    // Check if the username has been used already.
    if (username_exists($user_name)) {
        $errors->add('user_name', __('Sorry, that username already exists!', 'buddypress'));
    }
    // Validate the email address and process the validation results into
    // error messages
    $validate_email = bp_core_validate_email_address($user_email);
    bp_core_add_validation_error_messages($errors, $validate_email);
    // Assemble the return array
    $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors);
    // Apply WPMU legacy filter
    $result = apply_filters('wpmu_validate_user_signup', $result);
    return apply_filters('bp_core_validate_user_signup', $result);
}
/**
 * Validate a user name and email address when creating a new user.
 *
 * @since 1.2.2
 *
 * @param string $user_name  Username to validate.
 * @param string $user_email Email address to validate.
 * @return array Results of user validation including errors, if any.
 */
function bp_core_validate_user_signup($user_name, $user_email)
{
    // Make sure illegal names include BuddyPress slugs and values.
    bp_core_flush_illegal_names();
    // WordPress Multisite has its own validation. Use it, so that we
    // properly mirror restrictions on username, etc.
    if (function_exists('wpmu_validate_user_signup')) {
        $result = wpmu_validate_user_signup($user_name, $user_email);
        // When not running Multisite, we perform our own validation. What
        // follows reproduces much of the logic of wpmu_validate_user_signup(),
        // minus the multisite-specific restrictions on user_login.
    } else {
        $errors = new WP_Error();
        /**
         * Filters the username before being validated.
         *
         * @since 1.5.5
         *
         * @param string $user_name Username to validate.
         */
        $user_name = apply_filters('pre_user_login', $user_name);
        // User name can't be empty.
        if (empty($user_name)) {
            $errors->add('user_name', __('Please enter a username', 'buddypress'));
        }
        // User name can't be on the blacklist.
        $illegal_names = get_site_option('illegal_names');
        if (in_array($user_name, (array) $illegal_names)) {
            $errors->add('user_name', __('That username is not allowed', 'buddypress'));
        }
        // User name must pass WP's validity check.
        if (!validate_username($user_name)) {
            $errors->add('user_name', __('Usernames can contain only letters, numbers, ., -, and @', 'buddypress'));
        }
        // Minimum of 4 characters.
        if (strlen($user_name) < 4) {
            $errors->add('user_name', __('Username must be at least 4 characters', 'buddypress'));
        }
        // No underscores. @todo Why not?
        if (false !== strpos(' ' . $user_name, '_')) {
            $errors->add('user_name', __('Sorry, usernames may not contain the character "_"!', 'buddypress'));
        }
        // No usernames that are all numeric. @todo Why?
        $match = array();
        preg_match('/[0-9]*/', $user_name, $match);
        if ($match[0] == $user_name) {
            $errors->add('user_name', __('Sorry, usernames must have letters too!', 'buddypress'));
        }
        // Check into signups.
        $signups = BP_Signup::get(array('user_login' => $user_name));
        $signup = isset($signups['signups']) && !empty($signups['signups'][0]) ? $signups['signups'][0] : false;
        // Check if the username has been used already.
        if (username_exists($user_name) || !empty($signup)) {
            $errors->add('user_name', __('Sorry, that username already exists!', 'buddypress'));
        }
        // Validate the email address and process the validation results into
        // error messages.
        $validate_email = bp_core_validate_email_address($user_email);
        bp_core_add_validation_error_messages($errors, $validate_email);
        // Assemble the return array.
        $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors);
        // Apply WPMU legacy filter.
        $result = apply_filters('wpmu_validate_user_signup', $result);
    }
    /**
     * Filters the result of the user signup validation.
     *
     * @since 1.2.2
     *
     * @param array $result Results of user validation including errors, if any.
     */
    return apply_filters('bp_core_validate_user_signup', $result);
}
/**
 * Handles the changing and saving of user email addresses and passwords.
 *
 * We do quite a bit of logic and error handling here to make sure that users
 * do not accidentally lock themselves out of their accounts. We also try to
 * provide as accurate of feedback as possible without exposing anyone else's
 * information to them.
 *
 * Special considerations are made for super admins that are able to edit any
 * users accounts already, without knowing their existing password.
 *
 * @since 1.6.0
 *
 * @global BuddyPress $bp
 */
function bp_settings_action_general()
{
    // Bail if not a POST action.
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action.
    if (!isset($_POST['submit'])) {
        return;
    }
    // Bail if not in settings.
    if (!bp_is_settings_component() || !bp_is_current_action('general')) {
        return;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Define local defaults
    $bp = buddypress();
    // The instance
    $email_error = false;
    // invalid|blocked|taken|empty|nochange
    $pass_error = false;
    // invalid|mismatch|empty|nochange
    $pass_changed = false;
    // true if the user changes their password
    $email_changed = false;
    // true if the user changes their email
    $feedback_type = 'error';
    // success|error
    $feedback = array();
    // array of strings for feedback.
    // Nonce check.
    check_admin_referer('bp_settings_general');
    // Validate the user again for the current password when making a big change.
    if (is_super_admin() || !empty($_POST['pwd']) && wp_check_password($_POST['pwd'], $bp->displayed_user->userdata->user_pass, bp_displayed_user_id())) {
        $update_user = get_userdata(bp_displayed_user_id());
        /* Email Change Attempt ******************************************/
        if (!empty($_POST['email'])) {
            // What is missing from the profile page vs signup -
            // let's double check the goodies.
            $user_email = sanitize_email(esc_html(trim($_POST['email'])));
            $old_user_email = $bp->displayed_user->userdata->user_email;
            // User is changing email address.
            if ($old_user_email != $user_email) {
                // Run some tests on the email address.
                $email_checks = bp_core_validate_email_address($user_email);
                if (true !== $email_checks) {
                    if (isset($email_checks['invalid'])) {
                        $email_error = 'invalid';
                    }
                    if (isset($email_checks['domain_banned']) || isset($email_checks['domain_not_allowed'])) {
                        $email_error = 'blocked';
                    }
                    if (isset($email_checks['in_use'])) {
                        $email_error = 'taken';
                    }
                }
                // Store a hash to enable email validation.
                if (false === $email_error) {
                    $hash = wp_hash($_POST['email']);
                    $pending_email = array('hash' => $hash, 'newemail' => $user_email);
                    bp_update_user_meta(bp_displayed_user_id(), 'pending_email_change', $pending_email);
                    $verify_link = bp_displayed_user_domain() . bp_get_settings_slug() . '/?verify_email_change=' . $hash;
                    // Send the verification email.
                    $args = array('tokens' => array('displayname' => bp_core_get_user_displayname(bp_displayed_user_id()), 'old-user.email' => $old_user_email, 'user.email' => $user_email, 'verify.url' => esc_url($verify_link)));
                    bp_send_email('settings-verify-email-change', bp_displayed_user_id(), $args);
                    // We mark that the change has taken place so as to ensure a
                    // success message, even though verification is still required.
                    $_POST['email'] = $update_user->user_email;
                    $email_changed = true;
                }
                // No change.
            } else {
                $email_error = false;
            }
            // Email address cannot be empty.
        } else {
            $email_error = 'empty';
        }
        /* Password Change Attempt ***************************************/
        if (!empty($_POST['pass1']) && !empty($_POST['pass2'])) {
            if ($_POST['pass1'] == $_POST['pass2'] && !strpos(" " . $_POST['pass1'], "\\")) {
                // Password change attempt is successful.
                if (!empty($_POST['pwd']) && $_POST['pwd'] != $_POST['pass1'] || is_super_admin()) {
                    $update_user->user_pass = $_POST['pass1'];
                    $pass_changed = true;
                    // The new password is the same as the current password.
                } else {
                    $pass_error = 'same';
                }
                // Password change attempt was unsuccessful.
            } else {
                $pass_error = 'mismatch';
            }
            // Both password fields were empty.
        } elseif (empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = false;
            // One of the password boxes was left empty.
        } elseif (empty($_POST['pass1']) && !empty($_POST['pass2']) || !empty($_POST['pass1']) && empty($_POST['pass2'])) {
            $pass_error = 'empty';
        }
        // The structure of the $update_user object changed in WP 3.3, but
        // wp_update_user() still expects the old format.
        if (isset($update_user->data) && is_object($update_user->data)) {
            $update_user = $update_user->data;
            $update_user = get_object_vars($update_user);
            // Unset the password field to prevent it from emptying out the
            // user's user_pass field in the database.
            // @see wp_update_user().
            if (false === $pass_changed) {
                unset($update_user['user_pass']);
            }
        }
        // Clear cached data, so that the changed settings take effect
        // on the current page load.
        if (false === $email_error && false === $pass_error && wp_update_user($update_user)) {
            wp_cache_delete('bp_core_userdata_' . bp_displayed_user_id(), 'bp');
            $bp->displayed_user->userdata = bp_core_get_core_userdata(bp_displayed_user_id());
        }
        // Password Error.
    } else {
        $pass_error = 'invalid';
    }
    // Email feedback.
    switch ($email_error) {
        case 'invalid':
            $feedback['email_invalid'] = __('That email address is invalid. Check the formatting and try again.', 'buddypress');
            break;
        case 'blocked':
            $feedback['email_blocked'] = __('That email address is currently unavailable for use.', 'buddypress');
            break;
        case 'taken':
            $feedback['email_taken'] = __('That email address is already taken.', 'buddypress');
            break;
        case 'empty':
            $feedback['email_empty'] = __('Email address cannot be empty.', 'buddypress');
            break;
        case false:
            // No change.
            break;
    }
    // Password feedback.
    switch ($pass_error) {
        case 'invalid':
            $feedback['pass_error'] = __('Your current password is invalid.', 'buddypress');
            break;
        case 'mismatch':
            $feedback['pass_mismatch'] = __('The new password fields did not match.', 'buddypress');
            break;
        case 'empty':
            $feedback['pass_empty'] = __('One of the password fields was empty.', 'buddypress');
            break;
        case 'same':
            $feedback['pass_same'] = __('The new password must be different from the current password.', 'buddypress');
            break;
        case false:
            // No change.
            break;
    }
    // No errors so show a simple success message.
    if ((false === $email_error || false == $pass_error) && (true === $pass_changed || true === $email_changed)) {
        $feedback[] = __('Your settings have been saved.', 'buddypress');
        $feedback_type = 'success';
        // Some kind of errors occurred.
    } elseif ((false === $email_error || false === $pass_error) && (false === $pass_changed || false === $email_changed)) {
        if (bp_is_my_profile()) {
            $feedback['nochange'] = __('No changes were made to your account.', 'buddypress');
        } else {
            $feedback['nochange'] = __('No changes were made to this account.', 'buddypress');
        }
    }
    // Set the feedback.
    bp_core_add_message(implode("\n", $feedback), $feedback_type);
    /**
     * Fires after the general settings have been saved, and before redirect.
     *
     * @since 1.5.0
     */
    do_action('bp_core_general_settings_after_save');
    // Redirect to prevent issues with browser back button.
    bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_settings_slug() . '/general'));
}