覆盖默认WordPress措辞

时间:2012-09-13 作者:NightHawk

我正在开发一个插件,该插件将密码要求更改为更严格一点,然而,只要有密码字段来创建密码,WordPress的提示现在就不再准确了(例如,密码必须由七个字符组成)。

我如何替换这些提示?是否有一个过滤器/功能可以帮助实现这一点?

2 个回复
最合适的回答,由SO网友:fuxia 整理而成

您可以筛选\'gettext\'.

未测试的示例代码:

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;
    }
}

SO网友:elmino.cz
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\' );
结束

相关推荐

Simple Multilanguage Switcher

首先,我已经安装了以印尼语为默认语言的不同语言的wp,我有计划,想用其他语言翻译,如何简单地转换开关,但保持印尼语为默认语言。具有采购订单文件谢谢你的帮助。。。