PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.18
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.18
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / FormBuilder / Components / Recaptcha.php

Recaptcha.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.18, at app/Services/FormBuilder/Components/Recaptcha.php

89 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\FormBuilder\Components;
4
5 class Recaptcha extends BaseComponent
6 {
7 /**
8 * Compile and echo the html element
9 *
10 * @param array $data [element data]
11 * @param \stdClass $form [Form Object]
12 *
13 * @return void
14 */
15 public function compile($data, $form)
16 {
17 $elementName = $data['element'];
18 $data = apply_filters('fluentform_rendering_field_data_' . $elementName, $data, $form);
19
20 $key = get_option('_fluentform_reCaptcha_details');
21 $apiVersion = 'v2_visible';
22 if ($key && isset($key['siteKey'])) {
23 $siteKey = $key['siteKey'];
24 } else {
25 $siteKey = '';
26 }
27
28 if (! $siteKey) {
29 return false;
30 }
31
32 if (! empty($key['api_version'])) {
33 $apiVersion = $key['api_version'];
34 }
35
36 if ('v3_invisible' == $apiVersion) {
37 wp_enqueue_script(
38 'google-recaptcha',
39 'https://www.google.com/recaptcha/api.js?render=' . $siteKey,
40 [],
41 FLUENTFORM_VERSION,
42 true
43 );
44
45 add_filter('fluentform_form_class', function ($formClass) {
46 $formClass .= ' ff_has_v3_recptcha';
47 return $formClass;
48 });
49
50 add_filter('fluent_form_html_attributes', function ($atts) use ($siteKey) {
51 $atts['data-recptcha_key'] = $siteKey;
52 return $atts;
53 });
54
55 return;
56 }
57
58 wp_enqueue_script(
59 'google-recaptcha',
60 'https://www.google.com/recaptcha/api.js',
61 [],
62 FLUENTFORM_VERSION,
63 true
64 );
65
66 $recaptchaBlock = "<div
67 data-sitekey='" . esc_attr($siteKey) . "'
68 id='fluentform-recaptcha-" . $form->id . "'
69 class='ff-el-recaptcha g-recaptcha'
70 data-callback='fluentFormrecaptchaSuccessCallback'></div>";
71
72 $label = '';
73 if (! empty($data['settings']['label'])) {
74 $label = "<div class='ff-el-input--label'><label>" . fluentform_sanitize_html($data['settings']['label'], false) . '</label></div>';
75 }
76
77 $containerClass = '';
78 if (! empty($data['settings']['label_placement'])) {
79 $containerClass = 'ff-el-form-' . $data['settings']['label_placement'];
80 }
81
82 $el = "<div class='ff-el-input--content'><div data-fluent_id='" . $form->id . "' name='g-recaptcha-response'>{$recaptchaBlock}</div></div>";
83
84 $html = "<div class='ff-el-group " . esc_attr($containerClass) . "' >{$label}{$el}</div>";
85
86 $this->printContent('fluentform_rendering_field_html_' . $elementName, $html, $data, $form);
87 }
88 }
89