name = esc_html__( 'Captcha', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'captcha_provider' => 'recaptcha', 'captcha_alignment' => 'left', 'captcha_type' => 'v2_checkbox', 'hcaptcha_type' => 'hc_checkbox', 'score_threshold' => '0.5', 'captcha_badge' => 'bottomright', 'hc_invisible_notice' => sprintf( /* translators: 1. Open tag for Privacy policy, 2. Close , 3. Open tag for Terms of Service, 4. Close . */ esc_html__( 'This site is protected by hCaptcha and its %1$sPrivacy Policy%2$s and %3$sTerms of Service%4$s apply.', 'forminator' ), '', '', '', '' ), 'recaptcha_error_message' => esc_html__( 'reCAPTCHA verification failed. Please try again.', 'forminator' ), 'hcaptcha_error_message' => esc_html__( 'hCaptcha verification failed. Please try again.', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Invisible recaptcha * * @param mixed $field Field. * @return mixed */ public function is_invisible_recaptcha( $field ) { // backward. $is_invisible = self::get_property( 'invisible_captcha', $field ); $is_invisible = filter_var( $is_invisible, FILTER_VALIDATE_BOOLEAN ); if ( ! $is_invisible ) { $type = self::get_property( 'captcha_type', $field, '' ); if ( 'invisible' === $type || 'v3_recaptcha' === $type || 'v2_invisible' === $type ) { $is_invisible = true; } } return $is_invisible; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $extra_attrs = ''; $hcaptcha_notice = ''; $provider = self::get_property( 'captcha_provider', $field, 'recaptcha' ); $alignment = self::get_property( 'captcha_alignment', $field, 'left' ); if ( 'recaptcha' === $provider ) { $captcha_type = self::get_property( 'captcha_type', $field, 'v3_recaptcha' ); $captcha_theme = self::get_property( 'captcha_theme', $field, 'light' ); $captcha_size = self::get_property( 'captcha_size', $field, 'normal' ); $captcha_class = 'forminator-captcha-' . $alignment . ' forminator-g-recaptcha'; if ( $this->is_invisible_recaptcha( $field ) ) { $extra_attrs = 'data-badge="' . esc_attr( self::get_property( 'captcha_badge', $field, 'inline' ) ) . '"'; $captcha_size = 'invisible'; $captcha_class .= ' recaptcha-invisible'; } switch ( $captcha_type ) { case 'v2_checkbox': $key = get_option( 'forminator_captcha_key', '' ); break; case 'v2_invisible': $key = get_option( 'forminator_v2_invisible_captcha_key', '' ); break; case 'v3_recaptcha': $key = get_option( 'forminator_v3_captcha_key', '' ); break; } } elseif ( 'turnstile' === $provider ) { $captcha_class = 'forminator-captcha-' . $alignment . ' forminator-turnstile'; $key = get_option( 'forminator_turnstile_key', '' ); $captcha_theme = self::get_property( 'turnstile_theme', $field, 'auto' ); $captcha_size = self::get_property( 'turnstile_size', $field, 'normal' ); $extra_attrs = 'data-language="' . esc_attr( self::get_captcha_language( $field, 'turnstile' ) ) . '"'; } else { $key = get_option( 'forminator_hcaptcha_key', '' ); $captcha_type = self::get_property( 'hcaptcha_type', $field, 'hc_checkbox' ); $captcha_theme = self::get_property( 'hcaptcha_theme', $field, 'light' ); $captcha_size = self::get_property( 'hcaptcha_size', $field, 'normal' ); $captcha_class = 'forminator-captcha-' . $alignment . ' forminator-hcaptcha'; if ( 'hc_invisible' === $captcha_type ) { $captcha_size = 'invisible'; $hcaptcha_notice = self::get_property( 'hc_invisible_notice', $field, '' ); $hcaptcha_notice = sprintf( '