1

A client gave a WP page to fix some problems. Specifically, there was a front end profile page that was not updating information as it was meant to. After I started testing, it all updates, but if you update your password it leaves you logged in.

What I want to happen is to log the user out, send them to the login page with a "enter new password" message. Can anyone point me in the right direction?

Here is the submit:

<p class="form-submit">
     <input name="updateuser" type="submit" id="updateuser" class="submit button" value=" <?php _e('Update Profile', 'profile'); ?>" />
     <?php wp_nonce_field( 'update-user' ) ?>
     <input name="action" type="hidden" id="action" value="update-user" />
     <input type="hidden" name="updated" value="is-update" />
</p>

And here is the password update:

if ( !empty($_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) {
    if ( $_POST['pass1'] == $_POST['pass2'] ) {         
        wp_update_user( array( 'ID' => $current_user->ID, 'user_pass' => esc_attr( $_POST['pass1'] ) ) );
        $success[] = __('Password successfuly updated.', 'profile');
        //wp_logout();
        // $logInLink = wp_login_url( get_bloginfo('url') );
        // wp_logout_url($logInLink);
        // wp_login_form();
    }
    else {
        $error[] = __('The passwords you entered do not match.  Your password was not updated.', 'profile');
    }
}

The commented stuff is what I have tried without success.

2
  • Is there a page refresh when the form is submitted? In other words, is the form using AJAX? Commented Apr 29, 2013 at 15:41
  • No, no ajax I am the page POSTs to itself.
    – LouieV
    Commented Apr 29, 2013 at 15:47

1 Answer 1

2

in your script, after you update the data use wp_logout() and wp_redirect() or wp_safe_redirect()

  wp_logout();
  wp_redirect( home_url() ); 
  exit;
2
  • Is there a way to pass a message like "password updated"?
    – LouieV
    Commented Apr 29, 2013 at 16:14
  • 2
    you can do something like : redirect to a url with param ex: /?logged_out=ok that trigger a msg in your landing page Commented Apr 29, 2013 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.