3

As administrator, if I make a new user, I can choose to email my new users a link which they click to go to wp-login.php where they are invited to set their password for the first time. (Wordpress used to email out a password, but I can see why they changed that!)

Users arrive at wp-login which records the username in a hidden field, and shows a suggested password which they can customise.

Some of my more easily boggled users are confused by this. They find the generated password incomprehensible, and do not understand that they can click on the suggested password in the box and change it to something they can remember. I would like to add some help text and maybe automatically select the suggested password too at this point.

I am not sure which hooks will allow me to do stuff that only appears to users setting their password, and not to anyone else who is logging in.

How can I do that?

2 Answers 2

2

You can add an extra help message box, on the reset password screen:

help text

with the following:

 /**
  * Display an extra help message box on the 'reset password' screen
  * 
  * @link http://wordpress.stackexchange.com/a/204429/26350
  */
 add_action( 'validate_password_reset', function( $errors )
 {
    add_action( 'login_message', function( $message )
    {
        // Modify this help message box to your needs:
        $mybox = sprintf( 
            '<br/><p class="message reset-pass">%s</p>',
            __( 'Some help text here!' )
        );

        return $message . $mybox; 
    } );
 } );

Here we add the extra message box by using the login_message filter. It should only show up on the reset password screen, because we hook it into the validate_password_reset action.

3
  • validate_password_reset looks perfect, I'll try it now. Am I missing a resource where actions that can be hooked into like that are all listed, do you know? I didn't know where to look?
    – Victoria
    Commented Oct 6, 2015 at 9:54
  • I just looked at the source code and made the suggestion from that. @Victoria
    – birgire
    Commented Oct 6, 2015 at 11:00
  • Doh! should have thought of that!
    – Victoria
    Commented Oct 7, 2015 at 15:14
0

I ended up using this. It's definitely a hack... if someone else knows how better to modify what's happening in wp-admin/js/user-profile.js without hacking core, please let me know. I don't want to deregister the entire script because I like all of the password strength checking, etc that's in there.

// add some js to the login page
function squarecandy_login_stylesheet() {
    wp_enqueue_script( 'custom-login-js', get_stylesheet_directory_uri() . '/js/login.js' );
}
add_action( 'login_enqueue_scripts', 'squarecandy_login_stylesheet' );

login.js

jQuery(document).ready(function($){
  // wait half a second so WP can fill the suggestion first
  setTimeout( function(){
    // Switch to the non-visible entry mode
    $('.wp-hide-pw').click();
    // clear the password fields, put the cursor in the field
    $('#pass1, #pass1-text').val('').focus();
  }, 500 );
});

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.