Skip to:
Content
Pages
Categories
Search
Top
Bottom

Stop confirmation email from settings change email


  • knowitallninja
    Participant

    @knowitallninja

    Hi,

    I need my users to be able to change their email address in the settings tab of their profile, without receiving a confirmation email first.

    The reason being is I manually register new users to my site, and I have to assign them a generic email that doesn’t work to begin with sometimes. I want them then to be able to login and set the email to whatever they want it to be?

    Is this possible? Preferably without a plugin? I’ve looked online and seen alot about stopping the account activation email but nothing about the change email confirmation.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

  • ckchaudhary
    Participant

    @ckchaudhary

    Hi Ninja!
    This is possbile, but will require a considerable amount of custom coding. You’ll need to have some code this for you, or you can do it yourself if you are comfortable with wordpress coding.

    To give you an outline:
    – hook into bp_core_general_settings_after_save action
    – check if user is trying to change his email address
    – check if its the first time user is trying to do so( using a flag in usermeta ). You probably want it for the time time only.
    – delete the usermeta pending_email_change
    – and update emailaddress for user

    Hope it helps.


    knowitallninja
    Participant

    @knowitallninja

    Hi ckchaudhary,

    Thanks for the advice. It was really clear and helpful. While I am not the best coder I decided to have a go at doing it. I think I am super close. I have one problem, which is quite a major one, but probably super basic. I was hoping you wouldn’t mind me asking.

    Basically, I obviously need to know what the user actually wrote into the email input box. I thought this would be simple: $_POST[’email’]. However, this returns the users old email address, not the one they entered before pressing submit. Very strange!

    Do you know what is going wrong here? Is there a different way to get what they actually entered?

    I have added my code below as reference:

    function action_bp_core_general_settings_after_save() {
        $current_user = wp_get_current_user();
        if ( $current_user->user_email != $_POST['email'] ) {
            delete_user_meta( $current_user->ID, 'pending_email_change' );
            $userdata = array(
                'user_email' => $_POST['email']
            );
            wp_insert_user( $userdata );
        }
    };
    add_action( 'bp_core_general_settings_after_save','action_bp_core_general_settings_after_save' );

    moderator note: please use the code button when sharing code.


    knowitallninja
    Participant

    @knowitallninja

    Just thought I’d add, if I don’t enter my password it does allow me to update my user details as the $_POST[’email’] does pass my new email through.

    Obviously I don’t want the user to be able to change without confirming their password though. So I guess I need to validate their password first.


    knowitallninja
    Participant

    @knowitallninja

    Sorry for all the updates, I have found the problem. In bp-settings-actions.php there is a line in the default handling of a password change that says this: $_POST[’email’] = $update_user->user_email;

    By commenting that line out, it fixes the problem and my code works. It’s not ideal though as whenever I update buddypress it’ll change back. So if anyone knows a way around that then that would be great.

    Otherwise I have a working script. For future reference it’s here:

    function action_bp_core_general_settings_after_save() {
    $useremail = $_POST[’email’];
    $userpassword = $_POST[‘pwd’];
    $current_user = wp_get_current_user();

    if(wp_check_password( $userpassword, $current_user->user_pass, $current_user->ID)) {
    if ( $current_user->user_email != $useremail ) {
    delete_user_meta( $current_user->ID, ‘pending_email_change’ );
    $userdata = array(
    ‘ID’ => $current_user->ID,
    ‘user_login’ => $current_user->user_login,
    ‘user_email’ => $useremail
    );
    $result = wp_insert_user( $userdata );
    }
    }
    };
    add_action( ‘bp_core_general_settings_after_save’,’action_bp_core_general_settings_after_save’ );

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar