AnsPress_reCcaptcha::verify_recaptcha()

Description #

Check reCaptach verification.

Changelog #

VersionDescription
3.0.0Introduced.

Source #

File: addons/free/recaptcha.php

	public static function verify_recaptcha() {
		require_once( ANSPRESS_ADDONS_DIR . '/free/recaptcha/autoload.php' );
		$method = ap_opt( 'recaptcha_method' ) === 'curl' ? new \ReCaptcha\RequestMethod\CurlPost() : 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' );
		$resp = $recaptcha->verify( $captcha_response, $ip );

		if ( $resp->isSuccess() ) {
			do_action( 'ap_form_captcha_verified' );
			return true;
		}

		return false;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment