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.

I have a "change password" page.

Is there a way to redirect that page when the user login first time using wordpress generated password?

Thanks

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Maybe this helps you?

http://stackoverflow.com/questions/4267285/redirect-user-after-first-login-in-wordpress

He seems to had a similar problem and solved it a year ago.

What he does different to your approach is redirecting 48hrs after registration. Maybe this is enough?

If not - I'm looking to do it your way.

--- EDIT

Okay I just made a plugin what does exactly what you want:

/*
 Plugin Name: Redirect Passwort
Plugin URI: TODO
Description: TODO
Author: xaeDes
Version: 0.1
Author URI: TODO
License: GPL2
*/

function redirect_passwort_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
        update_metadata("user",$user_id,"changed_password",true);
    }
}
add_action("profile_update", "redirect_passwort_profile_update", 10, 2);

function redirect_passwort_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') . "/change-your-password-dude/";
        } else {
            return $redirect_to;
        }
    }
}
add_filter('login_redirect', 'redirect_passwort_login_redirect',10,3);

function redirect_passwort_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");
    }
}
add_action('password_reset', 'redirect_passwort_password_reset');

It adds a user meta data "changed_password" to the user who changed its passwort.

When logging in it checks whether the user meta data "changed_password" is set and redirects if it is not set (and therefore the user has not changed its passwort even once).

When the users password is reset to a random one, the user meta data "changed_password" is reset as well.

share|improve this answer
    
I don't think its a good idea redirecting users to "change password" page based on 48hours time. It will be problem if the user login defferent times in those 48 hours. I don't want to redirect that user to change password page often. –  Giri Mar 25 '12 at 16:05
    
Hi Thanks for the code. I tested your code. But its not working in my site. I'm using custom page for login. Is that the reason why its not working? Here is my login function. Do i have to modify any codes there? Thanks –  Giri Mar 25 '12 at 17:46
    
You have to change the url of the site you are redirecting to in my plugin: return get_bloginfo('url') . "/change-your-password-dude/"; You are using wp_redirect to redirect to a site. But my plugin hooks into login_redirect, which is called from standard wordpress login. You could apply the login_redirect for yourself : wp_redirect(apply_filters('login_redirect', get_bloginfo('url') . '/my-account/','', $user);); in your pastebin line 19. Does that solve your problems? –  xaedes Mar 25 '12 at 17:58
    
No it doesn't. Here is my modified login function. I created a new user and tested it. Its supposed to redirect to change-password page. But it still redirect to my-account page. And yes i replaced your change-your-password-dude text with my change-password text. Any idea whats wrong? –  Giri Mar 25 '12 at 18:16
    
Which wordpress version are you using? Could you check whether redirect_passwort_profile_update or redirect_passwort_login_redirect are ever called? Maybe add something like this as first line of the files : file_put_contents(dirname(__FILE__).'/log-'.__FUNCTION__.'_'.__LINE__, ''); and check the folder of the plugin for generated files. The folder of the plugin have to be writable for the webserver. –  xaedes Mar 25 '12 at 18:28
show 8 more comments

Hook user_register and add user metadata to store a "has not logged in yet" flag. Hook wp_login and check for that metadata, delete and redirect if it exists, otherwise do normal login behavior.

share|improve this answer
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.