| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.9/wp-content/themes/dt-the7/inc/ |
Upload File : |
<?php
/**
* The7 ReCaptcha class.
*
* @since 7.8.0
*
* @package The7
*/
defined( 'ABSPATH' ) || exit;
/**
* Class The7_ReCaptcha
*/
class The7_ReCaptcha {
/**
* The site key.
*
* @var string
*/
protected $site_key;
/**
* The secret key.
*
* @var string
*/
protected $secret_key;
/**
* The7_ReCaptcha constructor.
*/
public function __construct() {
$this->site_key = (string) of_get_option( 'contact_form_recaptcha_site_key' );
$this->secret_key = (string) of_get_option( 'contact_form_recaptcha_secret_key' );
}
/**
* Return captcha secret key.
*
* @return string
*/
public function get_secret_key() {
return $this->secret_key;
}
/**
* Return captcha site key.
*
* @return string
*/
public function get_site_key() {
return $this->site_key;
}
/**
* Return true if both secret and site keys are set.
*
* @return bool
*/
public function is_active() {
return $this->secret_key && $this->site_key;
}
/**
* Return true if provided token is valid and false otherwise.
*
* @param string $token Google captcha token.
*
* @return bool
*/
public function validate_token( $token ) {
$recaptcha_verify_url = 'https://www.google.com/recaptcha/api/siteverify';
$url = add_query_arg(
array(
'secret' => $this->get_secret_key(),
'response' => rawurlencode( $token ),
),
$recaptcha_verify_url
);
$response = wp_remote_post( esc_url_raw( $url ) );
if ( is_wp_error( $response ) ) {
return false;
}
if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
return false;
}
$response_body = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! isset( $response_body['success'] ) ) {
return false;
}
return (bool) $response_body['success'];
}
/**
* Enqueue google ReCaptcha api js if not enqueued already.
*/
public function enqueue_scripts() {
if ( ! wp_script_is( 'google-recaptcha', 'enqueued' ) ) {
$url = add_query_arg( array( 'render' => 'explicit' ), 'https://www.google.com/recaptcha/api.js' );
wp_enqueue_script( 'google-recaptcha', esc_url_raw( $url ), null, '2.0', true );
}
}
}