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