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" />

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');
        // $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.

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

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

  wp_redirect( home_url() ); 
  • Is there a way to pass a message like "password updated"? – LouieV Apr 29 '13 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 – Tribalpixel Apr 29 '13 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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