Skip to:
Content

BuddyPress.org

Ticket #2265: revalidation.diff

File revalidation.diff, 7.8 KB (added by j.conti, 11 years ago)

patch for revalidation

  • src/bp-settings/bp-settings-actions.php

    diff --git src/bp-settings/bp-settings-actions.php src/bp-settings/bp-settings-actions.php
    index db290e2..7703a17 100644
    function bp_settings_action_general() { 
    8989                                }
    9090
    9191                                // Yay we made it!
     92                                //Code taked from WordPress
    9293                                if ( false === $email_error ) {
    93                                         $update_user->user_email = $user_email;
    94                                         $email_changed = true;
     94                                        $hash = md5( $_POST['email'] . time() . mt_rand() );
     95                        $new_user_email = array(
     96                                        'hash' => $hash,
     97                                        'newemail' => $_POST['email']
     98                                        );
     99                        update_option( bp_displayed_user_id() . '_new_email', $new_user_email );
     100       
     101                        $email_text = __( 'Dear user,
     102       
     103You recently requested to have the email address on your account changed.
     104If this is correct, please click on the following link to change it:
     105###ADMIN_URL###
     106       
     107You can safely ignore and delete this email if you do not want to
     108take this action.
     109       
     110This email has been sent to ###EMAIL###
     111       
     112Regards,
     113All at ###SITENAME###
     114###SITEURL###', 'buddypress' );
     115       
     116                        /**
     117                         * Filter the email text sent when a user changes emails.
     118                         *
     119                         * The following strings have a special meaning and will get replaced dynamically:
     120                         * ###ADMIN_URL### The link to click on to confirm the email change. Required otherwise this functunalty is will break.
     121                         * ###EMAIL### The new email.
     122                         * ###SITENAME### The name of the site.
     123                         * ###SITEURL### The URL to the site.
     124                         *
     125                         * @since MU
     126                         *
     127                         * @param string $email_text     Text in the email.
     128                         * @param string $new_user_email New user email that the current user has changed to.
     129                         */
     130                        $content = apply_filters( 'bp_new_user_email_content', $email_text, $new_user_email );
     131       
     132                        $content = str_replace( '###ADMIN_URL###', esc_url( bp_displayed_user_domain() . bp_get_settings_slug() . '/?newuseremail=' .$hash ), $content );
     133                        $content = str_replace( '###EMAIL###', $_POST['email'], $content);
     134                        $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
     135                        $content = str_replace( '###SITEURL###', network_home_url(), $content );
     136       
     137                        wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content );
     138                        $_POST['email'] = $current_user->user_email;
     139                        $email_changed = true;
    95140                                }
    96141
    97142                        // No change
    function bp_settings_action_delete_account() { 
    355400        }
    356401}
    357402add_action( 'bp_actions', 'bp_settings_action_delete_account' );
     403
     404function bp_user_update_email(){
     405
     406        global $wpdb, $bp;
     407        if ( ( isset( $_GET[ 'newuseremail' ] ) ) && ( bp_current_component() == 'settings' ) ) {
     408                                        $new_email = get_option( bp_displayed_user_id() . '_new_email' );
     409                                        if ( $new_email[ 'hash' ] == $_GET[ 'newuseremail' ] ) {
     410                                        $user = new stdClass;
     411                                                $user->ID = bp_displayed_user_id();
     412                                                $user->user_name = bp_core_get_username($user->ID);
     413                                                $user->user_email = esc_html( trim( $new_email[ 'newemail' ] ) );
     414                                                if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_name ) ) )
     415                                                                $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $user->user_name ) );
     416                                                wp_update_user( $user );
     417                                                $email_changed = true;
     418                                                delete_option( bp_displayed_user_id() . '_new_email' );
     419                                                wp_redirect( esc_url( bp_displayed_user_domain() . bp_get_settings_slug() . '/?emailupdated=OK') );
     420                                                die();
     421                                                }
     422        } elseif ( !empty( $_GET['dismiss'] ) && bp_is_my_profile() && ( bp_displayed_user_id() . '_new_email' == $_GET['dismiss'] ) ) {
     423                delete_option( bp_displayed_user_id() . '_new_email' );
     424                wp_redirect( add_query_arg( array('updated' => 'true'), esc_url( bp_displayed_user_domain() . bp_get_settings_slug() . '/') ) );
     425                die();
     426        }
     427}
     428
     429add_action ('init', 'bp_user_update_email');
  • src/bp-templates/bp-legacy/buddypress/members/single/settings/general.php

    diff --git src/bp-templates/bp-legacy/buddypress/members/single/settings/general.php src/bp-templates/bp-legacy/buddypress/members/single/settings/general.php
    index d5058fc..a332f1d 100644
     
    1111
    1212        <label for="email"><?php _e( 'Account Email', 'buddypress' ); ?></label>
    1313        <input type="text" name="email" id="email" value="<?php echo bp_get_displayed_user_email(); ?>" class="settings-input" />
    14 
     14        <?php   
     15if ( bp_is_my_profile() ) {
     16                                                $new_email = get_option( bp_displayed_user_id() . '_new_email' );
     17                                                if ( $new_email && $new_email['newemail'] != bp_get_displayed_user_email() ) { ?>
     18                                                <div id="message" class="bp-template-notice error">
     19                                                        <p><?php printf( __('There is a pending change of your e-mail to <code>%1$s</code>. <a href="%2$s">Cancel</a>'), $new_email['newemail'], esc_url( bp_displayed_user_domain() . bp_get_settings_slug() . '/?dismiss=' . bp_displayed_user_id() . '_new_email' ) ); ?></p>
     20                                                </div>
     21                                        <?php }
     22                                                if ( isset( $_GET[ 'emailupdated' ] ) ) { ?>
     23                                                <div id="message" class="bp-template-notice updated">
     24                                                        <p><?php printf( __('Email updates successfully'), 'buddypress' ); ?></p>
     25                                                </div>
     26                                        <?php }
     27}?>
    1528        <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ); ?></label>
    1629        <input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'New Password', 'buddypress' ); ?><br />
    1730        <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'Repeat New Password', 'buddypress' ); ?>
  • src/bp-themes/bp-default/members/single/settings/general.php

    diff --git src/bp-themes/bp-default/members/single/settings/general.php src/bp-themes/bp-default/members/single/settings/general.php
    index 894cf61..5e7709a 100644
    get_header( 'buddypress' ); ?> 
    6161
    6262                                        <label for="email"><?php _e( 'Account Email', 'buddypress' ); ?></label>
    6363                                        <input type="text" name="email" id="email" value="<?php echo bp_get_displayed_user_email(); ?>" class="settings-input" />
    64 
     64                                        <?php   
     65if ( bp_is_my_profile() ) {
     66                                                $new_email = get_option( bp_displayed_user_id() . '_new_email' );
     67                                                if ( $new_email && $new_email['newemail'] != bp_get_displayed_user_email() ) { ?>
     68                                                <div id="message" class="bp-template-notice error">
     69                                                        <p><?php printf( __('There is a pending change of your e-mail to <code>%1$s</code>. <a href="%2$s">Cancel</a>'), $new_email['newemail'], esc_url( self_admin_url( bp_displayed_user_domain() . bp_get_settings_slug() . '/?dismiss=' . bp_displayed_user_id() . '_new_email' ) ) ); ?></p>
     70                                                </div>
     71                                        <?php }
     72                                                if ( isset( $_GET[ 'emailupdated' ] ) ) { ?>
     73                                                <div id="message" class="bp-template-notice updated">
     74                                                        <p><?php printf( __('Email updates successfully'), 'buddypress' ); ?></p>
     75                                                </div>
     76                                        <?php }
     77}?>
    6578                                        <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ); ?></label>
    6679                                        <input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'New Password', 'buddypress' ); ?><br />
    6780                                        <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'Repeat New Password', 'buddypress' ); ?>