2015-09-24 22 views
-2

所以我正在尋找一種方法來防止特定的電子郵件註冊我的網站上的帳戶。這是一個wordpress.org網站。防止特定的電子郵件註冊Wordpress.org

我試過Ban Hammer插件,但它不起作用。

我不是在尋找評論,但爲網站本身。就像我可以放在functions.php或某個地方的代碼一樣,當這個特定的電子郵件被用來嘗試和註冊我的網站上的帳戶,以獲得一個錯誤。

不是整個電子郵件域,例如@ gmail.com。但是一個特定的電子郵件,例如,[email protected]

任何人都知道該怎麼做?


編輯:我發現這個教程在這裏:http://www.davidtiong.com/block-spam-registrations-on-wordpress/

我試圖在文件的最底部在functions.php中添加該文件正上方的最後>:

function dtwd_blocked_emails($user_email) { 
    $dtwd_blocked_list = array("[email protected]",); 
    $user_email_split = explode('@', $user_email); $user_email_domain = $user_email_split[1]; 

    if (in_array($user_email_domain, $dtwd_blocked_list)) { 
     //Return 1, for detection 
     return 1; 
    } else { 
     //Return 0 for no detection 
     return 0; 
    } 
} 

?而且我還在我的主題的register.php中加入了這個:

elseif (dtwd_blocked_emails($user_email) == 1) { 
    $errors->add('blocked_email', __('<strong>ERROR</strong>: This email is not allowed.')); 
} 

而且我添加了相同的co de在我的主題login.php。

然後我嘗試註冊與此電子郵件帳戶(應該已被鎖住):[email protected]

該網站讓我註冊,它讓我登錄。該電子郵件現在應該已被阻止,並在我嘗試註冊和/或登錄時返回錯誤。

+1

我不打算把它寫你...但你可以考慮掛鉤到像['registration_errors'](https://codex.wordpress.org/Plugin_API/Filter_Reference/registration_errors)動作鉤子,並在那裏做一些驗證。 – rnevius

+0

恩,謝謝Rnevius。我正在查看你發佈的鏈接中的代碼,我認爲這就是我需要的,但我不知道如何爲我的需求製作代碼。任何機會,你可以......寫給我......盡我所能去問? – Overloard

+1

我很樂意幫助你,但你需要先嚐試一下。如果仍然無法正常工作,請通過編輯發佈您嘗試過的(以及出現的問題)[最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve)你原來的問題。 – rnevius

回答

1

我真的不知道該功能應該如何工作(它甚至沒有掛鉤任何東西......)。我沒有測試過這個,但是聽起來像在運行registration_errors過濾器掛鉤時驗證電子郵件一樣簡單。來自Codex:

registration_errors filter hook過濾新用戶註冊時遇到的錯誤。如果在$errors中存在任何錯誤,則會中止用戶的註冊。

這聽起來和你想要做的完全一樣(如果用戶電子郵件在你的黑名單中,註銷會中止)。同樣,這種未經過測試的,但我會嘗試像在的functions.php如下:

function so_32767928_blacklisted_user($errors, $sanitized_user_login, $user_email) { 

    // One or more blacklisted emails to validate against 
    $blacklist = array('[email protected]',); 

    // If the user trying to register is in the blacklist, add an error message 
    if (in_array($user_email, $blacklist)) { 
     $errors->add('blacklist_error', '<strong>ERROR</strong>: This email is not allowed to register on this site.'); 
    } 

    // Always return $errors, even if there are none 
    return $errors; 
} 
add_filter('registration_errors', 'so_32767928_blacklisted_user', 10, 3); 
+0

非常感謝你Rnevius。那就是訣竅。完美的作品。非常感謝你:) – Overloard

+1

不客氣。只是一個筆記......任何時候你需要「破壞」WordPress動作的正常流程,通常都會有一個動作鉤子或過濾器鉤子來執行此操作。這些改變幾乎總是在* functions.php *中完成,需要幾個參數並返回修改後的變量。乾杯。 – rnevius