/** * Validates challenge. * * @param array Challenge response data. * * @return mixed */ public function validate_challenge(array $data) { $response = array('success' => true); if (empty($data['recaptcha_challenge_field']) || empty($data['recaptcha_response_field'])) { $response['message'] = Ai1ec_I18n::_('There was an error reading the human verification data. Please try again.'); $response['success'] = false; } require_once AI1EC_VENDOR_PATH . 'recaptcha/recaptchalib.php'; $resp = recaptcha_check_answer($this->_settings->get('google_recaptcha_private_key'), $_SERVER['REMOTE_ADDR'], $data['recaptcha_challenge_field'], $data['recaptcha_response_field']); if (!$resp->is_valid) { $response['message'] = Ai1ec_I18n::__('Please try verifying you are human again.'); $response['success'] = false; } return $response; }
/** * Validates challenge. * * @param array Challenge response data. * * @return mixed */ public function validate_challenge(array $data) { $response['message'] = Ai1ec_I18n::__('Please try verifying you are human again.'); $response['success'] = false; if (empty($data['g-recaptcha-response'])) { $response['message'] = Ai1ec_I18n::_('There was an error reading the human verification data. Please try again.'); $response['success'] = false; } $url = add_query_arg(array('secret' => $this->_settings->get('google_nocaptcha_private_key'), 'response' => $data['g-recaptcha-response']), 'https://www.google.com/recaptcha/api/siteverify'); $json_resp = wp_remote_get($url); if (is_wp_error($json_resp)) { return $response; } $resp = json_decode($json_resp['body'], true); if (isset($resp['success']) && $resp['success']) { $response = array('success' => true); } return $response; }