Captcha::sanitize()
Description #
Validate captcha.
Source #
File: addons/recaptcha/recaptcha/class-captcha.php
public function sanitize() { if ( true === $this->sanitized ) { return $this->sanitized_value; } require_once ANSPRESS_ADDONS_DIR . '/recaptcha/recaptcha/autoload.php'; if ( ap_opt( 'recaptcha_method' ) === 'curl' ) { $method = new \ReCaptcha\RequestMethod\CurlPost(); } else { $method = new \ReCaptcha\RequestMethod\Post(); } $recaptcha = new \ReCaptcha\ReCaptcha( trim( ap_opt( 'recaptcha_secret_key' ) ), $method ); $ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); //@codingStandardsIgnoreLine. $captcha_response = ap_sanitize_unslash( 'g-recaptcha-response', 'r' ); $this->response = $recaptcha->verify( $captcha_response, $ip ); $this->sanitized = true; if ( $this->response->isSuccess() ) { $this->sanitized_value = true; } else { $this->add_error( 'captcha', __( 'Failed to verify captcha. Please try again.', 'anspress-question-answer' ) ); $this->sanitized_value = false; } }
Expand full source code Collapse full source code View on GitHub: addons/recaptcha/recaptcha/class-captcha.php:57
Add your comment