如何在使用WordPress的Contact Form 7时捕获reCAPTCHA v3的分数?

huangapple go评论67阅读模式
英文:

How to capture score recaptcha v3 score in wordpress while using contact form 7?

问题

请帮助捕获WordPress中的reCAPTCHA v3分数。

我可以从以下对象中获取分数,但如何从这个对象中获取呢?

$submission = WPCF7_Submission::get_instance();

WPCF7_Submission Object
(
[pocket:protected] => Array
        (
            [recaptcha] => Array
                (
                    [version] => 3.0
                    [threshold] => 0.5
                    [response] => Array
                        (
                            [success] => 1
                            [challenge_ts] => 2023-06-22T10:30:41Z
                            [hostname] => staging.bonoboz.in
                            [score] => 0.9
                            [action] => contactform
                        )

                )

        )

)
英文:

Please help for to capture a recatcha v3 score in worpdress.

I am getting score below object but how to get from this object

$submission = WPCF7_Submission::get_instance();

WPCF7_Submission Object
(
[pocket:protected] => Array
        (
            [recaptcha] => Array
                (
                    [version] => 3.0
                    [threshold] => 0.5
                    [response] => Array
                        (
                            [success] => 1
                            [challenge_ts] => 2023-06-22T10:30:41Z
                            [hostname] => staging.bonoboz.in
                            [score] => 0.9
                            [action] => contactform
                        )

                )

        )

)

答案1

得分: 2

WPCF7_Submission对象包含通过表单提交的数据。recaptcha数组包含reCAPTCHA数据,其中的response数组包含score字段。

您可以像这样访问此分数:

$submission = WPCF7_Submission::get_instance();
if ($submission) {
    $recaptcha = $submission->get_meta('recaptcha');
    if ($recaptcha) {
        $score = $recaptcha['response']['score'];
        // 使用$score进行操作
    }
}

在这段代码中,$submission->get_meta('recaptcha') 从提交中检索recaptcha数据。然后,$recaptcha['response']['score'] 从reCAPTCHA响应中检索分数。现在,$score 包含reCAPTCHA v3的分数。

请注意,此示例假定您正在使用启用并正确配置为使用reCAPTCHA v3的Contact Form 7插件。此外,此代码应放置在适当的位置,以便在表单提交后执行,例如表单提交挂钩或自定义表单处理代码。

英文:

The WPCF7_Submission object contains the data submitted through the form. The recaptcha array contains the reCAPTCHA data, and the response array within it contains the score field.

You can access this score like so:

$submission = WPCF7_Submission::get_instance();
if ($submission) {
    $recaptcha = $submission->get_meta('recaptcha');
    if ($recaptcha) {
        $score = $recaptcha['response']['score'];
        // do something with $score
    }
}

In this code, $submission->get_meta('recaptcha') retrieves the recaptcha data from the submission. Then, $recaptcha['response']['score'] retrieves the score from the reCAPTCHA response. Now, $score contains the reCAPTCHA v3 score.

Please note that this example assumes you're using the Contact Form 7 plugin with the reCAPTCHA module enabled and correctly configured to use reCAPTCHA v3. Also, this code should be placed in an appropriate location where it will be executed after form submission, such as a form submission hook or custom form processing code.

huangapple
  • 本文由 发表于 2023年6月22日 18:33:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76530992.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定