wpcf7_turnstile_verify_response()CF7 1.0

Verifies the Turnstile response token.

Хуков нет.

Возвращает

true|false. True if the submitter is a bot, false if a human.

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

wpcf7_turnstile_verify_response( $spam, $submission );
$spam(true|false) (обязательный)
The spam/ham status inherited from preceding callbacks.
$submission(WPCF7_Submission) (обязательный)
The submission object.

Код wpcf7_turnstile_verify_response() CF7 6.1.6

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

	$service = WPCF7_Turnstile::get_instance();

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

	$token = wpcf7_superglobal_post( '_wpcf7_turnstile_response' );

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

		if ( '' === $token ) {
			$submission->add_spam_log( array(
				'agent' => 'turnstile',
				'reason' => __( 'Turnstile token is empty.', 'contact-form-7' ),
			) );
		} else {
			$submission->add_spam_log( array(
				'agent' => 'turnstile',
				'reason' => __( 'Turnstile validation failed.', 'contact-form-7' ),
			) );
		}
	}

	return $spam;
}