如何为WP表单创建自定义蜜罐?

发布于 2025-02-12 17:34:53 字数 915 浏览 3 评论 0原文

我在WordPress上使用WP表单,并希望添加一个自定义的蜜罐作为防止垃圾邮件涌入的额外保护层。

为了以简单有效的方式实现这一目标,我以隐藏的形式创建了一个名称字段display:none; - 因此,从理论上讲,这应该意味着,如果此字段被填写,那么它很可能总是被垃圾邮件。

我相信我有这个工作,但是我注意到这种形式不再提交,而不管隐藏的名称字段True或False是什么。

我不确定是由于最近使用WP表单插件的更新或我使用的功能的问题。

有人知道如何实现这一目标还是建议这样做任何问题?

感谢

function forms_custom_honeypot( $honeypot, $fields, $entry, $form_data ) {
    $honeypot_class = 'fancy-name-field';

    $honey_field = false;

    foreach( $form_data['fields'] as $form_field ) {
        if( false !== strpos( $form_field['css'], $honeypot_class ) ) {
            $honey_field = absint( $form_field['id'] );
        }
    }

    if( !empty( $entry['fields'][$honey_field] ) ) {
        $honeypot = 'Custom honeypot';
    }

    return $honeypot;

}
add_filter( 'wpforms_process_honeypot', 'forms_custom_honeypot', 10, 4 );

@billerickson的Form_custom_honeypot。

I use WP Forms on WordPress, and I'm looking to add a custom honeypot as an extra layer of protection against an influx of spam.

In an attempt to achieve this in a simple and effective, I've created a name field in the form which is hidden display: none; - So in theory this should mean, If this field gets filled in, then it's most likely always going to be spam.

I believe I had this working, but it's come to my attention the form is no longer submitting regardless of the hidden name field true or false.

I'm unsure if it's due to a recent update with WP Forms plugin or an issue with the function I was using.

Does anybody know how to achieve this or advise any issues with this?

Thanks

function forms_custom_honeypot( $honeypot, $fields, $entry, $form_data ) {
    $honeypot_class = 'fancy-name-field';

    $honey_field = false;

    foreach( $form_data['fields'] as $form_field ) {
        if( false !== strpos( $form_field['css'], $honeypot_class ) ) {
            $honey_field = absint( $form_field['id'] );
        }
    }

    if( !empty( $entry['fields'][$honey_field] ) ) {
        $honeypot = 'Custom honeypot';
    }

    return $honeypot;

}
add_filter( 'wpforms_process_honeypot', 'forms_custom_honeypot', 10, 4 );

Credit to @billerickson for forms_custom_honeypot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一张白纸 2025-02-19 17:34:53

只是想提供一个快速更新,我设法通过现在使用WPFORMS来解决的自定义蜜罐代码解决了问题。

答案是,自定义蜜罐是将wpform上的名称的第一个设置设置为第一个名称,然后它行不通。但是,一旦更改为简单的文本字段,它可以正常运行,并且记录正常。

因此,如果您正在关注上述工作,那么Bill的建议是始终使用“文本”字段,并避免误报给它一个标签,而不是名称或电子邮件,因为某些用户会让浏览器预先填写这些标签。

​src =“ https://i.sstatic.net/mzta4.png” alt =“在此处输入图像说明”>

Just wanted to provide a quick update that I managed to solve the issue with the custom honeypot code working now with WPForms.

Answer is that the custom honeypot was setup as a First Last with Name on WPForms then it doens’t work. However, once changed back to simple text field it works fine and logs fine.

So, if you're following the work above, then Bill's recommendation is to always use the "Text" field and to avoid false positives give it a label that is not name or email because some users will let the browser pre-fill those in.

enter image description here

我是有多爱你 2025-02-19 17:34:53

只是在这里报告,我已经在网站上成功使用了Bill的脚本很长时间了,但是它似乎与我正在使用完整网站编辑主题的新网站无法使用。我认为这是FSE的东西,而不是WP 6的东西,因为运行6+的旧网站正常工作。

Just here to report I've used Bill's script successfully on sites for a long time, but it seems to not work with new sites I'm making with a Full Site Editing theme. I think it's a FSE thing rather than a WP 6 thing because old sites running 6+ are working fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文