Skip to main content
added 6 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

If we want to have the reset password form to look like this:

reset

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' :           
            $textremove_filter( current_filter(), __FUNCTION__ );
            $translated_text = __( 'Use this password, or type a new one over it' );
            $matchbreak;
 = true;
      case 'Log in' :
    break;
        caseremove_filter( 'Logcurrent_filter(), in'__FUNCTION__ :);
            $text$translated_text = __( 'Already registered before? Click here to log-in' );
            $match = true;          
        default:
            $match = false;
    }

    // Remove current gettext callback if there's a match
    if( $match )
        remove_filter( current_filter(), __FUNCTION__ );

    return $text;$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.

If we want to have the reset password form to look like this:

reset

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'); 
    return $message;
});


/**
 * Modify 'Log in' text
 */
add_action( 'resetpass_form', function()
{
    add_filter( 'gettext', 'wpse_gettext'); 
});

The wpse_gettext helper function is defined as:

function wpse_gettext( $text )
{
    // Modify gettext if there's a match
    switch ( $text )
    {
        case 'New password' :           
            $text = __( 'Use this password, or type a new one over it' );
            $match = true;
            break;
        case 'Log in' :
            $text = __( 'Already registered before? Click here to log-in' );
            $match = true;          
        default:
            $match = false;
    }

    // Remove current gettext callback if there's a match
    if( $match )
        remove_filter( current_filter(), __FUNCTION__ );

    return $text;
} 

where we remove the filter as soon as it has been used once. We also try to hook into nearby hooks to minimize the number of gettext checks.

If we want to have the reset password form to look like this:

reset

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.

added 6 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

If we want to have the reset password form to look like this:

reset

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'); 
    return $message;
});


/**
 * Modify 'Log in' text
 */
add_action( 'resetpass_form', function()
{
    add_filter( 'gettext', 'wpse_gettext'); 
});

The wpse_gettext helper function is defined as:

function wpse_gettext( $text )
{
    $match = false;

    // Modify gettext if there's a match
    switch ( $text )
    {
        case 'New password' :           
            $text = __( 'Use this password, or type a new one over it';it' );
            $match = true;
            break;
        case 'Log in' :
            $text = __( 'Already registered before? Click here to log-in';in' );
            $match = true;          
        default:
            $match = false;
    }

    // Remove current gettext callback if there's a match
    if( $match )
        remove_filter( current_filter(), __FUNCTION__ );

    return $text;
} 

where we remove the filter as soon as it has been used once. We also try to hook into nearby hooks to minimize the number of gettext checks.

If we want to have the reset password form to look like this:

reset

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'); 
    return $message;
});


/**
 * Modify 'Log in' text
 */
add_action( 'resetpass_form', function()
{
    add_filter( 'gettext', 'wpse_gettext'); 
});

The wpse_gettext helper function is defined as:

function wpse_gettext( $text )
{
    $match = false;

    // Modify gettext if there's a match
    switch ( $text )
    {
        case 'New password' :           
            $text = 'Use this password, or type a new one over it';
            $match = true;
            break;
        case 'Log in' :
            $text = 'Already registered before? Click here to log-in';
            $match = true;          
        default:
    }

    // Remove current gettext callback if there's a match
    if( $match )
        remove_filter( current_filter(), __FUNCTION__ );

    return $text;
} 

where we remove the filter as soon as it has been used once. We also try to hook into nearby hooks to minimize the number of gettext checks.

If we want to have the reset password form to look like this:

reset

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'); 
    return $message;
});


/**
 * Modify 'Log in' text
 */
add_action( 'resetpass_form', function()
{
    add_filter( 'gettext', 'wpse_gettext'); 
});

The wpse_gettext helper function is defined as:

function wpse_gettext( $text )
{
    // Modify gettext if there's a match
    switch ( $text )
    {
        case 'New password' :           
            $text = __( 'Use this password, or type a new one over it' );
            $match = true;
            break;
        case 'Log in' :
            $text = __( 'Already registered before? Click here to log-in' );
            $match = true;          
        default:
            $match = false;
    }

    // Remove current gettext callback if there's a match
    if( $match )
        remove_filter( current_filter(), __FUNCTION__ );

    return $text;
} 

where we remove the filter as soon as it has been used once. We also try to hook into nearby hooks to minimize the number of gettext checks.

added 13 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

If youwe want to have the reset password form to look like this:

reset

then youwe 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_filteradd_action( 'login_message''validate_password_reset', function( $message$errors )
{
    add_filter( 'gettext', 'wpse_gettext'); 
    return $message;
}); 


/**
 * Modify 'Log in' text
 */
add_action( 'resetpass_form', function()
{
    add_filter( 'gettext', 'wpse_gettext'); 
});

where theThe wpse_gettext helper function is defined as:

function wpse_gettext( $text )
{
    $match = false; 

    // Modify gettext if there's a match
    switch ( $text )
    {
        case 'New password' :           
            $text = 'Use this password, or type a new one over it';
            $match = true;
            break;
        case 'Log in' :
            $text = 'Already registered before? Click here to log-in';
            $match = true;          
        default:
    } 

    // Remove current gettext callback if there's a match
    if( $match )
        remove_filter( current_filter(), __FUNCTION__ );

    return $text;
} 

where we remove the filter as soon as it has been used once. We also try to hook into nearby hooks to minimize the number of gettext callsgettext checks.

If you want to have:

reset

then you 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_filter( 'login_message', function( $message )
{
    add_filter( 'gettext', 'wpse_gettext'); 
    return $message;
});

/**
 * Modify 'Log in' text
 */
add_action( 'resetpass_form', function()
{
    add_filter( 'gettext', 'wpse_gettext'); 
});

where the wpse_gettext helper function is defined as:

function wpse_gettext( $text )
{
    $match = false;
    switch ( $text )
    {
        case 'New password' :           
            $text = 'Use this password, or type a new one over it';
            $match = true;
            break;
        case 'Log in' :
            $text = 'Already registered before? Click here to log-in';
            $match = true;          
        default:
    }
    if( $match )
        remove_filter( current_filter(), __FUNCTION__ );

    return $text;
} 

where we remove the filter as soon as it has been used once. We also try to hook into nearby hooks to minimize the number of gettext calls.

If we want to have the reset password form to look like this:

reset

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'); 
    return $message;
}); 


/**
 * Modify 'Log in' text
 */
add_action( 'resetpass_form', function()
{
    add_filter( 'gettext', 'wpse_gettext'); 
});

The wpse_gettext helper function is defined as:

function wpse_gettext( $text )
{
    $match = false; 

    // Modify gettext if there's a match
    switch ( $text )
    {
        case 'New password' :           
            $text = 'Use this password, or type a new one over it';
            $match = true;
            break;
        case 'Log in' :
            $text = 'Already registered before? Click here to log-in';
            $match = true;          
        default:
    } 

    // Remove current gettext callback if there's a match
    if( $match )
        remove_filter( current_filter(), __FUNCTION__ );

    return $text;
} 

where we remove the filter as soon as it has been used once. We also try to hook into nearby hooks to minimize the number of gettext checks.

Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251
Loading