是否更改登录错误消息?Cookie错误消息

时间:2018-06-13 作者:joq3

我尝试过搜索这个,我发现可以使用钩子更改登录错误消息。但我找不到如何更改此错误消息:

错误:浏览器阻止或不支持Cookie。您必须启用Cookie才能使用WordPress。

如果禁用了Cookie,并且您尝试登录,则会显示此消息。如何自定义此文本?

非常感谢。

1 个回复
SO网友:Krzysiek Dróżdż

此文本硬编码为wp-login.php 文件(第886行):

$user = new WP_Error( \'test_cookie\', sprintf( __( \'<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href="%s">enable cookies</a> to use WordPress.\' ),
                __( \'https://codex.wordpress.org/Cookies\' ) ) );
正如您所见,没有用于生成它的过滤器。。。几乎没有过滤器。为什么几乎?因为它是经过翻译的,这意味着你可以使用gettext 筛选以修改它。

function my_change_cookies_disabled_error( $translated_text, $text, $domain ) {
    $default = \'<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href="%s">enable cookies</a> to use WordPress.\';

    if ( $translated_text == $default ) {
        $translated_text = __( \'<strong>ERROR</strong>: My error message\', \'my_text_domain\' );
    }

    return $translated_text;
}
add_filter( \'gettext\', \'my_change_cookies_disabled_error\', 20, 3 );

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register