init_settings(); $this->hooks(); } /** * Init CAPTCHA settings. * * @since 1.6.4 */ public function init_settings() { $this->settings = wp_parse_args( wpforms_get_captcha_settings(), [ 'provider' => 'none' ] ); } /** * Hooks. * * @since 1.6.4 */ public function hooks() { add_filter( 'wpforms_settings_tabs', [ $this, 'register_settings_tabs' ], 5, 1 ); add_filter( 'wpforms_settings_defaults', [ $this, 'register_settings_fields' ], 5, 1 ); add_action( 'wpforms_settings_updated', [ $this, 'updated' ] ); add_action( 'wpforms_settings_enqueue', [ $this, 'enqueues' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'apply_noconflict' ], 9999 ); } /** * Register CAPTCHA settings tab. * * @since 1.6.4 * * @param array $tabs Admin area tabs list. * * @return array */ public function register_settings_tabs( $tabs ) { $captcha = [ self::VIEW => [ 'name' => esc_html__( 'CAPTCHA', 'wpforms-lite' ), 'form' => true, 'submit' => esc_html__( 'Save Settings', 'wpforms-lite' ), ], ]; return wpforms_array_insert( $tabs, $captcha, 'email' ); } /** * Register CAPTCHA settings fields. * * @since 1.6.4 * * @param array $settings Admin area settings list. * * @return array */ public function register_settings_fields( $settings ) { $settings[ self::VIEW ] = [ self::VIEW . '-heading' => [ 'id' => self::VIEW . '-heading', 'content' => '
' . esc_html__( 'A CAPTCHA is an anti-spam technique which helps to protect your website from spam and abuse while letting real people pass through with ease. WPForms supports two popular services.', 'wpforms-lite' ) . '
', 'type' => 'content', 'no_label' => true, 'class' => [ 'wpforms-setting-captcha-heading', 'section-heading' ], ], self::VIEW . '-provider' => [ 'id' => self::VIEW . '-provider', 'type' => 'radio', 'default' => 'recaptcha', 'options' => [ 'hcaptcha' => esc_html__( 'hCaptcha', 'wpforms-lite' ), 'recaptcha' => esc_html__( 'reCAPTCHA', 'wpforms-lite' ), 'none' => esc_html__( 'None', 'wpforms-lite' ), ], 'desc' => wp_kses( /* translators: %s - WPForms.com CAPTCHA comparison page URL. */ __( 'Not sure which service is right for you? Check out our comparison for more details.', 'wpforms-lite' ), [ 'a' => [ 'href' => [], 'target' => [], 'rel' => [], ], ] ), ], 'recaptcha-heading' => [ 'id' => 'recaptcha-heading', 'content' => $this->get_recaptcha_field_desc(), 'type' => 'content', 'no_label' => true, 'class' => [ 'wpforms-setting-recaptcha', 'section-heading' ], ], 'hcaptcha-heading' => [ 'id' => 'hcaptcha-heading', 'content' => $this->get_hcaptcha_field_desc(), 'type' => 'content', 'no_label' => true, 'class' => [ 'section-heading' ], ], 'recaptcha-type' => [ 'id' => 'recaptcha-type', 'name' => esc_html__( 'Type', 'wpforms-lite' ), 'type' => 'radio', 'default' => 'v2', 'options' => [ 'v2' => esc_html__( 'Checkbox reCAPTCHA v2', 'wpforms-lite' ), 'invisible' => esc_html__( 'Invisible reCAPTCHA v2', 'wpforms-lite' ), 'v3' => esc_html__( 'reCAPTCHA v3', 'wpforms-lite' ), ], 'class' => [ 'wpforms-setting-recaptcha' ], ], 'recaptcha-site-key' => [ 'id' => 'recaptcha-site-key', 'name' => esc_html__( 'Site Key', 'wpforms-lite' ), 'type' => 'text', ], 'hcaptcha-site-key' => [ 'id' => 'hcaptcha-site-key', 'name' => esc_html__( 'Site Key', 'wpforms-lite' ), 'type' => 'text', ], 'recaptcha-secret-key' => [ 'id' => 'recaptcha-secret-key', 'name' => esc_html__( 'Secret Key', 'wpforms-lite' ), 'type' => 'text', ], 'hcaptcha-secret-key' => [ 'id' => 'hcaptcha-secret-key', 'name' => esc_html__( 'Secret Key', 'wpforms-lite' ), 'type' => 'text', ], 'recaptcha-fail-msg' => [ 'id' => 'recaptcha-fail-msg', 'name' => esc_html__( 'Fail Message', 'wpforms-lite' ), 'desc' => esc_html__( 'Displays to users who fail the verification process.', 'wpforms-lite' ), 'type' => 'text', 'default' => esc_html__( 'Google reCAPTCHA verification failed, please try again later.', 'wpforms-lite' ), ], 'hcaptcha-fail-msg' => [ 'id' => 'hcaptcha-fail-msg', 'name' => esc_html__( 'Fail Message', 'wpforms-lite' ), 'desc' => esc_html__( 'Displays to users who fail the verification process.', 'wpforms-lite' ), 'type' => 'text', 'default' => esc_html__( 'hCaptcha verification failed, please try again later.', 'wpforms-lite' ), ], 'recaptcha-v3-threshold' => [ 'id' => 'recaptcha-v3-threshold', 'name' => esc_html__( 'Score Threshold', 'wpforms-lite' ), 'desc' => esc_html__( 'reCAPTCHA v3 returns a score (1.0 is very likely a good interaction, 0.0 is very likely a bot). If the score less than or equal to this threshold, the form submission will be blocked and the message above will be displayed.', 'wpforms-lite' ), 'type' => 'number', 'attr' => [ 'step' => '0.1', 'min' => '0.0', 'max' => '1.0', ], 'default' => esc_html__( '0.4', 'wpforms-lite' ), 'class' => 'recaptcha' === $this->settings['provider'] && 'v3' === $this->settings['recaptcha_type'] ? [ 'wpforms-setting-recaptcha' ] : [ 'wpforms-setting-recaptcha', 'wpforms-hidden' ], ], 'recaptcha-noconflict' => [ 'id' => 'recaptcha-noconflict', 'name' => esc_html__( 'No-Conflict Mode', 'wpforms-lite' ), 'desc' => esc_html__( 'Check this option to forcefully remove other CAPTCHA occurrences in order to prevent conflicts. Only enable this option if your site is having compatibility issues or instructed by support.', 'wpforms-lite' ), 'type' => 'checkbox', ], self::VIEW . '-preview' => [ 'id' => self::VIEW . '-preview', 'name' => esc_html__( 'Preview', 'wpforms-lite' ), 'content' => '' . esc_html__( 'Please save settings to generate a preview of your CAPTCHA here.', 'wpforms-lite' ) . '
', 'type' => 'content', 'class' => [ 'wpforms-hidden' ], ], ]; if ( 'hcaptcha' === $this->settings['provider'] || ( 'recaptcha' === $this->settings['provider'] && 'v2' === $this->settings['recaptcha_type'] ) ) { $data = apply_filters( 'wpforms_admin_pages_settings_captcha_data', [ 'sitekey' => $this->settings['site_key'] ] ); // Prepare HTML for CAPTCHA preview. $placeholder_descr = $settings[ self::VIEW ][ self::VIEW . '-preview' ]['content']; $captcha_descr = esc_html__( 'This CAPTCHA is generated using your site and secret keys. If an error is displayed, please double-check your keys.', 'wpforms-lite' ); $captcha_preview = sprintf( '%2$s