我想在不惹恼用户的情况下保护我的jquery按钮不被机器人攻击,所以我想在其中添加google的不可见的recaptcha。然而,实现并不像我想的那么简单,而且我似乎也做不到。如果有人能向我展示它是如何做到的,那就太好了。附言:我正在做一个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);
https://stackoverflow.com/questions/42173990
复制相似问题