私はWooCommerceの登録に関する他の多くの質問にも注意しますが、WooCommerceベンダープラグインやベンダーの登録方法については何も言及していません。woocommerceのベンダー登録にreCAPTCHAを追加する方法
Researchは私がフィールドを追加することができましたし、WooCommerceは登録ページをベンダーにreCAPTCHAのが見え得るために私は2つの間の重要なリンクをしないのですが、私はreCAPTCHAのcodeいくつかの例を発見しました。
wcpv_shortcode_registration_form_process
に上記の例のコードで何かをすることができますか?
/**
* Add reCapcha to the Vendor registration page
*/
function wooc_validate_re_captcha_field($username, $email, $wpErrors)
{
$remoteIP = $_SERVER['REMOTE_ADDR'];
$recaptchaResponse = $_POST['g-recaptcha-response'];
$response = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', [
'body' => [
'secret' => 'PRIVATE KEY HERE !!!',
'response' => $recaptchaResponse,
'remoteip' => $remoteIP
]
]);
$response_code = wp_remote_retrieve_response_code($response);
$response_body = wp_remote_retrieve_body($response);
if ($response_code == 200)
{
$result = json_decode($response_body, true);
if (! $result['success'])
{
switch ($result['error-codes'])
{
case 'missing-input-secret':
case 'invalid-input-secret':
$wpErrors->add('recaptcha', __('<strong>ERROR</strong>: Invalid reCAPTCHA secret key.', 'woocommerce'));
break;
case 'missing-input-response' :
case 'invalid-input-response' :
$wpErrors->add('recaptcha', __('<strong>ERROR</strong>: Please check the box to prove that you are not a robot.', 'woocommerce'));
break;
default:
$wpErrors->add('recaptcha', __('<strong>ERROR</strong>: Something went wront validating the reCAPTCHA.', 'woocommerce'));
break;
}
}
}
else
{
$wpErrors->add('recaptcha_error', __('<strong>Error</strong>: Unable to reach the reCAPTCHA server.', 'woocommerce'));
}
}
add_action('wcpv_shortcode_registration_form_process', 'wooc_validate_re_captcha_field', 10, 3);
私は確かにこれを無駄にしようとしました。
何かお手伝いいただきありがとうございました。