If we want to have the reset password form to look like this:
then we could use the following hooks:
/**
* Modify the password hint
*/
add_filter( 'password_hint', function( $hint )
{
return __( 'Use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).' );
} );
/**
* Modify 'New password' text
*/
add_action( 'validate_password_reset', function( $errors )
{
add_filter( 'gettext', 'wpse_gettext', 10, 2 );
return $message;
});
/**
* Modify 'Log in' text
*/
add_action( 'resetpass_form', function()
{
add_filter( 'gettext', 'wpse_gettext', 10, 2 );
});
The wpse_gettext
helper function is defined as:
function wpse_gettext( $translated_text, $text )
{
// Modify gettext if there's a match
switch ( $text )
{
case 'New password' :
remove_filter( current_filter(), __FUNCTION__ );
$translated_text = __( 'Use this password, or type a new one over it' );
break;
case 'Log in' :
remove_filter( current_filter(), __FUNCTION__ );
$translated_text = __( 'Already registered before? Click here to log-in' );
$match = true;
default:
}
return $translated_text;
}
where we remove the filter callback as soon as it has been used once.
We also try to hook into nearby hooks to minimize the number of gettext
checks.
Also note the danger of using gettext
functions within the gettext
filter ;-)
That's why I moved the remove_filter
above the __()
calls, to avoid infinite loops.