Overwrite default WordPress wording

I’m working on a plugin that changes the password requirements to be a bit stricter, however wherever there is a password field to create a password, WordPress’ hints are now no longer accurate (e.g. Password must consists of seven characters).

How can I replace those hints? Is there a filter/function that can help with this?

Related posts

Leave a Reply

2 comments

  1. You can filter 'gettext'.

    Sample code, not tested:

    add_filter( 'gettext', 'wpse_65085_change_error_messages', 10, 3 );
    
    function wpse_65085_change_error_messages( $translated, $text, domain )
    { 
        if ( 'default' !== $domain )
        {
            return $translated;
        }
    
        switch( $text )
        {
            case 'Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).':
                return __( 'Use whatever you want', 'your_plugin_text_domain' );
    
            // more cases here.
    
            default:
                return $translated;
        }
    }
    
  2. function change_password_hint ( $text ) {
        if(basename($_SERVER["SCRIPT_NAME"])=='wp-login.php' && $text == 'Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).'){
            $text = 'Here is your message.';
        }
        return $text;
    }
    add_filter( 'gettext', 'change_password_hint' );