如果您需要另一种方法,您可以随时使用login_init
并修改gettext
过滤器:
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;
}
更新-更新
WP_Error
类已更改:的定义似乎有所更改
errors
的属性
WP_Errors
类别:
在WordPress中version 3.9 我们得到了这个部分:
var $errors = array();
但在WordPress中
version 4.0 已更改为:
private $error_data = array();
因此,此属性的范围已从公共更改为私有。
这就是为什么你can\'t modify it 直接在WordPress 4.0+。
。。。但是你可以使用魔法__set
和__get
方法WP_Error
班introduced 在WordPress 4.0中。
然后您的代码示例可以修改为:
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;
}
更改此特定错误消息。
以下是截图示例:
一零
九
After:
