PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.7
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.7
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/fields/class-field-recaptcha.php +225 -232 1.6.121.4.7 View file →
@@ -1,232 +1,225 @@
1 -<?php
2 -
3 -/**
4 - * Text Field Class
5 - */
6 -class WeForms_Form_Field_reCaptcha extends WeForms_Field_Contract {
7 -
8 - public function __construct() {
9 - $this->name = __( 'reCaptcha', 'weforms' );
10 - $this->input_type = 'recaptcha';
11 - $this->icon = 'qrcode';
12 - }
13 -
14 - /**
15 - * Render the text field
16 - *
17 - * @param array $field_settings
18 - * @param int $form_id
19 - *
20 - * @return void
21 - */
22 - public function render( $field_settings, $form_id ) {
23 - $settings = weforms_get_settings( 'recaptcha' );
24 - $is_invisible = false;
25 - $public_key = isset( $settings->key ) ? $settings->key : '';
26 - $type = isset( $settings->type ) ? $settings->type : '';
27 - $theme = isset( $field_settings['recaptcha_theme'] ) ? $field_settings['recaptcha_theme'] : 'light';
28 - $use_theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use_theme_css'] : 'wpuf-style';
29 - /** Recaptcha V3 start */
30 - if( 'v3' == $type ) { ?>
31 - <li <?php $this->print_list_attributes( $field_settings ); ?> >
32 - <?php if ( ! $public_key ) {
33 - esc_html_e( 'reCaptcha API key is missing.', 'weforms');
34 - } else { ?>
35 - <li <?php $this->print_list_attributes( $field_settings ); ?> >
36 - <div class="wpuf-fields <?php echo ' wpuf_'. esc_attr( $field_settings['name'] ).'_'. esc_attr( $form_id ); ?>" data-style="<?php echo esc_attr( $use_theme_css ); ?>">
37 - <input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response">
38 - <input type="hidden" name="g-action" id="g-action">
39 - <script src="https://www.google.com/recaptcha/api.js?render=<?php echo esc_attr( $public_key );?>"> </script>
40 - <script>
41 - grecaptcha.ready(function() {
42 - grecaptcha.execute('<?php echo esc_attr( $public_key );?>', {action: 'captcha_validation'}).then( function( token ) {
43 - document.getElementById('g-recaptcha-response').value = token;
44 - document.getElementById('g-action').value = 'captcha_validation';
45 -
46 - });
47 - setInterval(function () {
48 - grecaptcha.execute('<?php echo esc_attr( $public_key );?>', {action: 'captcha_validation'}).then( function( token ) {
49 - document.getElementById('g-recaptcha-response').value = token;
50 - document.getElementById('g-action').value = 'captcha_validation';
51 - });
52 - }, 60000);
53 - });
54 - </script>
55 - </div>
56 - </li>
57 - <?php }
58 - return ;
59 - }
60 - /** Recaptcha V3 end */
61 -
62 - if ( isset( $field_settings['recaptcha_type'] ) ) {
63 - $is_invisible = $field_settings['recaptcha_type'] == 'invisible_recaptcha' ? true : false;
64 - }
65 -
66 - $invisible_css = $is_invisible ? ' style="margin: 0; padding: 0" ' : '';
67 -
68 - ?> <li <?php $this->print_list_attributes( $field_settings ); echo esc_attr( $invisible_css ); ?>>
69 -
70 - <?php
71 -
72 - if ( !$is_invisible ) {
73 - $this->print_label( $field_settings );
74 - }
75 -
76 - if ( ! $public_key ) {
77 - esc_html_e( 'reCaptcha API key is missing.', 'weforms');
78 -
79 - } else {
80 -
81 - ?>
82 -
83 - <div class="wpuf-fields <?php echo ' wpuf_'. esc_attr( $field_settings['name'] ).'_'. esc_attr( $form_id ); ?>">
84 - <script>
85 - function weformsRecaptchaCallback(token) {
86 - jQuery('[name="g-recaptcha-response"]').val(token);
87 - jQuery('.weforms_submit_btn').attr('disabled',false).show();
88 - jQuery('.weforms_submit_btn_recaptcha').hide();
89 - }
90 -
91 - jQuery(document).ready( function($) {
92 - $('.weforms_submit_btn').attr('disabled',true);
93 - });
94 - </script>
95 -
96 - <input type="hidden" name="g-recaptcha-response">
97 - <?php
98 -
99 - if ( $is_invisible ) { ?>
100 -
101 - <script src="https://www.google.com/recaptcha/api.js?onload=weFormsreCaptchaLoaded&render=explicit&hl=en" async defer></script>
102 -
103 - <script>
104 -
105 - jQuery(document).ready(function($) {
106 - var btn = $('.weforms_submit_btn');
107 - var gc_btn = btn.clone().removeClass().addClass('weforms_submit_btn_recaptcha').attr('disabled',false);
108 - btn.after(gc_btn);
109 - btn.hide();
110 -
111 - $(document).on('click','.weforms_submit_btn_recaptcha',function(e){
112 - e.preventDefault();
113 - e.stopPropagation();
114 - grecaptcha.execute();
115 - })
116 - });
117 -
118 - var weFormsreCaptchaLoaded = function() {
119 -
120 - grecaptcha.render('recaptcha', {
121 - 'size' : 'invisible',
122 - 'sitekey' : '<?php echo esc_attr( $public_key ); ?>',
123 - 'callback' : weformsRecaptchaCallback
124 - });
125 -
126 - grecaptcha.execute();
127 - };
128 - </script>
129 -
130 - <div id='recaptcha' class="g-recaptcha" data-theme="<?php echo esc_attr( $theme ); ?>" data-sitekey="<?php echo esc_attr( $public_key ); ?>" data-callback="weformsRecaptchaCallback" data-size="invisible"></div>
131 -
132 - <?php } else { ?>
133 -
134 - <script src="https://www.google.com/recaptcha/api.js"></script>
135 - <div id='recaptcha' data-theme="<?php echo esc_attr( $theme ); ?>" class="g-recaptcha" data-sitekey="<?php echo esc_attr ( $public_key ); ?>" data-callback="weformsRecaptchaCallback"></div>
136 - <?php } ?>
137 -
138 - </div>
139 -
140 - <?php
141 - } ?>
142 -
143 - </li>
144 - <?php
145 - }
146 -
147 - /**
148 - * Custom validator
149 - *
150 - * @return array
151 - */
152 - public function get_validator() {
153 - return [
154 - 'callback' => 'has_recaptcha_api_keys',
155 - 'button_class' => 'button-faded',
156 - 'msg_title' => __( 'Site key and Secret key', 'weforms' ),
157 - 'msg' => sprintf(
158 - __( 'You need to set Site key and Secret key in <a href="%s" target="_blank">Settings</a> in order to use "Recaptcha" field. <a href="%s" target="_blank">Click here to get the these key</a>.', 'weforms' ),
159 - admin_url( 'admin.php?page=weforms#/settings' ),
160 - 'https://www.google.com/recaptcha/'
161 - ),
162 - ];
163 - }
164 -
165 - /**
166 - * Get field options setting
167 - *
168 - * @return array
169 - */
170 - public function get_options_settings() {
171 - $settings = [
172 - [
173 - 'name' => 'label',
174 - 'title' => __( 'Title', 'weforms' ),
175 - 'type' => 'text',
176 - 'section' => 'basic',
177 - 'priority' => 10,
178 - 'help_text' => __( 'Title of the section', 'weforms' ),
179 - ],
180 - [
181 - 'name' => 'recaptcha_type',
182 - 'title' => 'reCaptcha type',
183 - 'type' => 'radio',
184 - 'options' => [
185 - 'enable_no_captcha' => __( 'Enable noCaptcha', 'weforms' ),
186 - 'invisible_recaptcha' => __( 'Enable Invisible reCaptcha', 'weforms' ),
187 - ],
188 - 'default' => 'enable_no_captcha',
189 - 'section' => 'basic',
190 - 'priority' => 11,
191 - 'help_text' => __( 'Select reCaptcha type', 'weforms' ),
192 - 'show_if' => 'is_recaptcha_v2'
193 - ],
194 - [
195 - 'name' => 'recaptcha_theme',
196 - 'title' => 'reCaptcha Theme',
197 - 'type' => 'radio',
198 - 'options' => [
199 - 'light' => __( 'Light', 'weforms' ),
200 - 'dark' => __( 'Dark', 'weforms' ),
201 - ],
202 - 'default' => 'light',
203 - 'section' => 'advanced',
204 - 'priority' => 12,
205 - 'help_text' => __( 'Select reCaptcha Theme', 'weforms' ),
206 - 'show_if' => 'is_recaptcha_v2'
207 - ],
208 - ];
209 -
210 - return $settings;
211 - }
212 -
213 - /**
214 - * Get the field props
215 - *
216 - * @return array
217 - */
218 - public function get_field_props() {
219 - $props = [
220 - 'template' => $this->get_type(),
221 - 'label' => '',
222 - 'recaptcha_type' => 'enable_no_captcha',
223 - 'is_meta' => 'yes',
224 - 'id' => 0,
225 - 'is_new' => true,
226 - 'wpuf_cond' => null,
227 - 'recaptcha_theme' => 'light',
228 - ];
229 -
230 - return $props;
231 - }
232 -}
1 +<?php
2 +
3 +/**
4 + * Text Field Class
5 + */
6 +class WeForms_Form_Field_reCaptcha extends WeForms_Field_Contract {
7 +
8 + public function __construct() {
9 + $this->name = __( 'reCaptcha', 'weforms' );
10 + $this->input_type = 'recaptcha';
11 + $this->icon = 'qrcode';
12 + }
13 +
14 + /**
15 + * Render the text field
16 + *
17 + * @param array $field_settings
18 + * @param int $form_id
19 + *
20 + * @return void
21 + */
22 + public function render( $field_settings, $form_id ) {
23 + $settings = weforms_get_settings( 'recaptcha' );
24 + $is_invisible = false;
25 + $public_key = isset( $settings->key ) ? $settings->key : '';
26 + $type = isset( $settings->type ) ? $settings->type : '';
27 + $theme = isset( $field_settings['recaptcha_theme'] ) ? $field_settings['recaptcha_theme'] : 'light';
28 + /** Recaptcha V3 start */
29 + if( 'v3' == $type ) { ?>
30 + <li <?php $this->print_list_attributes( $field_settings ); ?> >
31 + <?php if ( ! $public_key ) {
32 + esc_html_e( 'reCaptcha API key is missing.', 'weforms');
33 + } else { ?>
34 + <li <?php $this->print_list_attributes( $field_settings ); ?> >
35 + <div class="wpuf-fields <?php echo ' wpuf_'. esc_attr( $field_settings['name'] ).'_'. esc_attr( $form_id ); ?>">
36 + <input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response">
37 + <input type="hidden" name="g-action" id="g-action">
38 + <script src="https://www.google.com/recaptcha/api.js?render=<?php echo esc_attr( $public_key );?>"> </script>
39 + <script>
40 + grecaptcha.ready(function() {
41 + grecaptcha.execute('<?php echo esc_attr( $public_key );?>', {action: 'captcha_validation'}).then( function( token ) {
42 + document.getElementById('g-recaptcha-response').value = token;
43 + document.getElementById('g-action').value = 'captcha_validation';
44 +
45 + });
46 + });
47 + </script>
48 + </div>
49 + </li>
50 + <?php }
51 + return ;
52 + }
53 + /** Recaptcha V3 end */
54 +
55 + if ( isset( $field_settings['recaptcha_type'] ) ) {
56 + $is_invisible = $field_settings['recaptcha_type'] == 'invisible_recaptcha' ? true : false;
57 + }
58 +
59 + $invisible_css = $is_invisible ? ' style="margin: 0; padding: 0" ' : '';
60 +
61 + ?> <li <?php $this->print_list_attributes( $field_settings ); echo esc_attr( $invisible_css ); ?>>
62 +
63 + <?php
64 +
65 + if ( !$is_invisible ) {
66 + $this->print_label( $field_settings );
67 + }
68 +
69 + if ( ! $public_key ) {
70 + esc_html_e( 'reCaptcha API key is missing.', 'weforms');
71 +
72 + } else {
73 +
74 + ?>
75 +
76 + <div class="wpuf-fields <?php echo ' wpuf_'. esc_attr( $field_settings['name'] ).'_'. esc_attr( $form_id ); ?>">
77 + <script>
78 + function weformsRecaptchaCallback(token) {
79 + jQuery('[name="g-recaptcha-response"]').val(token);
80 + jQuery('.weforms_submit_btn').attr('disabled',false).show();
81 + jQuery('.weforms_submit_btn_recaptcha').hide();
82 + }
83 +
84 + jQuery(document).ready( function($) {
85 + $('.weforms_submit_btn').attr('disabled',true);
86 + });
87 + </script>
88 +
89 + <input type="hidden" name="g-recaptcha-response">
90 + <?php
91 +
92 + if ( $is_invisible ) { ?>
93 +
94 + <script src="https://www.google.com/recaptcha/api.js?onload=weFormsreCaptchaLoaded&render=explicit&hl=en" async defer></script>
95 +
96 + <script>
97 +
98 + jQuery(document).ready(function($) {
99 + var btn = $('.weforms_submit_btn');
100 + var gc_btn = btn.clone().removeClass().addClass('weforms_submit_btn_recaptcha').attr('disabled',false);
101 + btn.after(gc_btn);
102 + btn.hide();
103 +
104 + $(document).on('click','.weforms_submit_btn_recaptcha',function(e){
105 + e.preventDefault();
106 + e.stopPropagation();
107 + grecaptcha.execute();
108 + })
109 + });
110 +
111 + var weFormsreCaptchaLoaded = function() {
112 +
113 + grecaptcha.render('recaptcha', {
114 + 'size' : 'invisible',
115 + 'sitekey' : '<?php echo esc_attr( $public_key ); ?>',
116 + 'callback' : weformsRecaptchaCallback
117 + });
118 +
119 + grecaptcha.execute();
120 + };
121 + </script>
122 +
123 + <div id='recaptcha' class="g-recaptcha" data-theme="<?php echo esc_attr( $theme ); ?>" data-sitekey="<?php echo esc_attr( $public_key ); ?>" data-callback="weformsRecaptchaCallback" data-size="invisible"></div>
124 +
125 + <?php } else { ?>
126 +
127 + <script src="https://www.google.com/recaptcha/api.js"></script>
128 + <div id='recaptcha' data-theme="<?php echo esc_attr( $theme ); ?>" class="g-recaptcha" data-sitekey="<?php echo esc_attr ( $public_key ); ?>" data-callback="weformsRecaptchaCallback"></div>
129 + <?php } ?>
130 +
131 + </div>
132 +
133 + <?php
134 + } ?>
135 +
136 + </li>
137 + <?php
138 + }
139 +
140 + /**
141 + * Custom validator
142 + *
143 + * @return array
144 + */
145 + public function get_validator() {
146 + return [
147 + 'callback' => 'has_recaptcha_api_keys',
148 + 'button_class' => 'button-faded',
149 + 'msg_title' => __( 'Site key and Secret key', 'weforms' ),
150 + 'msg' => sprintf(
151 + __( 'You need to set Site key and Secret key in <a href="%s" target="_blank">Settings</a> in order to use "Recaptcha" field. <a href="%s" target="_blank">Click here to get the these key</a>.', 'weforms' ),
152 + admin_url( 'admin.php?page=weforms#/settings' ),
153 + 'https://www.google.com/recaptcha/'
154 + ),
155 + ];
156 + }
157 +
158 + /**
159 + * Get field options setting
160 + *
161 + * @return array
162 + */
163 + public function get_options_settings() {
164 + $settings = [
165 + [
166 + 'name' => 'label',
167 + 'title' => __( 'Title', 'weforms' ),
168 + 'type' => 'text',
169 + 'section' => 'basic',
170 + 'priority' => 10,
171 + 'help_text' => __( 'Title of the section', 'weforms' ),
172 + ],
173 + [
174 + 'name' => 'recaptcha_type',
175 + 'title' => 'reCaptcha type',
176 + 'type' => 'radio',
177 + 'options' => [
178 + 'enable_no_captcha' => __( 'Enable noCaptcha', 'weforms' ),
179 + 'invisible_recaptcha' => __( 'Enable Invisible reCaptcha', 'weforms' ),
180 + ],
181 + 'default' => 'enable_no_captcha',
182 + 'section' => 'basic',
183 + 'priority' => 11,
184 + 'help_text' => __( 'Select reCaptcha type', 'weforms' ),
185 + 'show_if' => 'is_recaptcha_v2'
186 + ],
187 + [
188 + 'name' => 'recaptcha_theme',
189 + 'title' => 'reCaptcha Theme',
190 + 'type' => 'radio',
191 + 'options' => [
192 + 'light' => __( 'Light', 'weforms' ),
193 + 'dark' => __( 'Dark', 'weforms' ),
194 + ],
195 + 'default' => 'light',
196 + 'section' => 'advanced',
197 + 'priority' => 12,
198 + 'help_text' => __( 'Select reCaptcha Theme', 'weforms' ),
199 + 'show_if' => 'is_recaptcha_v2'
200 + ],
201 + ];
202 +
203 + return $settings;
204 + }
205 +
206 + /**
207 + * Get the field props
208 + *
209 + * @return array
210 + */
211 + public function get_field_props() {
212 + $props = [
213 + 'template' => $this->get_type(),
214 + 'label' => '',
215 + 'recaptcha_type' => 'enable_no_captcha',
216 + 'is_meta' => 'yes',
217 + 'id' => 0,
218 + 'is_new' => true,
219 + 'wpuf_cond' => null,
220 + 'recaptcha_theme' => 'light',
221 + ];
222 +
223 + return $props;
224 + }
225 +}