PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.3
3.6.0 3.5.3 3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / fields / class-evf-field-turnstile.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 1 week ago class-evf-field-ai.php 1 year ago class-evf-field-captcha.php 1 month ago class-evf-field-checkbox.php 3 months ago class-evf-field-color.php 1 month ago class-evf-field-country.php 3 months ago class-evf-field-credit-card.php 1 month ago class-evf-field-date-time.php 1 month ago class-evf-field-divider.php 2 years ago class-evf-field-email.php 1 year ago class-evf-field-file-upload.php 1 year ago class-evf-field-first-name.php 1 year ago class-evf-field-hcaptcha.php 5 months ago class-evf-field-hidden.php 1 year ago class-evf-field-html.php 10 months ago class-evf-field-image-upload.php 1 year ago class-evf-field-last-name.php 1 year ago class-evf-field-likert.php 1 year ago class-evf-field-lookup.php 1 month ago class-evf-field-number.php 1 year ago class-evf-field-password.php 1 month ago class-evf-field-payment-authorize-net.php 1 month ago class-evf-field-payment-checkbox.php 1 month ago class-evf-field-payment-coupon.php 1 month ago class-evf-field-payment-gateway-selector.php 1 month ago class-evf-field-payment-quantity.php 1 month ago class-evf-field-payment-radio.php 1 month ago class-evf-field-payment-single.php 1 month ago class-evf-field-payment-square.php 2 years ago class-evf-field-payment-subscription-plan.php 1 month ago class-evf-field-payment-subtotal.php 1 month ago class-evf-field-payment-total.php 1 month ago class-evf-field-phone.php 1 year ago class-evf-field-privacy-policy.php 3 months ago class-evf-field-private-note.php 1 year ago class-evf-field-progress.php 1 month ago class-evf-field-radio.php 3 months ago class-evf-field-range-slider.php 1 month ago class-evf-field-rating.php 3 months ago class-evf-field-recaptcha.php 5 months ago class-evf-field-repeater.php 1 month ago class-evf-field-reset.php 1 month ago class-evf-field-scale-rating.php 1 year ago class-evf-field-select.php 1 year ago class-evf-field-signature.php 1 month ago class-evf-field-text.php 1 year ago class-evf-field-textarea.php 1 year ago class-evf-field-title.php 2 years ago class-evf-field-turnstile.php 5 months ago class-evf-field-url.php 1 year ago class-evf-field-wysiwyg.php 3 months ago class-evf-field-yes-no.php 1 year ago payment-amount-helpers.php 1 month ago
class-evf-field-turnstile.php
150 lines
1 <?php
2 /**
3 * Cloudfare Turnstile field
4 *
5 * @package EverestForms\Fields
6 * @since 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Turnstile Class.
13 */
14 class EVF_Field_Turnstile extends \EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Turnstile', 'everest-forms' );
21 $this->type = 'turnstile';
22 $this->icon = 'evf-icon evf-icon-turnstile';
23 $this->order = 243;
24 $this->class = $this->get_turnstile_class();
25 $this->group = 'advanced';
26 $this->settings = array(
27 'basic-options' => array(
28 'field_options' => array(
29 'label',
30 ),
31 ),
32 'advanced-options' => array(
33 'field_options' => array(
34 'meta',
35 ),
36 ),
37 );
38
39 parent::__construct();
40 }
41
42 /**
43 * Get Turnstile class.
44 *
45 * @return string
46 */
47 private function get_turnstile_class() {
48 $site_key = get_option( 'everest_forms_recaptcha_turnstile_site_key' );
49 $secret_key = get_option( 'everest_forms_recaptcha_turnstile_secret_key' );
50 $recaptcha_type = get_option( 'everest_forms_recaptcha_type', 'v2' );
51 return ( empty( $site_key ) || empty( $secret_key ) || 'turnstile' !== $recaptcha_type ) ? 'turnstile_empty_key_validate' : '';
52 }
53
54 /**
55 * Field preview inside the builder.
56 *
57 * @since 1.0.0
58 *
59 * @param array $field Field data and settings.
60 */
61 public function field_preview( $field ) {
62 $recaptcha_type = get_option( 'everest_forms_recaptcha_type', '' );
63 $turnstile_enabled = get_option( 'everest_forms_recaptcha_turnstile_enable', 'no' );
64
65 if ( 'turnstile' !== $recaptcha_type || 'yes' !== $turnstile_enabled ) {
66 return;
67 }
68
69 $site_key = get_option( 'everest_forms_recaptcha_turnstile_site_key' );
70 $secret_key = get_option( 'everest_forms_recaptcha_turnstile_secret_key' );
71
72 if ( empty( $site_key ) || empty( $secret_key ) ) {
73 return;
74 }
75
76 // Label.
77 $this->field_preview_option( 'label', $field );
78
79 // Default value.
80 $default_value = isset( $field['default_value'] ) && ! empty( $field['default_value'] ) ? $field['default_value'] : '';
81
82 $image_url = plugins_url( 'assets/images/captcha/turnstile.png', EVF_PLUGIN_FILE );
83 echo '<img src="' . esc_url( $image_url ) . '" class="widefat" disabled />';
84 }
85
86
87 /**
88 * Field display on the form front-end.
89 *
90 * @since 1.0.0
91 *
92 * @param array $field Field Data.
93 * @param array $field_atts Field attributes.
94 * @param array $form_data All Form Data.
95 */
96 public function field_display( $field, $field_atts, $form_data ) {
97 $recaptcha_type = get_option( 'everest_forms_recaptcha_type', '' );
98 $turnstile_enabled = get_option( 'everest_forms_recaptcha_turnstile_enable', 'no' );
99
100 if ( 'turnstile' !== $recaptcha_type || 'yes' !== $turnstile_enabled ) {
101 return;
102 }
103
104 $site_key = get_option( 'everest_forms_recaptcha_turnstile_site_key' );
105 $secret_key = get_option( 'everest_forms_recaptcha_turnstile_secret_key' );
106
107 if ( empty( $site_key ) || empty( $secret_key ) ) {
108 return;
109 }
110
111 $form_id = isset( $form_data['id'] ) ? absint( $form_data['id'] ) : 0;
112 $visible = ! empty( self::$parts[ $form_id ] ) ? 'style="display:none;"' : '';
113 $data = apply_filters(
114 'everest_forms_frontend_recaptcha',
115 array(
116 'sitekey' => trim( sanitize_text_field( $site_key ) ),
117 ),
118 $form_data
119 );
120
121 if ( $site_key && $secret_key ) {
122 $theme = get_option( 'everest_forms_recaptcha_turnstile_theme' );
123 $lang = get_option( 'everest_forms_recaptcha_recaptcha_language', 'en-GB' );
124
125 $recaptcha_api = apply_filters( 'everest_forms_frontend_recaptcha_url', 'https://challenges.cloudflare.com/turnstile/v0/api.js?onload=EVFTurnstileLoad&render=explicit', 'turnstile', $form_id );
126 $recaptcha_inline = 'var EVFTurnstileLoad = function(){jQuery(".g-recaptcha").each(function(index, el){var recaptchaID = turnstile.render(el,{theme:"' . $theme . '",language:"' . $lang . '",callback:function(){EVFRecaptchaCallback(el);}},true);jQuery(el).attr( "data-recaptcha-id", recaptchaID);});};';
127 $recaptcha_inline .= 'var EVFRecaptchaCallback = function(el){jQuery(el).parent().find(".evf-recaptcha-hidden").val("1").trigger("change").valid();};';
128
129 wp_enqueue_script(
130 'evf-recaptcha',
131 $recaptcha_api,
132 array( 'jquery' ),
133 '2.0.0',
134 true
135 );
136
137 static $count = 1;
138 if ( 1 === $count ) {
139 wp_add_inline_script( 'evf-recaptcha', $recaptcha_inline );
140 ++$count;
141 }
142
143 echo '<div class="evf-recaptcha-container" style="display:' . ( ! empty( self::$parts[ $form_id ] ) ? 'none' : 'block' ) . '">';
144 echo '<div ' . evf_html_attributes( '', array( 'g-recaptcha' ), $data ) . '></div>';
145 echo '<input type="text" name="g-recaptcha-hidden" class="evf-recaptcha-hidden" style="position:absolute!important;clip:rect(0,0,0,0)!important;height:1px!important;width:1px!important;border:0!important;overflow:hidden!important;padding:0!important;margin:0!important;" required>';
146 echo '</div>';
147 }
148 }
149 }
150