gpt4 book ai didi

javascript - 如何使用 Invisible reCaptcha 保护 jquery 按钮?

转载 作者:IT王子 更新时间:2023-10-29 00:18:24 24 4
gpt4 key购买 nike

我想保护我的 jquery 按钮免受机器人的攻击而不打扰用户,所以我想向它添加 google 的不可见 recaptcha。然而,实现并不像我那么容易,而且我似乎做不到。如果有人能告诉我它是如何完成的,那就太好了。 PS:我是在 wordpress 主题上做的。

这是文档:

https://developers.google.com/recaptcha/docs/invisible

创建不可见的 recaptcha:

https://www.google.com/recaptcha/admin#beta

这就是我所拥有的:

HTML:

<button class="acf-get-content-button">Show Link</button>
<div class="fa" id="acf-content-wrapper" data-id="<?php echo $post_id; ?>"></div>

JS:

<script>
(function($) {
$('.acf-get-content-button').click(function(e) {
e.preventDefault();
$('.fa').addClass('fa-cog fa-spin fa-4x');
var $contentWrapper = $('#acf-content-wrapper');
var postId = $contentWrapper.data('id');

$.ajax({
url: "/public/ajax.php",
type: "POST",
data: {
'post_id': postId
},
})
.done(function(data) {
$('.fa').removeClass('fa-cog fa-spin fa-4x');
$contentWrapper.append(data);
$('.acf-get-content-button').removeClass().addClass('.acf-get-content-button')
});
});
$('.acf-get-content-button').mouseup(function() {
if (event.which == 1) {
$(".acf-get-content-button").hide();
}
});
})(jQuery);
</script>

ajax.php

<?php
define('WP_USE_THEMES', false);
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
global $post;
$post_id = $_REQUEST["post_id"];
$content = get_field( 'ebook_link_pdf', $post_id );
echo ($content);

最佳答案

您可以使用 Invisible reCaptcha for WordPress如果您认为从头开始编码对您来说很复杂,可以使用插件轻松完成。您还可以深入了解插件的源代码以了解其实现。

此插件具有自定义使用的操作和过滤器,这些都记录在插件主页上。

关于javascript - 如何使用 Invisible reCaptcha 保护 jquery 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42173990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com