PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.26.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.26.1
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / fields / FrmFieldGdpr.php

FrmFieldGdpr.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.26.1, at classes/models/fields/FrmFieldGdpr.php

225 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 6.19
8 */
9 class FrmFieldGdpr extends FrmFieldType {
10
11 /**
12 * @since 6.19
13 *
14 * @var string
15 */
16 protected $type = 'gdpr';
17
18 /**
19 * @since 6.19
20 *
21 * @var bool
22 */
23 protected $has_for_label = false;
24
25 /**
26 * @since 6.19
27 *
28 * @var string
29 */
30 const VIEW_PATH = '/classes/views/frm-fields/front-end/gdpr/gdpr-field.php';
31
32 /**
33 * Get the new field defaults.
34 *
35 * @since 6.19
36 *
37 * @return array
38 */
39 public function get_new_field_defaults() {
40 if ( FrmFieldGdprHelper::hide_gdpr_field() ) {
41 return array(
42 'name' => false,
43 'description' => false,
44 'type' => $this->type,
45 'options' => false,
46 'required' => false,
47 'field_options' => false,
48 );
49 }
50
51 return array(
52 'name' => $this->get_new_field_name() . __( ' Consent', 'formidable' ),
53 'description' => '',
54 'type' => $this->type,
55 'options' => '',
56 'required' => true,
57 'field_options' => $this->get_default_field_options(),
58 );
59 }
60
61 /**
62 * Get the field settings for the field type.
63 *
64 * @since 6.19
65 *
66 * @return bool[]
67 */
68 protected function field_settings_for_type() {
69 if ( FrmFieldGdprHelper::hide_gdpr_field() ) {
70 return array(
71 'size' => false,
72 'clear_on_focus' => false,
73 'default' => false,
74 'invalid' => false,
75 'max' => false,
76 'required' => false,
77 'label' => false,
78 'css' => false,
79 'label_position' => false,
80 'description' => false,
81 );
82 }
83
84 return array(
85 'size' => true,
86 'clear_on_focus' => false,
87 'default' => false,
88 'invalid' => false,
89 'max' => false,
90 'readonly_required' => true,
91 'required' => true,
92 );
93 }
94
95 /**
96 * Show the primary options for the field.
97 *
98 * @since 6.19
99 *
100 * @param array $args The arguments.
101 */
102 public function show_primary_options( $args ) {
103 if ( FrmFieldGdprHelper::hide_gdpr_field() ) {
104 return;
105 }
106
107 $field = $args['field'];
108 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/gdpr/primary-options.php';
109 }
110
111 public function show_label_on_form_builder() {
112 if ( FrmFieldGdprHelper::hide_gdpr_field() ) {
113 return;
114 }
115 parent::show_label_on_form_builder();
116 }
117
118 /**
119 * Gets extra field options.
120 *
121 * @since 6.19
122 *
123 * @return string[]
124 */
125 protected function extra_field_opts() {
126 return array(
127 'gdpr_agreement_text' => __( 'I consent to having this website store my submitted information so they can respond to my inquiry.', 'formidable' ),
128 );
129 }
130
131 /**
132 * Include the form builder file.
133 *
134 * @since 6.19
135 *
136 * @return string
137 */
138 protected function include_form_builder_file() {
139 return FrmAppHelper::plugin_path() . self::VIEW_PATH;
140 }
141
142 /**
143 * Include the front form file.
144 *
145 * @since 6.19
146 *
147 * @return string
148 */
149 protected function include_front_form_file() {
150 return FrmAppHelper::plugin_path() . self::VIEW_PATH;
151 }
152
153 /**
154 * Hide the field name/label if the GDPR field is disabled.
155 *
156 * @since 6.19
157 *
158 * @param array $args The arguments.
159 * @param string $html The HTML.
160 *
161 * @return string
162 */
163 protected function before_replace_html_shortcodes( $args, $html ) {
164 if ( FrmFieldGdprHelper::hide_gdpr_field() && ! current_user_can( 'frm_edit_forms' ) ) {
165 return '';
166 }
167 return $html;
168 }
169
170 /**
171 * Make sure the GDPR field is required even if the required setting is disabled.
172 *
173 * @since 6.20
174 *
175 * @param array $args
176 *
177 * @return array
178 */
179 public function validate( $args ) {
180 $errors = parent::validate( $args );
181
182 if ( ! $errors && ! FrmFieldGdprHelper::hide_gdpr_field() ) {
183 $required = FrmField::get_option( $this->field, 'required' );
184
185 if ( ! $required && empty( $args['value'] ) ) {
186 $frm_settings = FrmAppHelper::get_settings();
187 $errors[ 'field' . $args['id'] ] = str_replace( '[field_name]', is_object( $this->field ) ? $this->field->name : $this->field['name'], $frm_settings->blank_msg );
188 }
189 }
190
191 return $errors;
192 }
193
194 /**
195 * Make sure the GDPR field is required even if the required setting is disabled.
196 *
197 * @since 6.20
198 *
199 * @param bool $required
200 * @param array $field
201 *
202 * @return bool
203 */
204 public static function force_required_field( $required, $field ) {
205 if ( ! $required && 'gdpr' === $field['type'] && ! FrmFieldGdprHelper::hide_gdpr_field() ) {
206 $required = true;
207 }
208
209 return $required;
210 }
211
212 /**
213 * Add the GDPR agreement text as an additional translatable string.
214 *
215 * @since 6.23
216 *
217 * @return array
218 */
219 public function translatable_strings() {
220 $strings = parent::translatable_strings();
221 $strings[] = 'gdpr_agreement_text';
222 return $strings;
223 }
224 }
225