* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved. * @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html * * @website http://www.wpopal.com * @support http://www.wpopal.com/support/forum.html */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * @class OpalEstate_Nocaptcha_Recaptcha * * @version 1.0 */ class OpalEstate_Nocaptcha_Recaptcha { /** * OpalEstate_Nocaptcha_Recaptcha constructor. */ public function __construct() { if ( is_admin() ) { add_filter( 'opalestate_settings_3rd_party_subtabs_nav', [ $this, 'admin_tab_setting' ] ); add_filter( 'opalestate_settings_3rd_party_subtabs_google_captcha_page_fields', [ $this, 'admin_content_setting' ] ); } if ( opalestate_options( 'show_captcha' ) == 'on' ) { define( 'WPOPAL_CAPTCHA_LOAED', true ); $this->theme = opalestate_options( 'captcha_theme', 'light' ); add_action( 'wp_head', [ $this, 'add_custom_styles' ] ); add_action( 'opalestate_message_form_after', [ __CLASS__, 'show_captcha' ] ); add_action( 'opalestate_process_send_email_before', [ __CLASS__, 'ajax_verify_captcha' ] ); } } /** * */ public function add_custom_styles() { $lang = null; echo '' . "\r\n"; } /** * */ public static function show_captcha() { if ( isset( $_GET['captcha'] ) && $_GET['captcha'] == 'failed' ) { } echo '
'; } /** * */ public static function ajax_verify_captcha() { $response = isset( $_POST['g-recaptcha-response'] ) ? esc_attr( $_POST['g-recaptcha-response'] ) : ''; $remote_ip = $_SERVER["REMOTE_ADDR"]; // make a GET request to the Google reCAPTCHA Server $request = wp_remote_get( 'https://www.google.com/recaptcha/api/siteverify?secret=' . opalestate_options( 'secret_key' ) . '&response=' . $response . '&remoteip=' . $remote_ip ); // get the request response body $response_body = wp_remote_retrieve_body( $request ); $result = json_decode( $response_body, true ); if ( isset( $result['hostname'] ) && ! empty( $result['hostname'] ) && empty( $result['success'] ) ) { $result['success'] = 1; } if ( ! $result['success'] ) { $return = [ 'status' => false, 'msg' => esc_html__( 'The captcha is not verified, please try again!', 'opalestate-pro' ) ]; echo json_encode( $return ); die(); } } /** * */ public function admin_content_setting( $fields ) { $fields = apply_filters( 'opalestate_settings_google_captcha', [ [ 'name' => esc_html__( 'Show Captcha In Form', 'opalestate-pro' ), 'desc' => __( 'Enable google captch in contact , register form. After Set yes, you change setting in Google Captcha Tab. Register here: https://www.google.com/recaptcha/admin Version 2', 'opalestate-pro' ), 'id' => 'show_captcha', 'type' => 'switch', 'options' => [ 'off' => esc_html__( 'No', 'opalestate-pro' ), 'on' => esc_html__( 'Yes', 'opalestate-pro' ), ], 'default' => 'on', ], [ 'name' => esc_html__( 'Google Captcha page Settings', 'opalestate-pro' ), 'desc' => '