| 1 |
<?php // Google reCAPTCHA for PHP >= 5.3.0 |
| 2 |
|
| 3 |
// PHP Global space backslash class requires >= 5.3.0 |
| 4 |
|
| 5 |
// Google reCAPTCHA 1.1.3 @ https://github.com/google/recaptcha |
| 6 |
|
| 7 |
// Supports allow_url_fopen/file_get_contents and cURL |
| 8 |
|
| 9 |
if (!defined('ABSPATH')) die(); |
| 10 |
|
| 11 |
require_once('autoload.php'); |
| 12 |
|
| 13 |
if (ini_get('allow_url_fopen')) { |
| 14 |
|
| 15 |
// file_get_contents: allow_url_fopen = on |
| 16 |
$recaptcha = new \ReCaptcha\ReCaptcha($private); |
| 17 |
|
| 18 |
} elseif (extension_loaded('curl')) { |
| 19 |
|
| 20 |
// cURL: allow_url_fopen = off |
| 21 |
$recaptcha = new \ReCaptcha\ReCaptcha($private, new \ReCaptcha\RequestMethod\CurlPost()); |
| 22 |
|
| 23 |
} else { |
| 24 |
|
| 25 |
$recaptcha = null; |
| 26 |
|
| 27 |
error_log('WP Plugin USP: Google reCAPTCHA: allow_url_fopen and curl both disabled!', 0); |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
if (isset($recaptcha)) { |
| 32 |
|
| 33 |
$response = $recaptcha->verify($_POST['g-recaptcha-response'], usp_get_ip_address()); |
| 34 |
|
| 35 |
} else { |
| 36 |
|
| 37 |
$response = null; |
| 38 |
|
| 39 |
error_log('WP Plugin USP: Google reCAPTCHA: $recaptcha variable not set!', 0); |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
if ($response->isSuccess()) { |
| 44 |
|
| 45 |
return true; |
| 46 |
|
| 47 |
} else { |
| 48 |
|
| 49 |
$errors = $response->getErrorCodes(); |
| 50 |
|
| 51 |
if (!empty($errors) && is_array($errors)) { |
| 52 |
|
| 53 |
foreach ($errors as $error) { |
| 54 |
|
| 55 |
// error_log('WP Plugin USP: Google reCAPTCHA: '. $error, 0); |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
} else { |
| 60 |
|
| 61 |
// error_log('WP Plugin USP: Google reCAPTCHA: '. $errors, 0); |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
return false; |