Skip to:
Content

BuddyPress.org

Ticket #2517: 2517.004.patch

File 2517.004.patch, 6.0 KB (added by r-a-y, 15 years ago)

Cleaned up form and misc. settings page titles

  • buddypress/bp-core/bp-core-settings.php

     
    3030/**** GENERAL SETTINGS ****/
    3131
    3232function bp_core_screen_general_settings() {
    33         global $current_user, $bp_settings_updated, $pass_error;
     33        global $current_user, $bp_settings_updated, $pass_error, $email_error, $pwd_error;
    3434
    3535        $bp_settings_updated = false;
    3636        $pass_error = false;
     37        $email_error = false;
     38        $pwd_error = false;
    3739
    3840        if ( isset($_POST['submit']) ) {
    3941                check_admin_referer('bp_settings_general');
     
    4143                require_once( WPINC . '/registration.php' );
    4244
    4345                // Form has been submitted and nonce checks out, lets do it.
     46               
     47                //we want to validate the user again for the current password when making a big change
     48                if ( !empty( $_POST['pwd'] ) && $_POST['pwd'] != '' && wp_check_password($_POST['pwd'], $current_user->user_pass, $current_user->ID) ) {
     49
     50                        //need to make sure changing an email address does not already exist
     51                        if ( $_POST['email'] != '' ) {
     52
     53                                //what is missing from the profile page vs signup - lets double check the goodies
     54                                $user_email = sanitize_email( wp_specialchars( trim( $_POST['email'] ) ) );
     55
     56                                if ( !is_email( $user_email ) )
     57                                        $email_error = true;
     58
     59                                $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
     60
     61                                if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
     62                                        $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
     63
     64                                        if ( in_array( $emaildomain, (array)$limited_email_domains ) == false ) {
     65                                                $email_error = true;
     66                                               
     67                                        }
     68                                }
     69
     70                                if ( !$email_error && $current_user->user_email != $user_email  ) {
     71                               
     72                                        //we don't want email dups in the system
     73                                        if ( email_exists( $user_email ) )
     74                                                $email_error = true;
     75                                               
     76                                        if (!$email_error)
     77                                                $current_user->user_email = $user_email;
     78                                }
     79                        }
    4480
    45                 if ( $_POST['email'] != '' )
    46                         $current_user->user_email = wp_specialchars( trim( $_POST['email'] ) );
     81                        if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {
     82                       
     83                                if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
     84                                        $current_user->user_pass = $_POST['pass1'];
     85                                else
     86                                        $pass_error = true;
    4787
    48                 if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {
    49                         if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
    50                                 $current_user->user_pass = $_POST['pass1'];
    51                         else
     88                        } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
    5289                                $pass_error = true;
    53                 } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
    54                         $pass_error = true;
     90                        } else {
     91                                unset( $current_user->user_pass );
     92                        }
     93
     94                        if ( !$email_error && !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
     95                                $bp_settings_updated = true;
     96                       
    5597                } else {
    56                         unset( $current_user->user_pass );
     98                        $pwd_error = true;
    5799                }
    58 
    59                 if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
    60                         $bp_settings_updated = true;
     100                       
    61101        }
    62102
    63103        add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );
     
    67107}
    68108
    69109function bp_core_screen_general_settings_title() {
    70         _e( 'General Settings', 'buddypress' );
     110        _e( '<h3>General Settings</h3>', 'buddypress' );
    71111}
    72112
    73113function bp_core_screen_general_settings_content() {
    74         global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
     114        global $bp, $current_user, $bp_settings_updated, $pass_error, $pwd_error, $email_error; ?>
    75115
    76116        <?php if ( $bp_settings_updated && !$pass_error ) { ?>
    77117                <div id="message" class="updated fade">
     
    84124                        <p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>
    85125                </div>
    86126        <?php } ?>
     127       
     128        <?php if ( $pwd_error && !$bp_settings_updated ) { ?>
     129                <div id="message" class="error fade">
     130                        <p><?php _e( 'Your password is incorrect', 'buddypress' ) ?></p>
     131                </div>
     132        <?php } ?>
     133
     134        <?php
     135        if ( $email_error && !$bp_settings_updated ) { ?>
     136                <div id="message" class="error fade">
     137                        <p><?php _e( 'Sorry, that email address is already used or is invalid', 'buddypress' ) ?></p>
     138                </div>
     139        <?php } ?>
     140
    87141
    88142        <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
     143
     144                <label for="pwd"><?php _e( 'Current Password <span>(required to update email or change current password)</span>', 'buddypress' ) ?></label>
     145                <input type="password" name="pwd" id="pwd" size="16" value="" class="settings-input small" /> &nbsp;<a href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a>
     146
    89147                <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
    90148                <input type="text" name="email" id="email" value="<?php echo attribute_escape( $current_user->user_email ); ?>" class="settings-input" />
    91149
     
    128186}
    129187
    130188function bp_core_screen_notification_settings_title() {
    131         _e( 'Notification Settings', 'buddypress' );
     189        _e( '<h3>Email Notifications</h3>', 'buddypress' );
    132190}
    133191
    134192function bp_core_screen_notification_settings_content() {
     
    141199        <?php } ?>
    142200
    143201        <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/notifications' ?>" method="post" id="settings-form">
    144                 <h3><?php _e( 'Email Notifications', 'buddypress' ) ?></h3>
    145202                <p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p>
    146203
    147204                <?php do_action( 'bp_notification_settings' ) ?>
     
    174231}
    175232
    176233function bp_core_screen_delete_account_title() {
    177         _e( 'Delete Account', 'buddypress' );
     234        _e( '<h3>Delete Account</h3>', 'buddypress' );
    178235}
    179236
    180237function bp_core_screen_delete_account_content() {