Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Is there a page refresh when the form is submitted? In other words, is the form using AJAX? –  dalbaeb Apr 29 '13 at 15:41
    
No, no ajax I am the page POSTs to itself. –  LouieV Apr 29 '13 at 15:47
add comment

1 Answer

up vote 2 down vote accepted

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;
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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