WPCF7_RECAPTCHA::verify
Метод класса: WPCF7_RECAPTCHA{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$WPCF7_RECAPTCHA = new WPCF7_RECAPTCHA(); $WPCF7_RECAPTCHA->verify( $token );
- $token(обязательный)
- .
Код WPCF7_RECAPTCHA::verify() WPCF7 RECAPTCHA::verify CF7 6.1.4
public function verify( $token ) {
$is_human = false;
if ( empty( $token ) or ! $this->is_active() ) {
return $is_human;
}
$endpoint = 'https://www.google.com/recaptcha/api/siteverify';
if ( apply_filters( 'wpcf7_use_recaptcha_net', false ) ) {
$endpoint = 'https://www.recaptcha.net/recaptcha/api/siteverify';
}
$sitekey = $this->get_sitekey();
$secret = $this->get_secret( $sitekey );
$request = array(
'body' => array(
'secret' => $secret,
'response' => $token,
),
);
$response = wp_remote_post( sanitize_url( $endpoint ), $request );
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return $is_human;
}
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
$this->last_score = $score = isset( $response_body['score'] )
? $response_body['score']
: 0;
$threshold = $this->get_threshold();
$is_human = $threshold < $score;
$is_human = apply_filters( 'wpcf7_recaptcha_verify_response',
$is_human, $response_body );
if ( $submission = WPCF7_Submission::get_instance() ) {
$submission->push( 'recaptcha', array(
'version' => '3.0',
'threshold' => $threshold,
'response' => $response_body,
) );
}
return $is_human;
}