WP登录页面上的Google ReCaptcha

时间:2020-01-03 作者:Robert Joodat

新年快乐!

只是想知道是否有人知道我们如何在WP登录页面上使用Google reCaptcha?

v2或v3

2 个回复
SO网友:Rajnish Suvagiya

新年快乐。

以下是此插件:https://wordpress.org/plugins/login-recaptcha/

请检查。我相信你能满足你的要求。

SO网友:Will Ashworth

对于插件,一定要考虑Login No Captcha reCAPTCHA by Robert Peake.

如果你想在不引入其他插件的情况下将一些东西加入到你的主题中,那么Megan at Megabytecreated an article.

<?php
/**
* These Functions Add and Verify the Invisible Google reCAPTCHA on Login
*/

add_action(\'login_enqueue_scripts\', \'login_recaptcha_script\');

function login_recaptcha_script() {
wp_register_script(\'recaptcha_login\', \'https://www.google.com/recaptcha/api.js\');


wp_enqueue_script(\'recaptcha_login\')


}



add_action( \'login_form\', \'display_recaptcha_on_login\' );

function display_recaptcha_on_login() {
echo "<script>
function onSubmit(token) {
document.getElementById(\'loginform\').submit();
}
</script>
<button class=\'g-recaptcha\' data-sitekey=\'YOUR_PUBLIC_KEY\' data-callback=\'onSubmit\' data-size=\'invisible\' style=\'display:none;\'>Submit</button>";


}



add_filter(\'wp_authenticate_user\', \'verify_recaptcha_on_login\', 10, 2);

function verify_recaptcha_on_login($user, $password) {

if (isset($_POST[\'g-recaptcha-response\'])) {
$response = wp_remote_get( \'https://www.google.com/recaptcha/api/siteverify?secret=YOUR_SECRET_KEY&response=\' . $_POST[\'g-recaptcha-response\'] );


$response = json_decode($response[\'body\'], true);


if (true == $response[\'success\']) {


return $user;


} else {


// FIXME: This one fires if your password is incorrect... Check if password was incorrect before returning this error...


// return new WP_Error( \'Captcha Invalid\', __(\'<strong>ERROR</strong>: You are a bot\') );


}


} else {


return new WP_Error( \'Captcha Invalid\', __(\'<strong>ERROR</strong>: You are a bot. If not then enable JavaScript.\') );


}


}

相关推荐

是否可以在注册后修改USER_LOGIN?

我想让用户可以通过个人资料更新他的个人资料。php页面。但我注意到数据库中标记为user\\u login的字段没有更新。我四处搜索,他们说WordPress没有提供修改它的可能性,是真的吗?我当前正在使用此代码更新各种用户字段://Sanitize POST Array $POST = filter_var_array($_POST, FILTER_SANITIZE_STRING); $nome = $POST[\'nome\']; $cognome = $POST[\