plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { //wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/addonify-recaptcha-for-edd-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { //wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/addonify-recaptcha-for-edd-admin.js', array( 'jquery' ), $this->version, false ); } public function process_login() { if ( ! isset( $_POST['edd_action'] ) || 'user_login' !== $_POST['edd_action'] ) { return; } $is_captcha_valid = $this->recaptcha_process(); if ( ! $is_captcha_valid ) { $_POST['edd_login_nonce'] = false; } } public function recaptcha_process() { if ( empty( $_POST['g-recaptcha-response'] ) ) { edd_set_error( 'empty_captcha', __( 'Please, pass reCAPTCHA validation', 'addonify-recaptcha-for-edd' ) ); return false; } $result = $this->validate_recaptcha(); if ( false === $result ) { edd_set_error( 'fail_captcha', __( 'reCAPTCHA validation failed, please try again', 'addonify-recaptcha-for-edd' ) ); return false; } return true; } private function validate_recaptcha() { $edd_settings = get_option( 'edd_settings' ); $server_secret_key = $edd_settings['addonify_recaptcha_for_edd_server_key']; if ( ! $server_secret_key ) { return false; } $request_args = array( 'response' => $_POST['g-recaptcha-response'], 'secret' => $server_secret_key ); $request = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', array( 'body' => $request_args ) ); $result = json_decode( $request['body'], true ); if ( empty( $result ) || ! $result['success'] ) { return false; } return true; } }