PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
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-recaptcha.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 1 year ago class-evf-field-ai.php 1 year ago class-evf-field-captcha.php 4 weeks ago class-evf-field-checkbox.php 2 months ago class-evf-field-color.php 4 weeks ago class-evf-field-country.php 2 months ago class-evf-field-credit-card.php 4 weeks ago class-evf-field-date-time.php 4 weeks 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 4 months ago class-evf-field-hidden.php 1 year ago class-evf-field-html.php 9 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 4 weeks ago class-evf-field-number.php 1 year ago class-evf-field-password.php 4 weeks ago class-evf-field-payment-authorize-net.php 4 weeks ago class-evf-field-payment-checkbox.php 4 weeks ago class-evf-field-payment-coupon.php 4 weeks ago class-evf-field-payment-gateway-selector.php 4 weeks ago class-evf-field-payment-quantity.php 4 weeks ago class-evf-field-payment-radio.php 4 weeks ago class-evf-field-payment-single.php 4 weeks ago class-evf-field-payment-square.php 1 year ago class-evf-field-payment-subscription-plan.php 4 weeks ago class-evf-field-payment-subtotal.php 4 weeks ago class-evf-field-payment-total.php 4 weeks ago class-evf-field-phone.php 1 year ago class-evf-field-privacy-policy.php 2 months ago class-evf-field-private-note.php 1 year ago class-evf-field-progress.php 4 weeks ago class-evf-field-radio.php 2 months ago class-evf-field-range-slider.php 4 weeks ago class-evf-field-rating.php 2 months ago class-evf-field-recaptcha.php 4 months ago class-evf-field-repeater.php 4 weeks ago class-evf-field-reset.php 4 weeks ago class-evf-field-scale-rating.php 1 year ago class-evf-field-select.php 1 year ago class-evf-field-signature.php 4 weeks 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 4 months ago class-evf-field-url.php 1 year ago class-evf-field-wysiwyg.php 2 months ago class-evf-field-yes-no.php 1 year ago payment-amount-helpers.php 4 weeks ago
class-evf-field-recaptcha.php
223 lines
1 <?php
2 /**
3 * Hidden text field
4 *
5 * @package EverestForms_Pro\Fields
6 * @since 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Hidden Class.
13 */
14 class EVF_Field_Recaptcha extends \EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'reCaptcha', 'everest-forms' );
21 $this->type = 'recaptcha';
22 $this->icon = 'evf-icon evf-icon-recaptcha';
23 $this->order = 241;
24 $this->class = $this->get_recaptcha_class();
25
26 $this->group = 'advanced';
27 $this->settings = array(
28 'basic-options' => array(
29 'field_options' => array(
30 'label',
31 ),
32 ),
33 'advanced-options' => array(
34 'field_options' => array(
35 'meta',
36 ),
37 ),
38 );
39
40 parent::__construct();
41 }
42
43 /**
44 * Get reCaptcha class.
45 *
46 * @return string
47 */
48 private function get_recaptcha_class() {
49 $recaptcha_type = get_option( 'everest_forms_recaptcha_type', 'v2' );
50 $invisible_recaptcha = get_option( 'everest_forms_recaptcha_v2_invisible', 'no' );
51 if ( 'v2' === $recaptcha_type && 'no' === $invisible_recaptcha ) {
52 $site_key = get_option( 'everest_forms_recaptcha_v2_site_key' );
53 $secret_key = get_option( 'everest_forms_recaptcha_v2_secret_key' );
54 } elseif ( 'v2' === $recaptcha_type && 'yes' === $invisible_recaptcha ) {
55 $site_key = get_option( 'everest_forms_recaptcha_v2_invisible_site_key' );
56 $secret_key = get_option( 'everest_forms_recaptcha_v2_invisible_secret_key' );
57 } elseif ( 'v3' === $recaptcha_type ) {
58 $site_key = get_option( 'everest_forms_recaptcha_v3_site_key' );
59 $secret_key = get_option( 'everest_forms_recaptcha_v3_secret_key' );
60 }
61 return empty( $site_key ) || empty( $secret_key ) || ( 'v2' !== $recaptcha_type && 'v3' !== $recaptcha_type ) ? 'recaptcha_empty_key_validate' : '';
62 }
63
64
65
66 /**
67 * Field preview inside the builder.
68 *
69 * @since 1.0.0
70 *
71 * @param array $field Field data and settings.
72 */
73 public function field_preview( $field ) {
74 $recaptcha_type = get_option( 'everest_forms_recaptcha_type', '' );
75 $v2_enabled = get_option( 'everest_forms_recaptcha_v2_enable', 'no' );
76 $v3_enabled = get_option( 'everest_forms_recaptcha_v3_enable', 'no' );
77 $invisible = get_option( 'everest_forms_recaptcha_v2_invisible', 'no' );
78
79 if ( 'v2' === $recaptcha_type && 'yes' !== $v2_enabled ) {
80 return;
81 }
82
83 if ( 'v3' === $recaptcha_type && 'yes' !== $v3_enabled ) {
84 return;
85 }
86
87 if ( 'v2' === $recaptcha_type && 'no' === $invisible ) {
88 $image_url = plugins_url( 'assets/images/captcha/reCAPTCHA.png', EVF_PLUGIN_FILE );
89 } elseif ( ( 'v2' === $recaptcha_type && 'yes' === $invisible ) || 'v3' === $recaptcha_type ) {
90 $image_url = plugins_url( 'assets/images/captcha/google-v3-reCAPTCHA.png', EVF_PLUGIN_FILE );
91 } else {
92 return;
93 }
94
95 // Label.
96 $this->field_preview_option( 'label', $field );
97
98 // Default value.
99 $default_value = isset( $field['default_value'] ) && ! empty( $field['default_value'] ) ? $field['default_value'] : '';
100 echo '<img src="' . esc_url( $image_url ) . '" class="widefat" disabled />';
101 }
102
103
104 /**
105 * Field display on the form front-end.
106 *
107 * @since 1.0.0
108 *
109 * @param array $field Field Data.
110 * @param array $field_atts Field attributes.
111 * @param array $form_data All Form Data.
112 */
113 public function field_display( $field, $field_atts, $form_data ) {
114 $recaptcha_type = get_option( 'everest_forms_recaptcha_type', '' );
115 $invisible_recaptcha = get_option( 'everest_forms_recaptcha_v2_invisible', 'no' );
116 $v2_enabled = get_option( 'everest_forms_recaptcha_v2_enable', 'no' );
117 $v3_enabled = get_option( 'everest_forms_recaptcha_v3_enable', 'no' );
118
119 if ( 'v2' === $recaptcha_type ) {
120 if ( 'yes' !== $v2_enabled ) {
121 return;
122 }
123
124 if ( 'no' === $invisible_recaptcha ) {
125 $site_key = get_option( 'everest_forms_recaptcha_v2_site_key' );
126 $secret_key = get_option( 'everest_forms_recaptcha_v2_secret_key' );
127 } else {
128 $site_key = get_option( 'everest_forms_recaptcha_v2_invisible_site_key' );
129 $secret_key = get_option( 'everest_forms_recaptcha_v2_invisible_secret_key' );
130 }
131 } elseif ( 'v3' === $recaptcha_type ) {
132 if ( 'yes' !== $v3_enabled ) {
133 return;
134 }
135
136 $site_key = get_option( 'everest_forms_recaptcha_v3_site_key' );
137 $secret_key = get_option( 'everest_forms_recaptcha_v3_secret_key' );
138 } else {
139 return;
140 }
141
142 if ( ! isset( $site_key, $secret_key ) || ! $site_key || ! $secret_key ) {
143 return;
144 }
145
146 if ( evf_is_amp() ) {
147 if ( 'v3' === $recaptcha_type ) {
148 printf(
149 '<amp-recaptcha-input name="everest_forms[recaptcha]" data-sitekey="%s" data-action="%s" layout="nodisplay"></amp-recaptcha-input>',
150 esc_attr( $site_key ),
151 esc_attr( 'evf_' . $form_data['id'] )
152 );
153 }
154 return;
155 }
156
157 $form_id = isset( $form_data['id'] ) ? absint( $form_data['id'] ) : 0;
158 $visible = ! empty( self::$parts[ $form_id ] ) ? 'style="display:none;"' : '';
159 $data = apply_filters(
160 'everest_forms_frontend_recaptcha',
161 array(
162 'sitekey' => trim( sanitize_text_field( $site_key ) ),
163 ),
164 $form_data
165 );
166
167 if ( $site_key && $secret_key ) {
168 if ( 'v2' === $recaptcha_type ) {
169 $recaptcha_api = apply_filters( 'everest_forms_frontend_recaptcha_url', 'https://www.google.com/recaptcha/api.js?onload=EVFRecaptchaLoad&render=explicit', $recaptcha_type, $form_id );
170
171 if ( 'yes' === $invisible_recaptcha ) {
172 $recaptcha_inline = 'var EVFRecaptchaLoad = function(){jQuery(".g-recaptcha").each(function(index, el){var recaptchaID = grecaptcha.render(el,{callback:function(){EVFRecaptchaCallback(el);}},true); el.closest("form").querySelector("button[type=submit]").recaptchaID = recaptchaID;});};
173 var EVFRecaptchaCallback = function (el) {
174 var $form = el.closest("form");
175 if( typeof jQuery !== "undefined" ){
176 if( "1" === jQuery( $form ).attr( "data-ajax_submission" ) ) {
177 el.closest( "form" ).querySelector( "button[type=submit]" ).recaptchaID = "verified";
178 jQuery( $form ).find( ".evf-submit" ).trigger( "click" );
179 } else {
180 $form.submit();
181 }
182 grecaptcha.reset();
183 }
184 };
185 ';
186 } else {
187 $recaptcha_inline = 'var EVFRecaptchaLoad = function(){jQuery(".g-recaptcha").each(function(index, el){var recaptchaID = grecaptcha.render(el,{callback:function(){EVFRecaptchaCallback(el);}},true);jQuery(el).attr( "data-recaptcha-id", recaptchaID);});};';
188 $recaptcha_inline .= 'var EVFRecaptchaCallback = function(el){jQuery(el).parent().find(".evf-recaptcha-hidden").val("1").trigger("change").valid();};';
189 }
190 } elseif ( 'v3' === $recaptcha_type ) {
191 $recaptcha_api = apply_filters( 'everest_forms_frontend_recaptcha_url', 'https://www.google.com/recaptcha/api.js?render=' . $site_key, $recaptcha_type, $form_id );
192 $recaptcha_inline = 'var EVFRecaptchaLoad = function(){grecaptcha.execute("' . esc_html( $site_key ) . '",{action:"everest_form"}).then(function(token){var f=document.getElementsByName("everest_forms[recaptcha]");for(var i=0;i<f.length;i++){f[i].value = token;}});};grecaptcha.ready(EVFRecaptchaLoad);setInterval(EVFRecaptchaLoad, 110000);';
193 $recaptcha_inline .= 'grecaptcha.ready(function(){grecaptcha.execute("' . esc_html( $site_key ) . '",{action:"everest_form"}).then(function(token){var f=document.getElementsByName("everest_forms[recaptcha]");for(var i=0;i<f.length;i++){f[i].value = token;}});});';
194 }
195
196 wp_enqueue_script(
197 'evf-recaptcha',
198 $recaptcha_api,
199 'v3' === $recaptcha_type ? array() : array( 'jquery' ),
200 'v3' === $recaptcha_type ? '3.0.0' : '2.0.0',
201 true
202 );
203
204 static $count = 1;
205 if ( 1 === $count ) {
206 wp_add_inline_script( 'evf-recaptcha', $recaptcha_inline );
207 ++$count;
208 }
209
210 $class = ( 'v3' === $recaptcha_type || ( 'v2' === $recaptcha_type && 'yes' === $invisible_recaptcha ) ) ? 'recaptcha-hidden' : '';
211 echo '<div class="evf-recaptcha-container ' . esc_attr( $class ) . '" style="display:' . ( ! empty( self::$parts[ $form_id ] ) ? 'none' : 'block' ) . '">';
212
213 if ( 'v2' === $recaptcha_type ) {
214 echo '<div ' . evf_html_attributes( '', array( 'g-recaptcha' ), $data ) . '></div>';
215 } else {
216 echo '<input type="hidden" name="everest_forms[recaptcha]" value="">';
217 }
218
219 echo '</div>';
220 }
221 }
222 }
223