PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.3
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.3, at includes/fields/class-field-recaptcha.php

182 lines 6.1 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
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.', 'weforms');
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', 'weforms' ),
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>.', 'weforms' ),
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', 'weforms' ),
140 'type' => 'text',
141 'section' => 'basic',
142 'priority' => 10,
143 'help_text' => __( 'Title of the section', 'weforms' ),
144 ),
145
146 array(
147 'name' => 'recaptcha_type',
148 'title' => 'reCaptcha type',
149 'type' => 'radio',
150 'options' => array(
151 'enable_no_captcha' => __( 'Enable noCaptcha', 'weforms' ),
152 'invisible_recaptcha' => __( 'Enable Invisible reCaptcha', 'weforms' ),
153 ),
154 'default' => 'enable_no_captcha',
155 'section' => 'basic',
156 'priority' => 11,
157 'help_text' => __( 'Select reCaptcha type', 'weforms' ),
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 }