wpcf7_recaptcha_verify_response()CF7 1.0

Verifies reCAPTCHA token on the server side.

Хуков нет.

Возвращает

null. Ничего (null).

Использование

wpcf7_recaptcha_verify_response( $spam, $submission );
$spam (обязательный)
-
$submission (обязательный)
-

Код wpcf7_recaptcha_verify_response() CF7 5.9.3

function wpcf7_recaptcha_verify_response( $spam, $submission ) {
	if ( $spam ) {
		return $spam;
	}

	$service = WPCF7_RECAPTCHA::get_instance();

	if ( ! $service->is_active() ) {
		return $spam;
	}

	$token = trim( $_POST['_wpcf7_recaptcha_response'] ?? '' );

	if ( $service->verify( $token ) ) { // Human
		$spam = false;
	} else { // Bot
		$spam = true;

		if ( '' === $token ) {
			$submission->add_spam_log( array(
				'agent' => 'recaptcha',
				'reason' => __(
					'reCAPTCHA response token is empty.',
					'contact-form-7'
				),
			) );
		} else {
			$submission->add_spam_log( array(
				'agent' => 'recaptcha',
				'reason' => sprintf(
					__(
						'reCAPTCHA score (%1$.2f) is lower than the threshold (%2$.2f).',
						'contact-form-7'
					),
					$service->get_last_score(),
					$service->get_threshold()
				),
			) );
		}
	}

	return $spam;
}