If you need an alternative way, you can always hook into the login_init
and modify the gettext
filter:
add_filter( 'login_init',
function()
{
add_filter( 'gettext', 'wpse_161709', 99, 3 );
}
);
function wpse_161709( $translated_text, $untranslated_text, $domain )
{
$old = "Registration complete. Please check your e-mail.";
$new = "New text here";
if ( $untranslated_text === $old )
{
$translated_text = $new;
remove_filter( current_filter(), __FUNCTION__ );
}
return $translated_text;
}
Update — The WP_Error
class has changed:
There seems to be a change in the definition of the errors
property of the WP_Errors
class:
In WordPress version 3.9 we got this part:
var $errors = array();
but in WordPress version 4.0 it has been changed to:
private $error_data = array();
So the scope of this property has been changed from public to private.
That’s the reason why you can’t modify it directly in WordPress 4.0+.
… but you can instead use the magic __set
and __get
methods of the WP_Error
class introduced in WordPress 4.0.
Then your code example could be modified to:
add_filter( 'wp_login_errors', 'wpse_161709', 10, 2 );
function wpse_161709( $errors, $redirect_to )
{
if( isset( $errors->errors['registered'] ) )
{
// Use the magic __get method to retrieve the errors array:
$tmp = $errors->errors;
// What text to modify:
$old = __('Registration complete. Please check your email.');
$new = 'Your new message';
// Loop through the errors messages and modify the corresponding message:
foreach( $tmp['registered'] as $index => $msg )
{
if( $msg === $old )
$tmp['registered'][$index] = $new;
}
// Use the magic __set method to override the errors property:
$errors->errors = $tmp;
// Cleanup:
unset( $tmp );
}
return $errors;
}
to change this particular error message.
Here are screenshot examples:
Before:
After: