Support » Plugins » Force Password Change First Time Login

Viewing 1 replies (of 1 total)
  • Hi,
    I’m trying to redirect users the first time they login so they can change passwords to a cleaner one than what they receive in the register email. In functions.php I have:

    //redirect on first login
    function redirect_password_profile_update($user_id, $old_user_data) {
        $user = new WP_User( $user_id );
        if( $user->data->user_pass != $old_user_data->user_pass) {
            //password has changed
    add_action("profile_update", "redirect_password_profile_update", 10, 2);
    function redirect_password_login_redirect($redirect_to, $url_redirect_to = '', $user = null) {
        if( isset($user->ID) ) {
            $changed_password = get_metadata("user", $user->ID, "changed_password",true);
            if( $changed_password != true ) {
                return get_bloginfo('url') . "/wp-content/themes/xchange12/change-password.php/";
            } else {
                return $redirect_to;
    add_filter('login_redirect', 'redirect_password_login_redirect',10,3);
    function redirect_password_password_reset( $user ) {
        //password has been reset to a random one. so the changed_password meta data should be reset as well
        if( isset($user->ID) ) {
            delete_metadata("user", $user->ID, "changed_password");

    And in change-password.php I have:

    <form action="" type="POST">
    <input type="password" name="new_pass" id="new_pass">
    <input type="submit" value="Submit">
    $new_pass = $_POST['new_pass'];
    $user_id = get_current_user_id();
    $user_login = get_userdata($user_id);
    $user_login = $user_login->user_login;
    wp_update_user(array('ID' => $user_id, 'user_pass' => $new_pass));

    Can anyone tell me why this is not working? It updates the database with a blank value in the user_pass section and upon hitting submit i get the error message: Warning: get_object_vars() expects parameter 1 to be object, null given in /Applications/MAMP/htdocs/wordpress/xchange/wp-includes/user.php on line 1404

    and it does not redirect

    Thank you in advance

    [ Please do not bump, that’s not permitted here. ]

Viewing 1 replies (of 1 total)
  • The topic ‘Force Password Change First Time Login’ is closed to new replies.