WooCommerce, 實用技巧

Wordfence 干擾影響登入錯誤題示訊息翻譯

Wordfence 干擾影響登入錯誤題示訊息翻譯

對,你沒有看錯,我也沒有寫錯,我今天要說的是「Wordfence」這套安全防火牆外掛影響到了 WooCommerce 的登入錯誤提示訊息,預設 WC 示有翻譯的,但不知道為什麼安裝了 Wordfence 後會影響到該字串的翻譯,都會變強制英文的。

Wordfence 干擾影響登入錯誤題示訊息翻譯
就很莫名其妙,你即使找遍了 WC 的翻譯都是正確無誤的

今天我們只要用 Code Snippets 插入以下程式碼就好了

function uni_wc_login_error_translation( $translated, $original, $domain ) {
    
    switch ($original) {
        case '<strong>ERROR</strong>: The username or password you entered is incorrect. <a href="%2$s" title="Password Lost and Found">Lost your password</a>?':
            $translated = '<strong>錯誤</strong>: 使用者的帳號或者密碼錯誤 <a href="%2$s" title="忘記密碼?">忘記密碼</a>?';
            break;
    }
    
    return $translated;
}

add_filter( 'gettext', 'uni_wc_login_error_translation', 10, 3 );

以上很好理解,就直接抓取那串字串並且翻譯替代:

case ‘<strong>ERROR</strong>: The username or password you entered is incorrect. <a href=”%2$s” title=”Password Lost and Found”>Lost your password</a>?‘:

紅字就是要抓取的字串,今天我們的兇手就是這一串的語法,調整一下

$translated = 後面的就是要翻譯的文字填上

Wordfence 干擾影響登入錯誤題示訊息翻譯

是不是很簡單呢?

相關文章