handling multiple instances of reCaptcha

This commit is contained in:
Amine Ben hammou
2017-12-27 14:59:28 +00:00
parent a8052c118a
commit c63b7d9b91
4 changed files with 36 additions and 15 deletions

View File

@ -90,13 +90,13 @@ class Subscribers extends APIEndpoint {
));
}
if(!empty($recaptcha['enabled']) && $recaptcha['enabled'] && !isset($data['recaptcha'])) {
if(!empty($recaptcha['enabled']) && !isset($data['recaptcha'])) {
return $this->badRequest(array(
APIError::BAD_REQUEST => __('Please check the captcha.', 'mailpoet')
));
}
if(!empty($recaptcha['enabled']) && $recaptcha['enabled']) {
if(!empty($recaptcha['enabled'])) {
$res = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', array(
'body' => array(
'secret' => $recaptcha['secret_token'],
@ -109,7 +109,7 @@ class Subscribers extends APIEndpoint {
));
}
$res = json_decode(wp_remote_retrieve_body($res));
if(empty($res) || !$res->success) {
if(empty($res->success)) {
return $this->badRequest(array(
APIError::BAD_REQUEST => __('Error while validating the captcha.', 'mailpoet')
));