Skip to content

Instantly share code, notes, and snippets.

@andresclua
Created December 17, 2023 19:23
Show Gist options
  • Save andresclua/66b320e64857e0a3349411fbbefad4b4 to your computer and use it in GitHub Desktop.
Save andresclua/66b320e64857e0a3349411fbbefad4b4 to your computer and use it in GitHub Desktop.
recaptcha server php wp
add_action('wp_ajax_nopriv_recaptcha_validate', 'recaptcha_validate');
add_action('wp_ajax__loremrecaptcha_validate', 'recaptcha_validate');
function recaptcha_validate() {
$recaptcha_client_token = $_REQUEST["google_access_token"];
$SECRET_KEY = 'private token';
$responseGoogleRecaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$SECRET_KEY."&response=".$recaptcha_client_token);
$responseGoogleRecaptcha = json_decode($responseGoogleRecaptcha,true);
// $other = $_REQUEST["per_page"];
$response = [
"state" => 'recaptcha_validate',
"client_token"=> $google_access_token,
"server_response" => $responseGoogleRecaptcha,
];
echo json_encode($response);
/**
* Always finish with wp_die();
*/
wp_die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment