PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.3
3.6.0 3.5.3 3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / fields / class-evf-field-privacy-policy.php
everest-forms / includes / fields Last commit date
class-evf-field-address.php 1 week ago class-evf-field-ai.php 1 year ago class-evf-field-captcha.php 1 month ago class-evf-field-checkbox.php 3 months ago class-evf-field-color.php 1 month ago class-evf-field-country.php 3 months ago class-evf-field-credit-card.php 1 month ago class-evf-field-date-time.php 1 month ago class-evf-field-divider.php 2 years ago class-evf-field-email.php 1 year ago class-evf-field-file-upload.php 1 year ago class-evf-field-first-name.php 1 year ago class-evf-field-hcaptcha.php 5 months ago class-evf-field-hidden.php 1 year ago class-evf-field-html.php 10 months ago class-evf-field-image-upload.php 1 year ago class-evf-field-last-name.php 1 year ago class-evf-field-likert.php 1 year ago class-evf-field-lookup.php 1 month ago class-evf-field-number.php 1 year ago class-evf-field-password.php 1 month ago class-evf-field-payment-authorize-net.php 1 month ago class-evf-field-payment-checkbox.php 1 month ago class-evf-field-payment-coupon.php 1 month ago class-evf-field-payment-gateway-selector.php 1 month ago class-evf-field-payment-quantity.php 1 month ago class-evf-field-payment-radio.php 1 month ago class-evf-field-payment-single.php 1 month ago class-evf-field-payment-square.php 2 years ago class-evf-field-payment-subscription-plan.php 1 month ago class-evf-field-payment-subtotal.php 1 month ago class-evf-field-payment-total.php 1 month ago class-evf-field-phone.php 1 year ago class-evf-field-privacy-policy.php 3 months ago class-evf-field-private-note.php 1 year ago class-evf-field-progress.php 1 month ago class-evf-field-radio.php 3 months ago class-evf-field-range-slider.php 1 month ago class-evf-field-rating.php 3 months ago class-evf-field-recaptcha.php 5 months ago class-evf-field-repeater.php 1 month ago class-evf-field-reset.php 1 month ago class-evf-field-scale-rating.php 1 year ago class-evf-field-select.php 1 year ago class-evf-field-signature.php 1 month ago class-evf-field-text.php 1 year ago class-evf-field-textarea.php 1 year ago class-evf-field-title.php 2 years ago class-evf-field-turnstile.php 5 months ago class-evf-field-url.php 1 year ago class-evf-field-wysiwyg.php 3 months ago class-evf-field-yes-no.php 1 year ago payment-amount-helpers.php 1 month ago
class-evf-field-privacy-policy.php
380 lines
1 <?php
2 /**
3 * Privacy Policy field
4 *
5 * @package EverestForms\Fields
6 * @since 3.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Field_Privacy_Policy Class.
13 */
14 class EVF_Field_Privacy_Policy extends EVF_Form_Fields {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->name = esc_html__( 'Privacy Policy', 'everest-forms' );
21 $this->type = 'privacy-policy';
22 $this->icon = 'evf-icon evf-icon-privacy-policy';
23 $this->order = 150;
24 $this->group = 'advanced';
25 $this->settings = array(
26 'basic-options' => array(
27 'field_options' => array(
28 'label',
29 'description',
30 'consent_message',
31 'add_local_page',
32 'add_custom_link',
33 'required',
34 'required_field_message_setting',
35 'required_field_message',
36 ),
37 ),
38 'advanced-options' => array(
39 'field_options' => array(
40 'meta',
41 'label_hide',
42 'css',
43 ),
44 ),
45 );
46
47 parent::__construct();
48 }
49
50 /**
51 * Hook in tabs.
52 */
53 public function init_hooks() {
54 add_filter( 'everest_forms_html_field_value', array( $this, 'html_field_value' ), 10, 5 );
55 add_filter( 'everest_forms_field_exporter_' . $this->type, array( $this, 'field_exporter' ) );
56 }
57
58 /**
59 * Filter callback for outputting formatted data.
60 *
61 * @since 1.7.0
62 *
63 * @param array $field Field Data.
64 *
65 * @return array Formatted field value and label.
66 */
67 public function field_exporter( $field ) {
68 return array(
69 'label' => ! empty( $field['name'] ) ? $field['name'] : ucfirst( str_replace( '_', ' ', $field['type'] ) ) . " - {$field['id']}",
70 'value' => ! empty( $field['value'] ) ? evf_process_syntaxes( $field['value'] ) : '',
71 );
72 }
73
74 /**
75 * Format field value according to the context.
76 *
77 * @since 1.7.0
78 *
79 * @param string $value Field value.
80 * @param array $field_value Field settings.
81 * @param array $submitted_form_data Form data.
82 * @param string $context Value display context.
83 * @param string $field The field whose value is being passed.
84 *
85 * @return string $value Html Value.
86 */
87 public function html_field_value( $value, $field_value, $submitted_form_data = array(), $context = '', $field = null ) {
88 if ( in_array( $context, array( 'export-csv', 'entry-single', 'entry-table' ), true ) ) {
89 $meta_key = '';
90 $entry_id = false;
91 $fields = false;
92
93 if ( isset( $_GET['view-entry'] ) && 'entry-single' === $context ) { // phpcs:ignore WordPress.Security.NonceVerification
94 $entry_id = absint( $_GET['view-entry'] ); // phpcs:ignore WordPress.Security.NonceVerification
95 $meta_key = array_search( $field_value, $submitted_form_data, true );
96 } elseif ( 'entry-table' === $context && is_object( $submitted_form_data ) ) {
97 $entry_id = absint( $submitted_form_data->entry_id );
98 $meta_key = array_search( $field_value, $submitted_form_data->meta, true );
99 } elseif ( 'export-csv' === $context && is_object( $submitted_form_data ) ) {
100 $meta_key = array_search( $field_value, $submitted_form_data->meta, true );
101 $fields = json_decode( wp_unslash( (string) $submitted_form_data->fields ), true );
102 }
103
104 $entry = $entry_id ? evf_get_entry( $entry_id, true ) : false;
105
106 if ( ! $fields ) {
107 $fields = isset( $entry->fields ) ? evf_decode( $entry->fields ) : array();
108 }
109
110 if ( is_array( $fields ) ) {
111 foreach ( $fields as $field ) {
112 $field_type = isset( $field['type'] ) ? sanitize_text_field( wp_unslash( (string) $field['type'] ) ) : '';
113 $field_meta_key = isset( $field['meta_key'] ) ? sanitize_text_field( wp_unslash( (string) $field['meta_key'] ) ) : '';
114
115 if ( $this->type === $field_type && $meta_key === $field_meta_key && ! empty( $field_value ) ) {
116 if ( 'export-csv' === $context ) {
117 return evf_process_hyperlink_syntax( sanitize_text_field( wp_unslash( (string) $field_value ) ), true );
118 }
119
120 return wp_kses_post( evf_process_syntaxes( sanitize_text_field( wp_unslash( (string) $field_value ) ) ) );
121 }
122 }
123 }
124 }
125
126 return $value;
127 }
128
129 /**
130 * Consent message.
131 *
132 * @since 1.7.0
133 * @param array $field Field Data.
134 */
135 public function consent_message( $field ) {
136 $label = $this->field_element(
137 'label',
138 $field,
139 array(
140 'slug' => 'consent_message',
141 'value' => esc_html__( 'Consent Message', 'everest-forms' ),
142 'tooltip' => esc_html__( 'Enter a message for user consentment.', 'everest-forms' ),
143 ),
144 false
145 );
146 $input_field = $this->field_element(
147 'textarea',
148 $field,
149 array(
150 'slug' => 'consent_message',
151 'class' => 'evf-privacy-policy-consent-message',
152 'value' => isset( $field['consent_message'] ) ? esc_attr( $field['consent_message'] ) : '',
153 ),
154 false
155 );
156 $this->field_element(
157 'row',
158 $field,
159 array(
160 'slug' => 'consent_message',
161 'content' => $label . $input_field,
162 )
163 );
164
165 // Info on creating a hyperlink.
166 printf(
167 '<p class="description"><strong>%s: </strong>%s <code>[%s](%s)</code> %s.',
168 esc_html__( 'Note', 'everest-forms' ),
169 esc_html__( 'Please use syntax', 'everest-forms' ),
170 esc_html__( 'Link Label', 'everest-forms' ),
171 esc_html__( 'Link URL', 'everest-forms' ),
172 esc_html__( 'to create a hyperlink', 'everest-forms' )
173 );
174 }
175
176 /**
177 * Get a list of published pages belonging to the current user.
178 *
179 * @since 1.7.0
180 *
181 * @return array
182 */
183 public static function get_local_page_list() {
184 $args = array(
185 'authors' => get_current_user_id(),
186 'post_status' => 'publish',
187 );
188 $pages = array();
189 $fetched_pages = (array) get_pages( $args );
190
191 foreach ( $fetched_pages as $page ) {
192 if ( $page instanceof WP_POST ) {
193 $pages[ $page->ID ] = $page;
194 }
195 }
196 return $pages;
197 }
198
199 /**
200 * Add a link to the consent message.
201 *
202 * @since 1.7.0
203 * @param array $field Field Data.
204 */
205 public function add_custom_link( $field ) {
206 ob_start();
207 $this->field_element(
208 'label',
209 $field,
210 array(
211 'slug' => 'add_custom_link',
212 'value' => esc_html__( 'Add a custom URL', 'everest-forms' ),
213 'tooltip' => esc_html__( 'Add a custom URL, containing policy details, in the consent message.', 'everest-forms' ),
214 )
215 );
216 echo '<div class="evf-field-option-inputs-container">';
217 $this->field_element(
218 'text',
219 $field,
220 array(
221 'slug' => 'add_custom_link_label',
222 'class' => 'evf-privacy-policy-custom-link-label',
223 'placeholder' => 'Link Label',
224 'value' => '',
225 )
226 );
227 $this->field_element(
228 'text',
229 $field,
230 array(
231 'slug' => 'add_custom_link_url',
232 'class' => 'evf-privacy-policy-custom-link-url',
233 'placeholder' => 'Link URL',
234 'value' => '',
235 )
236 );
237 printf(
238 '<button class="button button-secondary evf-privacy-policy-add-custom-url" type="button">%s</button>',
239 esc_html__( 'Add Custom URL', 'everest-forms' )
240 );
241 echo '</div>';
242 $this->field_element(
243 'row',
244 $field,
245 array(
246 'slug' => 'add_custom_link',
247 'content' => ob_get_clean(),
248 )
249 );
250 }
251
252 /**
253 * Add a local page to the consent message.
254 *
255 * @since 1.7.0
256 * @param array $field Field Data.
257 */
258 public function add_local_page( $field ) {
259 $local_pages = self::get_local_page_list();
260 $page_options = array();
261
262 // Prepare page options.
263 foreach ( $local_pages as $page ) {
264 if ( $page instanceof WP_POST ) {
265 $page_options[ $page->ID ] = $page->post_title;
266 }
267 }
268
269 $label = $this->field_element(
270 'label',
271 $field,
272 array(
273 'slug' => 'add_local_page',
274 'value' => esc_html__( 'Add a local Privacy Policy page', 'everest-forms' ),
275 'tooltip' => esc_html__( 'Add a local page residing in your site, containing policy details, in the consent message.', 'everest-forms' ),
276 ),
277 false
278 );
279 $input_field = $this->field_element(
280 'select',
281 $field,
282 array(
283 'slug' => 'add_local_page',
284 'class' => 'evf-select-local-privacy-policy-page',
285 'options' => $page_options,
286 'value' => isset( $field['add_local_page'] ) ? esc_attr( $field['add_local_page'] ) : '',
287 ),
288 false
289 );
290 $add_button = sprintf(
291 '<button class="button button-secondary evf-add-local-privacy-policy-page" type="button">%s</button>',
292 esc_html__( 'Add page', 'everest-forms' )
293 );
294 $this->field_element(
295 'row',
296 $field,
297 array(
298 'slug' => 'add_local_page',
299 'content' => $label . $input_field . $add_button,
300 )
301 );
302 }
303
304 /**
305 * Field preview inside the builder.
306 *
307 * @since 1.7.0
308 *
309 * @param array $field Field data and settings.
310 */
311 public function field_preview( $field ) {
312 // Label.
313 $this->field_preview_option( 'label', $field );
314
315 // Primary Input.
316 echo '<input type="checkbox" disabled>';
317
318 // Consent message.
319 $consent_message = ! empty( $field['consent_message'] ) ? esc_attr( $field['consent_message'] ) : '';
320 printf(
321 '<label class="evf-privacy-policy-consent-message">%s</label>',
322 evf_process_syntaxes( $consent_message ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
323 );
324
325 // Description.
326 $this->field_preview_option( 'description', $field );
327 }
328
329 /**
330 * Field display on the form front-end.
331 *
332 * @since 1.7.0
333 * @param array $field Field Data.
334 * @param array $field_atts Field attributes.
335 * @param array $form_data All Form Data.
336 */
337 public function field_display( $field, $field_atts, $form_data ) {
338 // Define data.
339 $primary = $field['properties']['inputs']['primary'];
340 $consent_message = ! empty( $field['consent_message'] ) ? esc_attr( $field['consent_message'] ) : '';
341 $form_id = $form_data['id'];
342 $field_id = $field['id'];
343 $page_ids = evf_extract_page_ids( $consent_message );
344
345 // Primary field.
346 printf(
347 '<input type="checkbox" value="%s" %s %s />',
348 esc_attr( trim( $consent_message ) ),
349 evf_html_attributes( $primary['id'], $primary['class'], $primary['data'], $primary['attr'] ),
350 esc_attr( $primary['required'] )
351 );
352
353 // Consent message.
354 printf(
355 '<label class="evf-privacy-policy-consent-message" for="evf-%s-field_%s">%s</label>',
356 esc_attr( $form_id ),
357 esc_attr( $field_id ),
358 evf_process_syntaxes( $consent_message ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
359 );
360
361 // Local page contents for privacy policy detail.
362 echo '<div class="evf-privacy-policy-local-page-contents">';
363
364 if ( false !== $page_ids ) {
365 $pages = self::get_local_page_list();
366
367 foreach ( $page_ids as $page_id ) {
368 if ( isset( $pages[ $page_id ] ) && $pages[ $page_id ] instanceof WP_POST ) {
369 printf(
370 '<div class="evf-privacy-policy-local-page-content evf-privacy-policy-local-page-content-%s" hidden>%s</div>',
371 esc_attr( $page_id ),
372 $pages[ $page_id ]->post_content // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
373 );
374 }
375 }
376 }
377 echo '</div>';
378 }
379 }
380