PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.8
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.8
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
weforms / includes / fields / class-field-recaptcha.php

class-field-recaptcha.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.2.8, at includes/fields/class-field-recaptcha.php

199 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
199