PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.0
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.0
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 +198 -232 1.6.211.4.0 View file →
@@ -1,232 +1,198 @@
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 + 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 integer $form_id
19 + *
20 + * @return void
21 + */
22 + public function render( $field_settings, $form_id ) {
23 +
24 + $settings = weforms_get_settings( 'recaptcha' );
25 + $is_invisible = false;
26 + $public_key = isset( $settings->key ) ? $settings->key : '';
27 + $theme = isset( $field_settings['recaptcha_theme'] ) ? $field_settings['recaptcha_theme'] : 'light';
28 +
29 + if ( isset ( $field_settings['recaptcha_type'] ) ) {
30 + $is_invisible = $field_settings['recaptcha_type'] == 'invisible_recaptcha' ? true : false;
31 + }
32 +
33 + $invisible_css = $is_invisible ? ' style="margin: 0; padding: 0" ' : '';
34 +
35 + ?> <li <?php $this->print_list_attributes( $field_settings ); echo $invisible_css; ?>>
36 +
37 + <?php
38 +
39 + if ( ! $is_invisible ) {
40 + $this->print_label( $field_settings );
41 + }
42 +
43 + if ( ! $public_key ) {
44 + _e( 'reCaptcha API key is missing.', 'weforms');
45 +
46 + } else {
47 +
48 + ?>
49 +
50 + <div class="wpuf-fields <?php echo ' wpuf_'.$field_settings['name'].'_'.$form_id; ?>">
51 + <script>
52 + function weformsRecaptchaCallback(token) {
53 + jQuery('[name="g-recaptcha-response"]').val(token);
54 + jQuery('.weforms_submit_btn').attr('disabled',false).show();
55 + jQuery('.weforms_submit_btn_recaptcha').hide();
56 + }
57 +
58 + jQuery(document).ready( function($) {
59 + $('.weforms_submit_btn').attr('disabled',true);
60 + });
61 + </script>
62 +
63 + <input type="hidden" name="g-recaptcha-response">
64 + <?php
65 +
66 + if ( $is_invisible ) { ?>
67 +
68 + <script src="https://www.google.com/recaptcha/api.js?onload=weFormsreCaptchaLoaded&render=explicit&hl=en" async defer></script>
69 +
70 + <script>
71 +
72 + jQuery(document).ready(function($) {
73 + var btn = $('.weforms_submit_btn');
74 + var gc_btn = btn.clone().removeClass().addClass('weforms_submit_btn_recaptcha').attr('disabled',false);
75 + btn.after(gc_btn);
76 + btn.hide();
77 +
78 + $(document).on('click','.weforms_submit_btn_recaptcha',function(e){
79 + e.preventDefault();
80 + e.stopPropagation();
81 + grecaptcha.execute();
82 + })
83 + });
84 +
85 + var weFormsreCaptchaLoaded = function() {
86 +
87 + grecaptcha.render('recaptcha', {
88 + 'size' : 'invisible',
89 + 'sitekey' : '<?php echo $public_key; ?>',
90 + 'callback' : weformsRecaptchaCallback
91 + });
92 +
93 + grecaptcha.execute();
94 + };
95 + </script>
96 +
97 + <div id='recaptcha' class="g-recaptcha" data-theme="<?php echo $theme; ?>" data-sitekey="<?php echo $public_key; ?>" data-callback="weformsRecaptchaCallback" data-size="invisible"></div>
98 +
99 + <?php } else { ?>
100 +
101 + <script src="https://www.google.com/recaptcha/api.js"></script>
102 + <div id='recaptcha' data-theme="<?php echo $theme; ?>" class="g-recaptcha" data-sitekey="<?php echo $public_key; ?>" data-callback="weformsRecaptchaCallback"></div>
103 + <?php } ?>
104 +
105 + </div>
106 +
107 + <?php } ?>
108 +
109 + </li>
110 + <?php
111 + }
112 +
113 + /**
114 + * Custom validator
115 + *
116 + * @return array
117 + */
118 + public function get_validator() {
119 + return array(
120 + 'callback' => 'has_recaptcha_api_keys',
121 + 'button_class' => 'button-faded',
122 + 'msg_title' => __( 'Site key and Secret key', 'weforms' ),
123 + 'msg' => sprintf(
124 + __( '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' ),
125 + admin_url( 'admin.php?page=weforms#/settings' ),
126 + 'https://www.google.com/recaptcha/'
127 + ),
128 + );
129 + }
130 +
131 + /**
132 + * Get field options setting
133 + *
134 + * @return array
135 + */
136 + public function get_options_settings() {
137 + $settings = array(
138 + array(
139 + 'name' => 'label',
140 + 'title' => __( 'Title', 'weforms' ),
141 + 'type' => 'text',
142 + 'section' => 'basic',
143 + 'priority' => 10,
144 + 'help_text' => __( 'Title of the section', 'weforms' ),
145 + ),
146 +
147 + array(
148 + 'name' => 'recaptcha_type',
149 + 'title' => 'reCaptcha type',
150 + 'type' => 'radio',
151 + 'options' => array(
152 + 'enable_no_captcha' => __( 'Enable noCaptcha', 'weforms' ),
153 + 'invisible_recaptcha' => __( 'Enable Invisible reCaptcha', 'weforms' ),
154 + ),
155 + 'default' => 'enable_no_captcha',
156 + 'section' => 'basic',
157 + 'priority' => 11,
158 + 'help_text' => __( 'Select reCaptcha type', 'weforms' ),
159 + ),
160 +
161 + array(
162 + 'name' => 'recaptcha_theme',
163 + 'title' => 'reCaptcha Theme',
164 + 'type' => 'radio',
165 + 'options' => array(
166 + 'light' => __( 'Light', 'weforms' ),
167 + 'dark' => __( 'Dark', 'weforms' ),
168 + ),
169 + 'default' => 'light',
170 + 'section' => 'advanced',
171 + 'priority' => 12,
172 + 'help_text' => __( 'Select reCaptcha Theme', 'weforms' ),
173 + ),
174 + );
175 +
176 + return $settings;
177 + }
178 +
179 + /**
180 + * Get the field props
181 + *
182 + * @return array
183 + */
184 + public function get_field_props() {
185 + $props = array(
186 + 'template' => $this->get_type(),
187 + 'label' => '',
188 + 'recaptcha_type' => 'enable_no_captcha',
189 + 'is_meta' => 'yes',
190 + 'id' => 0,
191 + 'is_new' => true,
192 + 'wpuf_cond' => null,
193 + 'recaptcha_theme' => 'light',
194 + );
195 +
196 + return $props;
197 + }
198 +}