PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.07
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.07
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
← All changes | classes/helpers/FrmFieldsHelper.php +202 -871 6.26.15.2.07 View file →
@@ -4,21 +4,8 @@
4 4 }
5 5
6 6 class FrmFieldsHelper {
7 7
8 - /**
9 - * The context is memoized for re-use as the context is checked for each field.
10 - *
11 - * @var bool|null
12 - */
13 - private static $context_is_safe_to_load_field_options_from_request_data;
14 -
15 - /**
16 - * @param string $type
17 - * @param int|string $form_id
18 - *
19 - * @return array
20 - */
21 8 public static function setup_new_vars( $type = '', $form_id = '' ) {
22 9
23 10 if ( strpos( $type, '|' ) ) {
24 11 list( $type, $setting ) = explode( '|', $type );
@@ -26,14 +13,9 @@
26 13
27 14 $values = self::get_default_field( $type );
28 15
29 16 global $wpdb;
30 - $field_count = FrmDb::get_var(
31 - 'frm_fields',
32 - array( 'form_id' => $form_id ),
33 - 'field_order',
34 - array( 'order_by' => 'field_order DESC' )
35 - );
17 + $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
36 18
37 19 $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' );
38 20 $values['form_id'] = $form_id;
39 21 $values['field_order'] = $field_count + 1;
@@ -39,10 +21,10 @@
39 21 $values['field_order'] = $field_count + 1;
40 22
41 23 $values['field_options']['custom_html'] = self::get_default_html( $type );
42 24
43 - if ( ! empty( $setting ) ) {
44 - if ( in_array( $type, array( 'data', 'lookup' ), true ) ) {
25 + if ( isset( $setting ) && ! empty( $setting ) ) {
26 + if ( in_array( $type, array( 'data', 'lookup' ) ) ) {
45 27 $values['field_options']['data_type'] = $setting;
46 28 } else {
47 29 $values['field_options'][ $setting ] = 1;
48 30 }
@@ -47,30 +29,15 @@
47 29 $values['field_options'][ $setting ] = 1;
48 30 }
49 31 }
50 32
51 - // Increase the field order of submit field and fields in the same row.
52 - FrmSubmitHelper::update_last_row_fields_order_when_adding_field( $field_count );
53 -
54 33 return $values;
55 34 }
56 35
57 - /**
58 - * @param array $field
59 - * @param string $plus
60 - *
61 - * @return string
62 - */
63 36 public static function get_html_id( $field, $plus = '' ) {
64 37 return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
65 38 }
66 39
67 - /**
68 - * @param object $field
69 - * @param bool $doing_ajax
70 - *
71 - * @return array
72 - */
73 40 public static function setup_edit_vars( $field, $doing_ajax = false ) {
74 41 $values = self::field_object_to_array( $field );
75 42
76 43 return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
@@ -75,29 +42,18 @@
75 42
76 43 return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
77 44 }
78 45
79 - /**
80 - * @param object $field
81 - *
82 - * @return array
83 - */
84 46 public static function field_object_to_array( $field ) {
85 47 $values = (array) $field;
86 48
87 49 self::fill_field_array( $field, $values );
88 50
89 - $values['custom_html'] = $field->field_options['custom_html'] ?? self::get_default_html( $field->type );
51 + $values['custom_html'] = ( isset( $field->field_options['custom_html'] ) ) ? $field->field_options['custom_html'] : self::get_default_html( $field->type );
90 52
91 53 return $values;
92 54 }
93 55
94 - /**
95 - * @param object $field
96 - * @param array $field_array
97 - *
98 - * @return void
99 - */
100 56 private static function fill_field_array( $field, array &$field_array ) {
101 57 $field_array['options'] = $field->options;
102 58 $field_array['value'] = $field->default_value;
103 59
@@ -106,17 +62,11 @@
106 62 $field_array = array_merge( (array) $field->field_options, $field_array );
107 63 }
108 64
109 65 /**
110 - * Prepare field while creating a new entry.
66 + * Prepare field while creating a new entry
111 67 *
112 68 * @since 3.0
113 - *
114 - * @param array $field_array Field values array, passed by reference.
115 - * @param stdClass $field Field object.
116 - * @param array $args Additional arguments.
117 - *
118 - * @return void
119 69 */
120 70 public static function prepare_new_front_field( &$field_array, $field, $args = array() ) {
121 71 $args['action'] = 'new';
122 72 self::prepare_front_field( $field_array, $field, $args );
@@ -122,18 +72,11 @@
122 72 self::prepare_front_field( $field_array, $field, $args );
123 73 }
124 74
125 75 /**
126 - * Prepare field while editing an entry.
76 + * Prepare field while editing an entry
127 77 *
128 78 * @since 3.0
129 - *
130 - * @param array $field_array Field values array, passed by reference.
131 - * @param array|stdClass $field Field object or array.
132 - * @param int $entry_id Entry ID.
133 - * @param array $args Additional arguments.
134 - *
135 - * @return void
136 79 */
137 80 public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) {
138 81 $args['entry_id'] = $entry_id;
139 82 $args['action'] = 'edit';
@@ -143,14 +86,8 @@
143 86 /**
144 87 * Prepare field while creating a new entry
145 88 *
146 89 * @since 3.0
147 - *
148 - * @param array $field_array
149 - * @param stdClass $field
150 - * @param array $args
151 - *
152 - * @return void
153 90 */
154 91 private static function prepare_front_field( &$field_array, $field, $args ) {
155 92 self::fill_default_field_opts( $field, $field_array );
156 93 self::fill_cleared_strings( $field, $field_array );
@@ -155,26 +92,15 @@
155 92 self::fill_default_field_opts( $field, $field_array );
156 93 self::fill_cleared_strings( $field, $field_array );
157 94
158 95 // Track the original field's type
159 - $field_array['original_type'] = $field->field_options['original_type'] ?? $field->type;
96 + $field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
160 97
161 98 self::prepare_field_options_for_display( $field_array, $field, $args );
162 99
163 - if ( $args['action'] === 'edit' ) {
164 - /**
165 - * @param array $field_array
166 - * @param stdClass $field
167 - * @param int|string $entry_id
168 - * @param array $args
169 - */
100 + if ( $args['action'] == 'edit' ) {
170 101 $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args );
171 102 } else {
172 - /**
173 - * @param array $field_array
174 - * @param stdClass $field
175 - * @param array $args
176 - */
177 103 $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args );
178 104 }
179 105 }
180 106
@@ -194,16 +120,14 @@
194 120 /**
195 121 * @since 3.0
196 122 *
197 123 * @param object $field
198 - * @param array $values
199 - *
200 - * @return void
124 + * @param array $values
201 125 */
202 126 private static function fill_default_field_opts( $field, array &$values ) {
203 - $check_post = self::context_is_safe_to_load_field_options_from_request_data();
204 - $defaults = self::get_default_field_options_from_field( $field, $values );
127 + $check_post = FrmAppHelper::is_admin_page() && $_POST && isset( $_POST['field_options'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
205 128
129 + $defaults = self::get_default_field_options_from_field( $field, $values );
206 130 if ( ! $check_post ) {
207 131 $defaults['required_indicator'] = '';
208 132 $defaults['original_type'] = $field->type;
209 133 }
@@ -208,65 +132,16 @@
208 132 $defaults['original_type'] = $field->type;
209 133 }
210 134
211 135 foreach ( $defaults as $opt => $default ) {
212 - $values[ $opt ] = $field->field_options[ $opt ] ?? $default;
136 + $values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default;
213 137
214 138 if ( $check_post ) {
215 139 self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] );
216 140 }
217 - }
218 - }
219 141
220 - /**
221 - * The fill_default_field_opts method is called when loading a field.
222 - * This is used to preserve the $_POST data after updating settings for a field.
223 - * To prevent this from happening when creating an entry, we need to check the context.
224 - *
225 - * @return bool
226 - */
227 - private static function context_is_safe_to_load_field_options_from_request_data() {
228 - if ( isset( self::$context_is_safe_to_load_field_options_from_request_data ) ) {
229 - return self::$context_is_safe_to_load_field_options_from_request_data;
142 + unset( $opt, $default );
230 143 }
231 -
232 - $function = function () {
233 - if ( ! FrmAppHelper::is_admin_page() ) {
234 - return false;
235 - }
236 -
237 - if ( ! $_POST || ! isset( $_POST['field_options'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
238 - return false;
239 - }
240 -
241 - if ( ! current_user_can( 'frm_edit_forms' ) ) {
242 - return false;
243 - }
244 -
245 - $action = FrmAppHelper::get_post_param( 'action', '', 'sanitize_title' );
246 -
247 - if ( 'frm_forms_preview' === $action ) {
248 - // Never trigger when previewing.
249 - return false;
250 - }
251 -
252 - // Confirm an allowed action is being used, and that the correct nonce is being used.
253 - if ( 'update' === $action ) {
254 - $nonce = FrmAppHelper::get_post_param( 'frm_save_form', '', 'sanitize_text_field' );
255 - return wp_verify_nonce( $nonce, 'frm_save_form_nonce' );
256 - }
257 -
258 - $action = FrmAppHelper::get_post_param( 'frm_action', '', 'sanitize_title' );
259 -
260 - if ( 'update_settings' === $action ) {
261 - $nonce = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
262 - return wp_verify_nonce( $nonce, 'process_form_nonce' );
263 - }
264 - };
265 -
266 - self::$context_is_safe_to_load_field_options_from_request_data = $function();
267 -
268 - return self::$context_is_safe_to_load_field_options_from_request_data;
269 144 }
270 145
271 146 /**
272 147 * Fill the required message, invalid message,
@@ -274,23 +149,23 @@
274 149 *
275 150 * @since 3.0
276 151 *
277 152 * @param object $field
278 - * @param array $field_array
279 - *
280 - * @return void
153 + * @param array $field_array
281 154 */
282 155 private static function fill_cleared_strings( $field, array &$field_array ) {
156 + $frm_settings = FrmAppHelper::get_settings();
157 +
283 158 if ( '' == $field_array['blank'] && '1' === $field_array['required'] ) {
284 - $field_array['blank'] = self::default_blank_msg();
159 + $field_array['blank'] = $frm_settings->blank_msg;
285 160 }
286 161
287 - if ( '' === $field_array['invalid'] ) {
162 + if ( '' == $field_array['invalid'] ) {
288 163 if ( 'captcha' === $field->type ) {
289 - $frm_settings = FrmAppHelper::get_settings();
290 164 $field_array['invalid'] = $frm_settings->re_msg;
291 165 } else {
292 - $field_array['invalid'] = self::default_invalid_msg();
166 + /* translators: %s: Field name */
167 + $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
293 168 }
294 169 }
295 170
296 171 if ( '' == $field_array['custom_html'] ) {
@@ -298,50 +173,12 @@
298 173 }
299 174 }
300 175
301 176 /**
302 - * @since 6.8.3
303 - *
304 - * @return string
305 - */
306 - public static function default_invalid_msg() {
307 - /* translators: %s: [field_name] shortcode (Which gets replaced by a Field Name) */
308 - return sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' );
309 - }
310 -
311 - /**
312 - * @since 6.8.3
313 - *
314 - * @return string
315 - */
316 - public static function default_unique_msg() {
317 - $frm_settings = FrmAppHelper::get_settings();
318 - $unique_message = $frm_settings->unique_msg;
319 - $unique_message = str_replace( 'This value', '[field_name]', $unique_message );
320 - return $unique_message;
321 - }
322 -
323 - /**
324 - * @since 6.8.3
325 - *
326 - * @return string
327 - */
328 - public static function default_blank_msg() {
329 - $frm_settings = FrmAppHelper::get_settings();
330 - $blank_message = $frm_settings->blank_msg;
331 - $blank_message = str_replace( 'This field', '[field_name]', $blank_message );
332 - return $blank_message;
333 - }
334 -
335 - /**
336 - * When loading settings for a field, check the $_POST data and possibly use that instead of the DB value.
337 - *
338 177 * @since 3.0
339 178 *
340 179 * @param string $setting
341 - * @param mixed $value
342 - *
343 - * @return void
180 + * @param mixed $value
344 181 */
345 182 private static function get_posted_field_setting( $setting, &$value ) {
346 183 if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
347 184 return;
@@ -347,14 +184,10 @@
347 184 return;
348 185 }
349 186
350 187 if ( strpos( $setting, 'html' ) !== false ) {
188 + // Strip slashes from HTML but not regex or script tags.
351 189 $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
352 -
353 - // Conditionally strip script tags if the user sending $_POST data is not allowed to use unfiltered HTML.
354 - if ( ! FrmAppHelper::allow_unfiltered_html() ) {
355 - $value = FrmAppHelper::kses( $value, 'all' );
356 - }
357 190 } elseif ( strpos( $setting, 'format_' ) === 0 ) {
358 191 // TODO: Remove stripslashes on output, and use on input only.
359 192 $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
360 193 } else {
@@ -366,9 +199,9 @@
366 199 /**
367 200 * @since 3.0
368 201 *
369 202 * @param object $field
370 - * @param array $values The field array is needed for hooks.
203 + * @param array $values The field array is needed for hooks
371 204 *
372 205 * @return array
373 206 */
374 207 public static function get_default_field_options_from_field( $field, $values = array() ) {
@@ -385,13 +218,12 @@
385 218 * @since 3.0
386 219 *
387 220 * @param object $field
388 221 *
389 - * @return FrmFieldType
222 + * @return array
390 223 */
391 224 private static function get_original_field( $field ) {
392 225 $original_type = FrmField::get_option( $field, 'original_type' );
393 -
394 226 if ( ! empty( $original_type ) && $field->type != $original_type ) {
395 227 $field->type = $original_type;
396 228 }
397 229
@@ -400,13 +232,11 @@
400 232
401 233 /**
402 234 * @since 3.0
403 235 *
404 - * @param array $field_array
236 + * @param array $field_array
405 237 * @param object $field
406 - * @param array $atts
407 - *
408 - * @return void
238 + * @param array $atts
409 239 */
410 240 private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
411 241 $field_obj = FrmFieldFactory::get_field_object( $field );
412 242 $field_array = $field_obj->prepare_front_field( $field_array, $atts );
@@ -424,16 +254,8 @@
424 254
425 255 return $field_type->get_new_field_defaults();
426 256 }
427 257
428 - /**
429 - * @param array $values
430 - * @param object $field
431 - * @param int|string $form_id
432 - * @param string $new_key
433 - *
434 - * @return void
435 - */
436 258 public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
437 259 global $wpdb;
438 260
439 261 $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
@@ -448,27 +270,29 @@
448 270
449 271 /**
450 272 * @since 2.0
451 273 *
452 - * @param array|object $field
453 - * @param string $error
274 + * @param $field
275 + * @param $error
454 276 *
455 277 * @return string
456 278 */
457 279 public static function get_error_msg( $field, $error ) {
458 - $frm_settings = FrmAppHelper::get_settings();
280 + $frm_settings = FrmAppHelper::get_settings();
281 + $default_settings = $frm_settings->default_options();
282 + $field_name = is_array( $field ) ? $field['name'] : $field->name;
459 283
460 284 $conf_msg = __( 'The entered values do not match', 'formidable' );
461 285 $defaults = array(
462 286 'unique_msg' => array(
463 - 'full' => self::default_unique_msg(),
287 + 'full' => $default_settings['unique_msg'],
464 288 /* translators: %s: Field name */
465 - 'part' => sprintf( __( '%s must be unique', 'formidable' ), '[field_name]' ),
289 + 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ),
466 290 ),
467 291 'invalid' => array(
468 292 'full' => __( 'This field is invalid', 'formidable' ),
469 293 /* translators: %s: Field name */
470 - 'part' => sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' ),
294 + 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ),
471 295 ),
472 296 'blank' => array(
473 297 'full' => $frm_settings->blank_msg,
474 298 'part' => $frm_settings->blank_msg,
@@ -482,97 +306,17 @@
482 306 $msg = FrmField::get_option( $field, $error );
483 307 $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
484 308 $msg = do_shortcode( $msg );
485 309
486 - $msg = self::maybe_replace_substrings_with_field_name( $msg, $error, $field );
487 -
488 310 return $msg;
489 311 }
490 312
491 - /**
492 - * @since 6.8.3
493 - *
494 - * @param string $msg
495 - * @param string $error
496 - * @param array|object $field
497 - *
498 - * @return string
499 - */
500 - private static function maybe_replace_substrings_with_field_name( $msg, $error, $field ) {
501 - $field_name = is_array( $field ) ? $field['name'] : $field->name;
502 - $field_name = FrmAppHelper::maybe_kses( $field_name );
503 - $substrings = self::get_substrings_to_replace_with_field_name( $field_name, compact( 'msg', 'error', 'field' ) );
504 -
505 - // Use the "This value"/"This field" placeholder strings if field name is empty.
506 - if ( ! $field_name ) {
507 - if ( 'unique_msg' === $error ) {
508 - $field_name = __( 'This value', 'formidable' );
509 - } else {
510 - $field_name = __( 'This field', 'formidable' );
511 - }
512 - }
513 -
514 - $msg = str_replace( $substrings, $field_name, $msg );
515 - return $msg;
516 - }
517 -
518 - /**
519 - * @since 6.8.3
520 - *
521 - * @param string $field_name
522 - * @param array $filter_args {
523 - * Filter arguments.
524 - *
525 - * @type string $msg The current error message before the substrings are replaced.
526 - * @type string $error A key including 'unique_msg', 'invalid', 'blank', or 'conf_msg'.
527 - * @type array|object $field The field with the error.
528 - * }
529 - *
530 - * @return array
531 - */
532 - private static function get_substrings_to_replace_with_field_name( $field_name, $filter_args ) {
533 - $substrings = array( '[field_name]' );
534 -
535 - if ( $field_name ) {
536 - array_push( $substrings, 'This value', 'This field' );
537 - }
538 -
539 - /**
540 - * @since 6.8.3
541 - *
542 - * @param array<string> $substrings
543 - * @param array $filter_args
544 - */
545 - $filtered_substrings = apply_filters( 'frm_error_substrings_to_replace_with_field_name', $substrings, $filter_args );
546 -
547 - if ( is_array( $filtered_substrings ) ) {
548 - $substrings = $filtered_substrings;
549 - } else {
550 - _doing_it_wrong( __METHOD__, 'Only arrays should be returned when using the frm_error_substrings_to_replace_with_field_name filter.', '6.8.3' );
551 - }
552 -
553 - return $substrings;
554 - }
555 -
556 - /**
557 - * @param int|string $form_id
558 - * @param array $error
559 - *
560 - * @return array
561 - */
562 313 public static function get_form_fields( $form_id, $error = array() ) {
563 314 $fields = FrmField::get_all_for_form( $form_id );
564 315
565 - FrmFieldName::track_first_name_field( $fields );
566 -
567 316 return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
568 317 }
569 318
570 - /**
571 - * @param string $type
572 - *
573 - * @return string
574 - */
575 319 public static function get_default_html( $type = 'text' ) {
576 320 $field = FrmFieldFactory::get_field_type( $type );
577 321 $default_html = $field->default_html();
578 322
@@ -584,14 +328,12 @@
584 328 return apply_filters( 'frm_custom_html', $default_html, $type );
585 329 }
586 330
587 331 /**
588 - * @param array $fields
589 - * @param array $errors
332 + * @param array $fields
333 + * @param array $errors
590 334 * @param object $form
591 - * @param object $form_action
592 - *
593 - * @return void
335 + * @param $form_action
594 336 */
595 337 public static function show_fields( $fields, $errors, $form, $form_action ) {
596 338 foreach ( $fields as $field ) {
597 339 $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field );
@@ -601,21 +343,17 @@
601 343
602 344 /**
603 345 * @since 3.0
604 346 *
605 - * @param array $atts
606 - * @param array|string $value
607 - *
608 - * @return void
347 + * @param array $atts
348 + * @param string|array $value
609 349 */
610 350 public static function run_wpautop( $atts, &$value ) {
611 - $autop = $atts['wpautop'] ?? true;
612 -
351 + $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true;
613 352 if ( apply_filters( 'frm_use_wpautop', $autop ) ) {
614 353 if ( is_array( $value ) ) {
615 354 $value = implode( "\n", $value );
616 355 }
617 -
618 356 $value = wpautop( $value );
619 357 }
620 358 }
621 359
@@ -622,18 +360,12 @@
622 360 /**
623 361 * Get the class to use for the label position
624 362 *
625 363 * @since 2.05
626 - *
627 - * @param string $position
628 - * @param array $field
629 - * @param bool|object|string $form
630 - *
631 - * @return string
632 364 */
633 365 public static function &label_position( $position, $field, $form ) {
634 366 if ( $position && $position != '' ) {
635 - if ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
367 + if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
636 368 $position = 'top';
637 369 }
638 370
639 371 return $position;
@@ -639,19 +371,18 @@
639 371 return $position;
640 372 }
641 373
642 374 $position = FrmStylesController::get_style_val( 'position', $form );
643 -
644 - if ( $position === 'none' ) {
375 + if ( $position == 'none' ) {
645 376 $position = 'top';
646 - } elseif ( $position === 'no_label' ) {
377 + } elseif ( $position == 'no_label' ) {
647 378 $position = 'none';
648 - } elseif ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
379 + } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
649 380 $position = 'top';
650 381 }
651 382
652 383 $position = apply_filters( 'frm_html_label_position', $position, $field, $form );
653 - $position = ! empty( $position ) ? $position : 'top';
384 + $position = ( ! empty( $position ) ) ? $position : 'top';
654 385
655 386 return $position;
656 387 }
657 388
@@ -658,11 +389,9 @@
658 389 /**
659 390 * Check if this field type allows placeholders
660 391 *
661 392 * @since 2.05
662 - *
663 393 * @param string $type
664 - *
665 394 * @return bool
666 395 */
667 396 public static function is_placeholder_field_type( $type ) {
668 397 return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true );
@@ -667,18 +396,10 @@
667 396 public static function is_placeholder_field_type( $type ) {
668 397 return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true );
669 398 }
670 399
671 - /**
672 - * @param array $field
673 - * @param int|string $opt_key
674 - * @param string $type
675 - *
676 - * @return string
677 - */
678 400 public static function get_checkbox_id( $field, $opt_key, $type = 'checkbox' ) {
679 401 $id = $field['id'];
680 -
681 402 if ( isset( $field['in_section'] ) && $field['in_section'] && ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
682 403 $id .= '-' . $field['in_section'];
683 404 }
684 405
@@ -684,13 +405,8 @@
684 405
685 406 return 'frm_' . $type . '_' . $id . '-' . $opt_key;
686 407 }
687 408
688 - /**
689 - * @param array $field
690 - *
691 - * @return void
692 - */
693 409 public static function show_single_option( $field ) {
694 410 self::hidden_field_option( $field );
695 411
696 412 if ( ! is_array( $field['options'] ) ) {
@@ -697,12 +413,11 @@
697 413 return;
698 414 }
699 415
700 416 $base_name = 'default_value_' . $field['id'];
701 - $html_id = $field['html_id'] ?? self::get_html_id( $field );
417 + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
702 418
703 - $default_type = self::get_default_value_type( $field );
704 - $options_count = count( $field['options'] );
419 + $default_type = self::get_default_value_type( $field );
705 420
706 421 foreach ( $field['options'] as $opt_key => $opt ) {
707 422 $field_val = self::get_value_from_array( $opt, $opt_key, $field );
708 423 $opt = self::get_label_from_array( $opt, $opt_key, $field );
@@ -713,12 +428,12 @@
713 428
714 429 // If this is an "Other" option, get the HTML for it.
715 430 if ( self::is_other_opt( $opt_key ) ) {
716 431 if ( FrmAppHelper::pro_is_installed() ) {
717 - require FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php';
432 + require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' );
718 433 }
719 434 } else {
720 - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
435 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
721 436 }
722 437
723 438 unset( $checked );
724 439 }
@@ -727,17 +442,13 @@
727 442 /**
728 443 * Include hidden row for javascript to duplicate.
729 444 *
730 445 * @since 4.0
731 - *
732 446 * @param array $field
733 - *
734 - * @return void
735 447 */
736 448 private static function hidden_field_option( $field ) {
737 449 // Don't duplicate during an ajax add option.
738 450 $ajax_action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' );
739 -
740 451 if ( $ajax_action === 'frm_add_field_option' ) {
741 452 return;
742 453 }
743 454
@@ -745,14 +456,14 @@
745 456 $field_val = __( 'New Option', 'formidable' );
746 457 $opt = __( 'New Option', 'formidable' );
747 458 $checked = false;
748 459 $field_name = 'default_value_' . $field['id'];
749 - $html_id = $field['html_id'] ?? self::get_html_id( $field );
460 + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
750 461
751 462 $default_type = self::get_default_value_type( $field );
752 463 $field_name .= ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
753 464
754 - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
465 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
755 466 }
756 467
757 468 /**
758 469 * @since 4.0
@@ -757,14 +468,12 @@
757 468 /**
758 469 * @since 4.0
759 470 *
760 471 * @param array $field
761 - *
762 472 * @return string radio or checkbox
763 473 */
764 474 private static function get_default_value_type( $field ) {
765 475 $default_type = $field['type'];
766 -
767 476 if ( $field['type'] === 'select' ) {
768 477 $default_type = FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio';
769 478 }
770 479 return $default_type;
@@ -769,15 +478,8 @@
769 478 }
770 479 return $default_type;
771 480 }
772 481
773 - /**
774 - * @param array|string $opt
775 - * @param int|string $opt_key
776 - * @param array $field
777 - *
778 - * @return mixed
779 - */
780 482 public static function get_value_from_array( $opt, $opt_key, $field ) {
781 483 $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
782 484
783 485 return FrmFieldsController::check_value( $opt, $opt_key, $field );
@@ -782,15 +484,8 @@
782 484
783 485 return FrmFieldsController::check_value( $opt, $opt_key, $field );
784 486 }
785 487
786 - /**
787 - * @param array|string $opt
788 - * @param int|string $opt_key
789 - * @param array $field
790 - *
791 - * @return string
792 - */
793 488 public static function get_label_from_array( $opt, $opt_key, $field ) {
794 489 $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
795 490
796 491 return FrmFieldsController::check_label( $opt );
@@ -796,66 +491,50 @@
796 491 return FrmFieldsController::check_label( $opt );
797 492 }
798 493
799 494 /**
800 - * Shows the inline modal.
801 - *
802 495 * @since 4.0
803 - * @since 6.4.1 Added `inside_class` in the arguments.
804 - *
805 - * @param array $args The arguments.
806 - *
807 - * @return void
808 496 */
809 497 public static function inline_modal( $args ) {
810 498 $defaults = array(
811 - 'id' => '',
812 - 'class' => '',
813 - 'show' => 0,
814 - 'callback' => array(),
815 - 'args' => array(),
816 - 'title' => '',
817 - 'inside_class' => 'inside',
818 - 'dismiss-icon' => true,
499 + 'id' => '',
500 + 'class' => '',
501 + 'show' => 0,
502 + 'callback' => array(),
503 + 'args' => array(),
504 + 'title' => '',
819 505 );
820 - $args = array_merge( $defaults, $args );
506 + $args = array_merge( $defaults, $args );
821 507
822 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php';
508 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php' );
823 509 }
824 510
825 511 /**
826 512 * @since 4.0
827 - *
828 - * @return void
829 513 */
830 514 public static function smart_values() {
831 515 $continue = apply_filters( 'frm_smart_values_box', true );
832 -
833 516 if ( $continue === true ) {
834 517 $upgrade_link = array(
835 518 'medium' => 'builder',
836 519 'content' => 'smart-tags',
837 520 );
838 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php';
521 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php' );
839 522 }
840 523 }
841 524
842 525 /**
843 526 * @since 4.0
844 - *
845 - * @return void
846 527 */
847 528 public static function input_mask() {
848 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php';
529 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php' );
849 530 }
850 531
851 532 /**
852 533 * @since 4.0
853 - *
854 - * @return void
855 534 */
856 535 public static function layout_classes() {
857 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php';
536 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php' );
858 537 }
859 538
860 539 /**
861 540 * @param int $tax_id
@@ -863,9 +542,8 @@
863 542 * @return string
864 543 */
865 544 public static function get_term_link( $tax_id ) {
866 545 $tax = get_taxonomy( $tax_id );
867 -
868 546 if ( ! $tax ) {
869 547 return '';
870 548 }
871 549
@@ -881,18 +559,11 @@
881 559
882 560 return $link;
883 561 }
884 562
885 - /**
886 - * @param array|string $observed_value
887 - * @param string $cond
888 - * @param array|string $hide_opt
889 - *
890 - * @return bool
891 - */
892 563 public static function value_meets_condition( $observed_value, $cond, $hide_opt ) {
893 - $hide_opt = self::get_value_for_comparison( $hide_opt );
894 - $observed_value = self::get_value_for_comparison( $observed_value );
564 + $hide_opt = self::get_value_for_comparision( $hide_opt );
565 + $observed_value = self::get_value_for_comparision( $observed_value );
895 566
896 567 if ( is_array( $observed_value ) ) {
897 568 return self::array_value_condition( $observed_value, $cond, $hide_opt );
898 569 }
@@ -897,9 +568,8 @@
897 568 return self::array_value_condition( $observed_value, $cond, $hide_opt );
898 569 }
899 570
900 571 $m = false;
901 -
902 572 if ( $cond === '==' ) {
903 573 $m = $observed_value == $hide_opt;
904 574 } elseif ( $cond === '!=' ) {
905 575 $m = $observed_value != $hide_opt;
@@ -912,13 +582,12 @@
912 582 } elseif ( $cond === '<=' ) {
913 583 $m = $observed_value <= $hide_opt;
914 584 } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) {
915 585 $m = stripos( $observed_value, $hide_opt );
916 -
917 586 if ( $cond === 'not LIKE' ) {
918 - $m = $m === false;
587 + $m = ( $m === false ) ? true : false;
919 588 } else {
920 - $m = $m !== false;
589 + $m = ( $m === false ) ? false : true;
921 590 }
922 591 } elseif ( $cond === '%LIKE' ) {
923 592 // ends with
924 593 $length = strlen( $hide_opt );
@@ -928,9 +597,9 @@
928 597 // starts with
929 598 $length = strlen( $hide_opt );
930 599 $substr = substr( $observed_value, 0, $length );
931 600 $m = 0 === strcasecmp( $substr, $hide_opt );
932 - }//end if
601 + }
933 602
934 603 return $m;
935 604 }
936 605
@@ -937,14 +606,10 @@
937 606 /**
938 607 * Trim and sanitize the values
939 608 *
940 609 * @since 2.05
941 - *
942 - * @param array|string $value
943 - *
944 - * @return array|string
945 610 */
946 - private static function get_value_for_comparison( $value ) {
611 + private static function get_value_for_comparision( $value ) {
947 612 // Remove white space from hide_opt
948 613 if ( ! is_array( $value ) ) {
949 614 $value = trim( $value );
950 615 }
@@ -953,22 +618,14 @@
953 618
954 619 return $value;
955 620 }
956 621
957 - /**
958 - * @param array $observed_value
959 - * @param string $cond
960 - * @param array|string $hide_opt
961 - *
962 - * @return bool
963 - */
964 622 public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
965 623 $m = false;
966 -
967 624 if ( $cond === '==' ) {
968 625 if ( is_array( $hide_opt ) ) {
969 626 $m = array_intersect( $hide_opt, $observed_value );
970 - $m = ! empty( $m );
627 + $m = empty( $m ) ? false : true;
971 628 } else {
972 629 $m = in_array( $hide_opt, $observed_value );
973 630 }
974 631 } elseif ( $cond === '!=' ) {
@@ -981,9 +638,8 @@
981 638 $m = $max < $hide_opt;
982 639 } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) {
983 640 foreach ( $observed_value as $ob ) {
984 641 $m = strpos( $ob, $hide_opt );
985 -
986 642 if ( $m !== false ) {
987 643 $m = true;
988 644 break;
989 645 }
@@ -989,9 +645,9 @@
989 645 }
990 646 }
991 647
992 648 if ( $cond === 'not LIKE' ) {
993 - $m = $m === false;
649 + $m = ( $m === false ) ? true : false;
994 650 }
995 651 } elseif ( $cond === '%LIKE' ) {
996 652 // ends with
997 653 foreach ( $observed_value as $ob ) {
@@ -1007,9 +663,9 @@
1007 663 $m = true;
1008 664 break;
1009 665 }
1010 666 }
1011 - }//end if
667 + }
1012 668
1013 669 return $m;
1014 670 }
1015 671
@@ -1016,13 +672,8 @@
1016 672 /**
1017 673 * Replace a few basic shortcodes and field ids
1018 674 *
1019 675 * @since 2.0
1020 - *
1021 - * @param string $value
1022 - * @param object $form
1023 - * @param object $entry
1024 - *
1025 676 * @return string
1026 677 */
1027 678 public static function basic_replace_shortcodes( $value, $form, $entry ) {
1028 679 if ( strpos( $value, '[sitename]' ) !== false ) {
@@ -1035,14 +686,8 @@
1035 686
1036 687 return $value;
1037 688 }
1038 689
1039 - /**
1040 - * @param string $content
1041 - * @param int|string $form_id
1042 - *
1043 - * @return array
1044 - */
1045 690 public static function get_shortcodes( $content, $form_id ) {
1046 691 if ( FrmAppHelper::pro_is_installed() ) {
1047 692 return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
1048 693 }
@@ -1060,13 +705,8 @@
1060 705
1061 706 return $matches;
1062 707 }
1063 708
1064 - /**
1065 - * @param array $fields
1066 - *
1067 - * @return string
1068 - */
1069 709 public static function allowed_shortcodes( $fields = array() ) {
1070 710 $tagregexp = array(
1071 711 'editlink',
1072 712 'id',
@@ -1074,16 +714,13 @@
1074 714 'ip',
1075 715 'siteurl',
1076 716 'sitename',
1077 717 'admin_email',
1078 - 'default-email',
1079 - 'default-from-email',
1080 718 'post[-|_]id',
1081 719 'created[-|_]at',
1082 720 'updated[-|_]at',
1083 721 'updated[-|_]by',
1084 722 'parent[-|_]id',
1085 - 'form_name',
1086 723 );
1087 724
1088 725 foreach ( $fields as $field ) {
1089 726 $tagregexp[] = $field->id;
@@ -1094,15 +731,8 @@
1094 731
1095 732 return $tagregexp;
1096 733 }
1097 734
1098 - /**
1099 - * @param string $content
1100 - * @param false|object $entry
1101 - * @param array $shortcodes
1102 - *
1103 - * @return string
1104 - */
1105 735 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1106 736 foreach ( $shortcodes[0] as $short_key => $tag ) {
1107 737 if ( empty( $tag ) ) {
1108 738 continue;
@@ -1129,21 +759,13 @@
1129 759
1130 760 /**
1131 761 * @param string $replace_with
1132 762 * @param array $atts
1133 - *
1134 - * @return string
1135 763 */
1136 764 private static function trigger_shortcode_atts( $replace_with, $atts ) {
1137 - $supported_atts = array( 'remove_accents', 'sanitize', 'sanitize_url' );
765 + $supported_atts = array( 'sanitize', 'sanitize_url' );
1138 766 $included_atts = array_intersect( $supported_atts, array_keys( $atts ) );
1139 -
1140 767 foreach ( $included_atts as $included_att ) {
1141 - if ( '0' === $atts[ $included_att ] ) {
1142 - // Skip any option that uses 0 so sanitize_url=0 does not encode.
1143 - continue;
1144 - }
1145 -
1146 768 $function = 'atts_' . $included_att;
1147 769 $replace_with = self::$function( $replace_with, $atts );
1148 770 }
1149 771 return $replace_with;
@@ -1149,23 +771,9 @@
1149 771 return $replace_with;
1150 772 }
1151 773
1152 774 /**
1153 - * Converts all accent characters to ASCII characters.
1154 - *
1155 - * @since 6.3.1
1156 - *
1157 - * @param string $replace_with The text to remove accents from.
1158 - *
1159 - * @return string
1160 - */
1161 - public static function atts_remove_accents( $replace_with ) {
1162 - return remove_accents( $replace_with );
1163 - }
1164 -
1165 - /**
1166 775 * @param string $replace_with
1167 - *
1168 776 * @return string
1169 777 */
1170 778 private static function atts_sanitize( $replace_with ) {
1171 779 return sanitize_title_with_dashes( $replace_with );
@@ -1172,9 +780,8 @@
1172 780 }
1173 781
1174 782 /**
1175 783 * @param string $replace_with
1176 - *
1177 784 * @return string
1178 785 */
1179 786 private static function atts_sanitize_url( $replace_with ) {
1180 787 return urlencode( $replace_with );
@@ -1184,21 +791,14 @@
1184 791 * Prevent shortcodes in fields from being processed
1185 792 *
1186 793 * @since 3.01.02
1187 794 *
1188 - * @param array $atts Includes entry object.
1189 - * @param string|null $value
1190 - *
1191 - * @return void
795 + * @param array $atts - includes entry object
796 + * @param string $value
1192 797 */
1193 798 public static function sanitize_embedded_shortcodes( $atts, &$value ) {
1194 - if ( is_null( $value ) ) {
1195 - return;
1196 - }
1197 -
1198 799 $atts['value'] = $value;
1199 800 $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
1200 -
1201 801 if ( $should_sanitize ) {
1202 802 $value = str_replace( '[', '&#91;', $value );
1203 803 }
1204 804 }
@@ -1205,9 +805,9 @@
1205 805
1206 806 /**
1207 807 * @since 3.0
1208 808 *
1209 - * @param array $atts
809 + * @param $atts
1210 810 *
1211 811 * @return string
1212 812 */
1213 813 private static function get_value_for_shortcode( $atts ) {
@@ -1218,21 +818,21 @@
1218 818 'key' => $atts['entry']->item_key,
1219 819 'ip' => $atts['entry']->ip,
1220 820 );
1221 821
1222 - $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get', 'default-email', 'default-from-email' );
822 + $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
1223 823
1224 824 if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
1225 825 $replace_with = $shortcode_values[ $atts['tag'] ];
1226 - } elseif ( in_array( $atts['tag'], $dynamic_default, true ) ) {
826 + } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
1227 827 $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
1228 - } elseif ( $clean_tag === 'user_agent' ) {
828 + } elseif ( $clean_tag == 'user_agent' ) {
1229 829 $description = $atts['entry']->description;
1230 830 $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
1231 - } elseif ( $clean_tag === 'created_at' || $clean_tag === 'updated_at' ) {
831 + } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
1232 832 $atts['tag'] = $clean_tag;
1233 833 $replace_with = self::get_entry_timestamp( $atts );
1234 - } elseif ( $clean_tag === 'created_by' || $clean_tag === 'updated_by' ) {
834 + } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
1235 835 $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
1236 836 } else {
1237 837 $replace_with = self::get_field_shortcode_value( $atts );
1238 838 }
@@ -1242,9 +842,9 @@
1242 842
1243 843 /**
1244 844 * @since 3.0
1245 845 *
1246 - * @param array $atts
846 + * @param $atts
1247 847 *
1248 848 * @return string
1249 849 */
1250 850 private static function get_entry_timestamp( $atts ) {
@@ -1260,15 +860,14 @@
1260 860
1261 861 /**
1262 862 * @since 3.0
1263 863 *
1264 - * @param array $atts
864 + * @param $atts
1265 865 *
1266 - * @return string|null
866 + * @return null|string
1267 867 */
1268 868 private static function get_field_shortcode_value( $atts ) {
1269 869 $field = FrmField::getOne( $atts['tag'] );
1270 -
1271 870 if ( empty( $field ) ) {
1272 871 return null;
1273 872 }
1274 873
@@ -1278,12 +877,11 @@
1278 877 $replace_with = $field->description;
1279 878 } else {
1280 879 $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
1281 880 $string_value = $replace_with;
1282 -
1283 881 if ( is_array( $replace_with ) ) {
1284 - $sep = $atts['sep'] ?? ', ';
1285 - $string_value = FrmAppHelper::safe_implode( $sep, $replace_with );
882 + $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
883 + $string_value = implode( $sep, $replace_with );
1286 884 }
1287 885
1288 886 if ( empty( $string_value ) && $string_value != '0' ) {
1289 887 $replace_with = '';
@@ -1291,9 +889,9 @@
1291 889 $atts['entry_id'] = $atts['entry']->id;
1292 890 $atts['entry_key'] = $atts['entry']->item_key;
1293 891 $replace_with = self::get_display_value( $replace_with, $field, $atts );
1294 892 }
1295 - }//end if
893 + }
1296 894
1297 895 return $replace_with;
1298 896 }
1299 897
@@ -1300,13 +898,8 @@
1300 898 /**
1301 899 * Get the value to replace a few standard shortcodes
1302 900 *
1303 901 * @since 2.0
1304 - *
1305 - * @param string $tag
1306 - * @param array $atts
1307 - * @param bool $return_array
1308 - *
1309 902 * @return string
1310 903 */
1311 904 public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
1312 905 $new_value = '';
@@ -1313,16 +906,8 @@
1313 906 switch ( $tag ) {
1314 907 case 'admin_email':
1315 908 $new_value = get_option( 'admin_email' );
1316 909 break;
1317 - case 'default-email':
1318 - $frm_settings = FrmAppHelper::get_settings();
1319 - $new_value = ! empty( $frm_settings->default_email ) && is_email( $frm_settings->default_email ) ? $frm_settings->default_email : get_option( 'admin_email' );
1320 - break;
1321 - case 'default-from-email':
1322 - $frm_settings = FrmAppHelper::get_settings();
1323 - $new_value = ! empty( $frm_settings->from_email ) && is_email( $frm_settings->from_email ) ? $frm_settings->from_email : get_option( 'admin_email' );
1324 - break;
1325 910 case 'siteurl':
1326 911 $new_value = FrmAppHelper::site_url();
1327 912 break;
1328 913 case 'frmurl':
@@ -1332,9 +917,9 @@
1332 917 $new_value = FrmAppHelper::site_name();
1333 918 break;
1334 919 case 'get':
1335 920 $new_value = self::process_get_shortcode( $atts, $return_array );
1336 - }//end switch
921 + }
1337 922
1338 923 return $new_value;
1339 924 }
1340 925
@@ -1341,13 +926,9 @@
1341 926 /**
1342 927 * Process the [get] shortcode
1343 928 *
1344 929 * @since 2.0
1345 - *
1346 - * @param array $atts
1347 - * @param bool $return_array
1348 - *
1349 - * @return array|string
930 + * @return string|array
1350 931 */
1351 932 public static function process_get_shortcode( $atts, $return_array = false ) {
1352 933 if ( ! isset( $atts['param'] ) ) {
1353 934 return '';
@@ -1365,9 +946,9 @@
1365 946 if ( ! isset( $atts['prev_val'] ) ) {
1366 947 $atts['prev_val'] = '';
1367 948 }
1368 949
1369 - $new_value = $atts['default'] ?? $atts['prev_val'];
950 + $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
1370 951 }
1371 952
1372 953 if ( is_array( $new_value ) && ! $return_array ) {
1373 954 $new_value = implode( ', ', $new_value );
@@ -1375,15 +956,8 @@
1375 956
1376 957 return $new_value;
1377 958 }
1378 959
1379 - /**
1380 - * @param mixed $value
1381 - * @param object $field
1382 - * @param array $atts
1383 - *
1384 - * @return mixed
1385 - */
1386 960 public static function get_display_value( $value, $field, $atts = array() ) {
1387 961
1388 962 $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts );
1389 963 $value = apply_filters( 'frm_get_display_value', $value, $field, $atts );
@@ -1393,16 +967,14 @@
1393 967 return apply_filters( 'frm_display_value', $value, $field, $atts );
1394 968 }
1395 969
1396 970 /**
1397 - * @param array $atts Includes value, field, and atts.
1398 - *
1399 - * @return mixed
971 + * @param $atts array Includes value, field, and atts
1400 972 */
1401 973 public static function get_unfiltered_display_value( $atts ) {
1402 974 $value = $atts['value'];
1403 975 $field = $atts['field'];
1404 - $atts = $atts['atts'] ?? $atts;
976 + $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
1405 977
1406 978 if ( is_array( $field ) ) {
1407 979 $field = $field['id'];
1408 980 }
@@ -1415,14 +987,8 @@
1415 987 /**
1416 988 * Get a value from the user profile from the user ID
1417 989 *
1418 990 * @since 3.0
1419 - *
1420 - * @param int|string $user_id
1421 - * @param string $user_info
1422 - * @param array $args
1423 - *
1424 - * @return string
1425 991 */
1426 992 public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
1427 993 $defaults = array(
1428 994 'blank' => false,
@@ -1435,14 +1001,14 @@
1435 1001 $user = get_userdata( $user_id );
1436 1002 $info = '';
1437 1003
1438 1004 if ( $user ) {
1439 - if ( $user_info === 'avatar' ) {
1005 + if ( $user_info == 'avatar' ) {
1440 1006 $info = get_avatar( $user_id, $args['size'] );
1441 - } elseif ( $user_info === 'author_link' ) {
1007 + } elseif ( $user_info == 'author_link' ) {
1442 1008 $info = get_author_posts_url( $user_id );
1443 1009 } else {
1444 - $info = $user->$user_info ?? '';
1010 + $info = isset( $user->$user_info ) ? $user->$user_info : '';
1445 1011 }
1446 1012
1447 1013 if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
1448 1014 $info = $user->user_login;
@@ -1455,22 +1021,18 @@
1455 1021
1456 1022 return $info;
1457 1023 }
1458 1024
1459 - /**
1460 - * @param string $type
1461 - *
1462 - * @return array
1463 - */
1464 1025 public static function get_field_types( $type ) {
1465 - $single_input = self::single_input_fields();
1466 - $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
1026 + $single_input = self::single_input_fields();
1027 + $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
1028 +
1467 1029 $field_selection = FrmField::all_field_selection();
1468 - $field_types = array();
1469 1030
1470 - if ( in_array( $type, $single_input, true ) ) {
1031 + $field_types = array();
1032 + if ( in_array( $type, $single_input ) ) {
1471 1033 self::field_types_for_input( $single_input, $field_selection, $field_types );
1472 - } elseif ( in_array( $type, $multiple_input, true ) ) {
1034 + } elseif ( in_array( $type, $multiple_input ) ) {
1473 1035 self::field_types_for_input( $multiple_input, $field_selection, $field_types );
1474 1036 } elseif ( isset( $field_selection[ $type ] ) ) {
1475 1037 $field_types[ $type ] = $field_selection[ $type ];
1476 1038 }
@@ -1483,10 +1045,8 @@
1483 1045 /**
1484 1046 * Get a list of all fields that use a single value input.
1485 1047 *
1486 1048 * @since 4.0
1487 - *
1488 - * @return array
1489 1049 */
1490 1050 public static function single_input_fields() {
1491 1051 $fields = array(
1492 1052 'text',
@@ -1500,26 +1060,15 @@
1500 1060 'hidden',
1501 1061 'time',
1502 1062 'tag',
1503 1063 'password',
1504 - 'gdpr',
1505 1064 );
1506 1065 return apply_filters( 'frm_single_input_fields', $fields );
1507 1066 }
1508 1067
1509 - /**
1510 - * @param string[] $inputs
1511 - * @param array $fields
1512 - * @param array $field_types
1513 - *
1514 - * @return void
1515 - */
1516 1068 private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1517 1069 foreach ( $inputs as $input ) {
1518 - // This may not be set if a field type was removed using the frm_available_fields or frm_pro_available_fields filters.
1519 - if ( array_key_exists( $input, $fields ) ) {
1520 - $field_types[ $input ] = $fields[ $input ];
1521 - }
1070 + $field_types[ $input ] = $fields[ $input ];
1522 1071 unset( $input );
1523 1072 }
1524 1073 }
1525 1074
@@ -1529,9 +1078,9 @@
1529 1078 * @since 2.0.6
1530 1079 *
1531 1080 * @param string $opt_key
1532 1081 *
1533 - * @return bool Returns true if current field option is an "Other" option
1082 + * @return boolean Returns true if current field option is an "Other" option
1534 1083 */
1535 1084 public static function is_other_opt( $opt_key ) {
1536 1085 return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1537 1086 }
@@ -1541,10 +1090,8 @@
1541 1090 *
1542 1091 * @since 2.0.6
1543 1092 *
1544 1093 * @param array $args
1545 - *
1546 - * @return string
1547 1094 */
1548 1095 public static function get_other_val( $args ) {
1549 1096 $defaults = array(
1550 1097 'opt_key' => 0,
@@ -1576,11 +1123,10 @@
1576 1123 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1577 1124 }
1578 1125
1579 1126 return $other_val;
1580 - }
1581 1127
1582 - if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1128 + } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1583 1129 // For normal fields
1584 1130
1585 1131 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1586 1132 // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -1589,9 +1135,9 @@
1589 1135 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1590 1136 }
1591 1137
1592 1138 return $other_val;
1593 - }//end if
1139 + }
1594 1140
1595 1141 // For checkboxes
1596 1142 if ( $field['type'] === 'checkbox' && is_array( $field['value'] ) ) {
1597 1143 // Check if there is an "other" val in saved value and make sure the
@@ -1603,15 +1149,13 @@
1603 1149 /**
1604 1150 * For radio buttons and dropdowns
1605 1151 * Check if saved value equals any of the options. If not, set it as the other value.
1606 1152 */
1607 - foreach ( $field['options'] as $opt_val ) {
1153 + foreach ( $field['options'] as $opt_key => $opt_val ) {
1608 1154 $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1609 -
1610 1155 // Multi-select dropdowns - key is not preserved
1611 1156 if ( is_array( $field['value'] ) ) {
1612 1157 $o_key = array_search( $temp_val, $field['value'] );
1613 -
1614 1158 if ( isset( $field['value'][ $o_key ] ) ) {
1615 1159 unset( $field['value'][ $o_key ], $o_key );
1616 1160 }
1617 1161 } elseif ( $temp_val == $field['value'] ) {
@@ -1619,16 +1163,15 @@
1619 1163 return '';
1620 1164 } else {
1621 1165 $other_val = $field['value'];
1622 1166 }
1623 - unset( $opt_val, $temp_val );
1167 + unset( $opt_key, $opt_val, $temp_val );
1624 1168 }
1625 -
1626 1169 // For multi-select dropdowns only
1627 1170 if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1628 1171 $other_val = reset( $field['value'] );
1629 1172 }
1630 - }//end if
1173 + }
1631 1174
1632 1175 return $other_val;
1633 1176 }
1634 1177
@@ -1637,10 +1180,10 @@
1637 1180 * Intended for front-end use
1638 1181 *
1639 1182 * @since 2.0.6
1640 1183 *
1641 - * @param array $args Should include field, opt_key and field name.
1642 - * @param bool $other_opt
1184 + * @param array $args should include field, opt_key and field name
1185 + * @param boolean $other_opt
1643 1186 * @param string $checked
1644 1187 *
1645 1188 * @return array $other_args
1646 1189 */
@@ -1649,14 +1192,14 @@
1649 1192 'name' => '',
1650 1193 'value' => '',
1651 1194 );
1652 1195
1653 - // Check if this is an "Other" option.
1196 + //Check if this is an "Other" option
1654 1197 if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1655 1198 return $other_args;
1656 1199 }
1657 1200
1658 - $other_opt = true;
1201 + $other_opt = true;
1659 1202
1660 1203 self::set_other_name( $args, $other_args );
1661 1204 self::set_other_value( $args, $other_args );
1662 1205
@@ -1663,37 +1206,25 @@
1663 1206 if ( '' !== $other_args['value'] ) {
1664 1207 $checked = 'checked="checked" ';
1665 1208 }
1666 1209
1667 - // If 'other' is selected as one of the default values for a checkbox field, 'checked' attribute should be on.
1668 - if ( ! $checked &&
1669 - $args['field']['type'] === 'checkbox' &&
1670 - is_array( $args['field']['value'] ) &&
1671 - isset( $args['field_val'] ) &&
1672 - in_array( $args['field_val'], $args['field']['value'], true )
1673 - ) {
1674 - $checked = 'checked="checked" ';
1675 - }
1676 -
1677 1210 return $other_args;
1678 1211 }
1679 1212
1680 1213 /**
1681 - * @since 2.0.6
1682 - *
1683 1214 * @param array $args
1684 1215 * @param array $other_args
1685 1216 *
1686 - * @return void
1217 + * @since 2.0.6
1687 1218 */
1688 1219 private static function set_other_name( $args, &$other_args ) {
1689 - // Set up name for other field
1220 + //Set up name for other field
1690 1221 $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1691 1222 $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] );
1692 1223 $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']';
1693 1224
1694 - // Converts item_meta[field_id] => item_meta[other][field_id] and
1695 - // item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1225 + //Converts item_meta[field_id] => item_meta[other][field_id] and
1226 + //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1696 1227 if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1697 1228 $other_args['name'] .= '[' . $args['opt_key'] . ']';
1698 1229 }
1699 1230 }
@@ -1700,14 +1231,12 @@
1700 1231
1701 1232 /**
1702 1233 * Find the parent and pointer, and get text for "other" text field
1703 1234 *
1704 - * @since 2.0.6
1705 - *
1706 1235 * @param array $args
1707 1236 * @param array $other_args
1708 1237 *
1709 - * @return void
1238 + * @since 2.0.6
1710 1239 */
1711 1240 private static function set_other_value( $args, &$other_args ) {
1712 1241 $parent = '';
1713 1242 $pointer = '';
@@ -1734,13 +1263,11 @@
1734 1263
1735 1264 /**
1736 1265 * If this field includes an other option, show it
1737 1266 *
1267 + * @param $args array
1268 + *
1738 1269 * @since 2.0.6
1739 - *
1740 - * @param array $args
1741 - *
1742 - * @return void
1743 1270 */
1744 1271 public static function include_other_input( $args ) {
1745 1272 if ( ! $args['other_opt'] ) {
1746 1273 return;
@@ -1746,15 +1273,13 @@
1746 1273 return;
1747 1274 }
1748 1275
1749 1276 $classes = array( 'frm_other_input' );
1750 -
1751 - if ( ! $args['checked'] || trim( $args['checked'] ) === '' ) {
1277 + if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1752 1278 // hide the field if the other option is not selected
1753 1279 $classes[] = 'frm_pos_none';
1754 1280 }
1755 -
1756 - if ( $args['field']['type'] === 'select' && ! empty( $args['field']['multiple'] ) ) {
1281 + if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1757 1282 $classes[] = 'frm_other_full';
1758 1283 }
1759 1284
1760 1285 // Set up HTML ID for Other field
@@ -1759,9 +1284,9 @@
1759 1284
1760 1285 // Set up HTML ID for Other field
1761 1286 $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1762 1287
1763 - $label = $args['opt_label'] ?? $args['field']['name'];
1288 + $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1764 1289
1765 1290 echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1766 1291 esc_html( $label ) .
1767 1292 '</label>' .
@@ -1775,11 +1300,11 @@
1775 1300 * Note: This does not affect fields in repeating sections
1776 1301 *
1777 1302 * @since 2.0.08
1778 1303 *
1779 - * @param string $type Field type.
1780 - * @param string $html_id
1781 - * @param bool|string $opt_key
1304 + * @param string $type - field type
1305 + * @param string $html_id
1306 + * @param string|boolean $opt_key
1782 1307 *
1783 1308 * @return string $other_id
1784 1309 */
1785 1310 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
@@ -1785,9 +1310,9 @@
1785 1310 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1786 1311 $other_id = $html_id;
1787 1312
1788 1313 // If hidden radio field, add an opt key of 0
1789 - if ( $type === 'radio' && $opt_key === false ) {
1314 + if ( $type == 'radio' && $opt_key === false ) {
1790 1315 $opt_key = 0;
1791 1316 }
1792 1317
1793 1318 if ( $opt_key !== false ) {
@@ -1798,18 +1323,12 @@
1798 1323
1799 1324 return $other_id;
1800 1325 }
1801 1326
1802 - /**
1803 - * @param string $val
1804 - *
1805 - * @return string
1806 - */
1807 1327 public static function switch_field_ids( $val ) {
1808 1328 global $frm_duplicate_ids;
1809 1329 $replace = array();
1810 1330 $replace_with = array();
1811 -
1812 1331 foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1813 1332 $replace[] = '[if ' . $old . ']';
1814 1333 $replace_with[] = '[if ' . $new . ']';
1815 1334 $replace[] = '[if ' . $old . ' ';
@@ -1827,26 +1346,13 @@
1827 1346 $replace[] = '[' . $old . ']';
1828 1347 $replace_with[] = '[' . $new . ']';
1829 1348 $replace[] = '[' . $old . ' ';
1830 1349 $replace_with[] = '[' . $new . ' ';
1831 - $replace[] = 'field_id="' . $old . '"';
1832 - $replace_with[] = 'field_id="' . $new . '"';
1833 - $replace[] = 'field_id=\"' . $old . '\"';
1834 - $replace_with[] = 'field_id=\"' . $new . '\"';
1835 - // This covers conditional logic.
1836 - $replace[] = '_field":"' . $old . '","';
1837 - $replace_with[] = '_field":"' . $new . '","';
1838 1350 unset( $old, $new );
1839 - }//end foreach
1840 -
1351 + }
1841 1352 if ( is_array( $val ) ) {
1842 1353 foreach ( $val as $k => $v ) {
1843 1354 if ( is_string( $v ) ) {
1844 - if ( 'custom_html' === $k ) {
1845 - $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v );
1846 - unset( $k, $v );
1847 - continue;
1848 - }
1849 1355 $val[ $k ] = str_replace( $replace, $replace_with, $v );
1850 1356 unset( $k, $v );
1851 1357 }
1852 1358 }
@@ -1857,49 +1363,17 @@
1857 1363 return $val;
1858 1364 }
1859 1365
1860 1366 /**
1861 - * Removes exception strings from replacement arrays and replaces the rest in the provided value string.
1862 - *
1863 - * @since 6.14
1864 - *
1865 - * @param array $replace Values to be replaced.
1866 - * @param array $replace_with Replacement values.
1867 - * @param array $exceptions Array of strings to skip.
1868 - * @param string $value Value to be updated.
1869 - *
1870 - * @return string
1871 - */
1872 - private static function switch_ids_except_strings( $replace, $replace_with, $exceptions, $value ) {
1873 - foreach ( $exceptions as $exception ) {
1874 - $index = array_search( $exception, $replace, true );
1875 -
1876 - if ( false === $index ) {
1877 - continue;
1878 - }
1879 - unset( $replace[ $index ] );
1880 - unset( $replace_with[ $index ] );
1881 - }
1882 -
1883 - $value = str_replace( $replace, $replace_with, $value );
1884 - return $value;
1885 - }
1886 -
1887 - /**
1888 1367 * @since 4.0
1889 - *
1890 - * @return void
1891 1368 */
1892 1369 public static function bulk_options_overlay() {
1893 1370 $prepop = array();
1894 1371 self::get_bulk_prefilled_opts( $prepop, true );
1895 1372
1896 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php';
1373 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1897 1374 }
1898 1375
1899 - /**
1900 - * @return array
1901 - */
1902 1376 public static function get_us_states() {
1903 1377 $states = array(
1904 1378 'AL' => 'Alabama',
1905 1379 'AK' => 'Alaska',
@@ -1956,11 +1430,8 @@
1956 1430
1957 1431 return apply_filters( 'frm_us_states', $states );
1958 1432 }
1959 1433
1960 - /**
1961 - * @return array
1962 - */
1963 1434 public static function get_countries() {
1964 1435 $countries = array(
1965 1436 __( 'Afghanistan', 'formidable' ),
1966 1437 __( 'Aland Islands', 'formidable' ),
@@ -2225,15 +1696,12 @@
2225 1696 * @since 5.0.04 Add `$include_class` param.
2226 1697 *
2227 1698 * @param array $prepop Bulk options.
2228 1699 * @param array|false $include_class Include the class in the bulk options.
2229 - *
2230 - * @return void
2231 1700 */
2232 1701 public static function get_bulk_prefilled_opts( array &$prepop, $include_class = false ) {
2233 1702 // Countries.
2234 1703 $countries = self::get_countries();
2235 -
2236 1704 if ( $include_class ) {
2237 1705 $countries['class'] = 'frm-countries-opts';
2238 1706 }
2239 1707
@@ -2242,9 +1710,8 @@
2242 1710 // State abv.
2243 1711 $states = self::get_us_states();
2244 1712 $state_abv = array_keys( $states );
2245 1713 sort( $state_abv );
2246 -
2247 1714 if ( $include_class ) {
2248 1715 $state_abv['class'] = 'frm-state-abv-opts';
2249 1716 }
2250 1717
@@ -2252,9 +1719,8 @@
2252 1719
2253 1720 // States.
2254 1721 $states = array_values( $states );
2255 1722 sort( $states );
2256 -
2257 1723 if ( $include_class ) {
2258 1724 $states['class'] = 'frm-states-opts';
2259 1725 }
2260 1726
@@ -2271,9 +1737,8 @@
2271 1737 __( '55-64', 'formidable' ),
2272 1738 __( '65 or Above', 'formidable' ),
2273 1739 __( 'Prefer Not to Answer', 'formidable' ),
2274 1740 );
2275 -
2276 1741 if ( $include_class ) {
2277 1742 $ages['class'] = 'frm-age-opts';
2278 1743 }
2279 1744
@@ -2287,9 +1752,8 @@
2287 1752 __( 'Satisfied', 'formidable' ),
2288 1753 __( 'Very Satisfied', 'formidable' ),
2289 1754 __( 'N/A', 'formidable' ),
2290 1755 );
2291 -
2292 1756 if ( $include_class ) {
2293 1757 $satisfaction['class'] = 'frm-satisfaction-opts';
2294 1758 }
2295 1759
@@ -2303,9 +1767,8 @@
2303 1767 __( 'Important', 'formidable' ),
2304 1768 __( 'Very Important', 'formidable' ),
2305 1769 __( 'N/A', 'formidable' ),
2306 1770 );
2307 -
2308 1771 if ( $include_class ) {
2309 1772 $importance['class'] = 'frm-importance-opts';
2310 1773 }
2311 1774
@@ -2319,9 +1782,8 @@
2319 1782 __( 'Agree', 'formidable' ),
2320 1783 __( 'Strongly Agree', 'formidable' ),
2321 1784 __( 'N/A', 'formidable' ),
2322 1785 );
2323 -
2324 1786 if ( $include_class ) {
2325 1787 $agreement['class'] = 'frm-agreement-opts';
2326 1788 }
2327 1789
@@ -2335,9 +1797,8 @@
2335 1797 __( 'Likely', 'formidable' ),
2336 1798 __( 'Extremely Likely', 'formidable' ),
2337 1799 __( 'N/A', 'formidable' ),
2338 1800 );
2339 -
2340 1801 if ( $include_class ) {
2341 1802 $likely['class'] = 'frm-likely-opts';
2342 1803 }
2343 1804
@@ -2350,12 +1811,10 @@
2350 1811 * Display a field value selector
2351 1812 *
2352 1813 * @since 2.03.05
2353 1814 *
2354 - * @param int $selector_field_id
1815 + * @param int $selector_field_id
2355 1816 * @param array $selector_args
2356 - *
2357 - * @return void
2358 1817 */
2359 1818 public static function display_field_value_selector( $selector_field_id, $selector_args ) {
2360 1819 $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
2361 1820 $field_value_selector->display();
@@ -2370,9 +1829,9 @@
2370 1829 *
2371 1830 * @return array
2372 1831 */
2373 1832 public static function convert_field_object_to_flat_array( $field ) {
2374 - $field_options = is_array( $field->field_options ) ? $field->field_options : array();
1833 + $field_options = $field->field_options;
2375 1834 $field_array = get_object_vars( $field );
2376 1835 unset( $field_array['field_options'] );
2377 1836
2378 1837 return $field_array + $field_options;
@@ -2379,12 +1838,9 @@
2379 1838 }
2380 1839
2381 1840 /**
2382 1841 * @since 4.04
2383 - *
2384 1842 * @param array $args
2385 - *
2386 - * @return void
2387 1843 */
2388 1844 public static function show_add_field_buttons( $args ) {
2389 1845 $field_key = $args['field_key'];
2390 1846 $field_type = $args['field_type'];
@@ -2391,14 +1847,8 @@
2391 1847 $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
2392 1848 $field_name = FrmFormsHelper::get_field_link_name( $field_type );
2393 1849 $field_label .= ' <span>' . $field_name . '</span>';
2394 1850
2395 - if ( ! empty( $field_type['is_new'] ) ) {
2396 - ob_start();
2397 - FrmAppHelper::show_pill_text();
2398 - $field_label .= ob_get_clean();
2399 - }
2400 -
2401 1851 // If the individual field isn't allowed, disable it.
2402 1852 $run_filter = true;
2403 1853 $single_no_allow = ' ';
2404 1854 $install_data = '';
@@ -2403,9 +1853,9 @@
2403 1853 $single_no_allow = ' ';
2404 1854 $install_data = '';
2405 1855 $requires = '';
2406 1856 $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
2407 - $has_show_upgrade_class = isset( $field_type['icon'] ) && strpos( $field_type['icon'], ' frm_show_upgrade' );
1857 + $has_show_upgrade_class = strpos( $field_type['icon'], ' frm_show_upgrade' );
2408 1858 $show_upgrade = $has_show_upgrade_class || false !== strpos( $args['no_allow_class'], 'frm_show_upgrade' );
2409 1859
2410 1860 if ( $has_show_upgrade_class ) {
2411 1861 $single_no_allow .= 'frm_show_upgrade';
@@ -2410,16 +1860,13 @@
2410 1860 if ( $has_show_upgrade_class ) {
2411 1861 $single_no_allow .= 'frm_show_upgrade';
2412 1862 $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
2413 1863 $run_filter = false;
2414 -
2415 1864 if ( isset( $field_type['addon'] ) ) {
2416 1865 $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
2417 -
2418 1866 if ( isset( $upgrading['url'] ) ) {
2419 1867 $install_data = json_encode( $upgrading );
2420 1868 }
2421 -
2422 1869 $requires = FrmFormsHelper::get_plan_required( $upgrading );
2423 1870 } elseif ( isset( $field_type['require'] ) ) {
2424 1871 $requires = $field_type['require'];
2425 1872 }
@@ -2426,9 +1873,8 @@
2426 1873 }
2427 1874
2428 1875 $upgrade_label = '';
2429 1876 $upgrade_message = '';
2430 -
2431 1877 if ( $show_upgrade ) {
2432 1878 /* translators: %s: Field name */
2433 1879 $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
2434 1880
@@ -2447,31 +1893,9 @@
2447 1893 'data-content' => $field_key,
2448 1894 'data-requires' => $requires,
2449 1895 );
2450 1896
2451 - if ( ! empty( $field_type['hide'] ) ) {
2452 - $li_params['class'] .= ' frm_hidden';
2453 - }
2454 -
2455 - if ( ! empty( $field_type['upsell_image'] ) ) {
2456 - $li_params['data-upsell-image'] = $field_type['upsell_image'];
2457 - }
2458 -
2459 - if ( ! empty( $field_type['learn-more'] ) ) {
2460 - $li_params['data-learn-more'] = FrmAppHelper::get_doc_url(
2461 - $field_type['learn-more'],
2462 - 'form-builder-add-fields',
2463 - false !== strpos( $field_type['learn-more'], '/' )
2464 - );
2465 - }
2466 -
2467 - if ( isset( $upgrading['url'] ) ) {
2468 - $li_params['data-message'] = sprintf(
2469 - // translators: %s: Field name
2470 - esc_html__( 'You already have access to %s fields, you\'ll just need to activate to start using them.', 'formidable' ),
2471 - $field_name
2472 - );
2473 - } elseif ( $upgrade_message ) {
1897 + if ( $upgrade_message ) {
2474 1898 $li_params['data-message'] = $upgrade_message;
2475 1899 }
2476 1900 ?>
2477 1901 <li <?php FrmAppHelper::array_to_html_params( $li_params, true ); ?>>
@@ -2478,9 +1902,9 @@
2478 1902 <?php
2479 1903 if ( $run_filter ) {
2480 1904 $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
2481 1905 }
2482 - FrmAppHelper::kses_echo( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) );
1906 + echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2483 1907 ?>
2484 1908 </li>
2485 1909 <?php
2486 1910 }
@@ -2490,33 +1914,14 @@
2490 1914 *
2491 1915 * @since 5.0.04
2492 1916 *
2493 1917 * @param array $field Field data.
2494 - *
2495 - * @return void
2496 1918 */
2497 1919 public static function show_radio_display_format( $field ) {
2498 - $options = self::get_display_format_options( $field );
2499 -
2500 - $args = self::get_display_format_args( $field, $options );
2501 -
2502 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php';
2503 - }
2504 -
2505 - /**
2506 - * Creates an array that contains variables used for display format options setting.
2507 - *
2508 - * @since 6.3.2
2509 - *
2510 - * @param array $field The field.
2511 - *
2512 - * @return array
2513 - */
2514 - public static function get_display_format_options( $field ) {
2515 1920 $options = array(
2516 1921 '0' => array(
2517 - 'text' => __( 'Simple', 'formidable' ),
2518 - 'svg' => 'frm_simple_radio',
1922 + 'text' => __( 'Simple', 'formidable' ),
1923 + 'svg' => 'frm_simple_radio',
2519 1924 ),
2520 1925 '1' => array(
2521 1926 'text' => __( 'Images', 'formidable' ),
2522 1927 'svg' => 'frm_image_as_option',
@@ -2540,13 +1945,14 @@
2540 1945 *
2541 1946 * @since 5.0.04
2542 1947 *
2543 1948 * @param array $options Options.
2544 - * @param array $field
2545 1949 */
2546 - $options = apply_filters( 'frm_' . $field['type'] . '_display_format_options', $options, $field );
1950 + $options = apply_filters( 'frm_radio_display_format_options', $options );
2547 1951
2548 - return $options;
1952 + $args = self::get_display_format_args( $field, $options );
1953 +
1954 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php';
2549 1955 }
2550 1956
2551 1957 /**
2552 1958 * Gets display format arguments to pass to the images_dropdown() method.
@@ -2554,12 +1960,11 @@
2554 1960 * @since 5.0.04
2555 1961 *
2556 1962 * @param array $field Field data.
2557 1963 * @param array $options Options array.
2558 - *
2559 1964 * @return array
2560 1965 */
2561 - public static function get_display_format_args( $field, $options ) {
1966 + private static function get_display_format_args( $field, $options ) {
2562 1967 $args = array(
2563 1968 'selected' => '0',
2564 1969 'options' => array(),
2565 1970 'name' => 'field_options[image_options_' . $field['id'] . ']',
@@ -2577,18 +1982,13 @@
2577 1982 *
2578 1983 * @param array $args Arguments.
2579 1984 * @param array $method_args The arguments from the method. Contains `field`, `options`.
2580 1985 */
2581 - return apply_filters( 'frm_' . $field['type'] . '_display_format_args', $args, compact( 'field', 'options' ) );
1986 + return apply_filters( 'frm_radio_display_format_args', $args, compact( 'field', 'options' ) );
2582 1987 }
2583 1988
2584 1989 /**
2585 1990 * @since 5.0.04
2586 - *
2587 - * @param array $options Options.
2588 - * @param array $args Arguments.
2589 - *
2590 - * @return void
2591 1991 */
2592 1992 private static function fill_image_setting_options( $options, &$args ) {
2593 1993 foreach ( $options as $key => $option ) {
2594 1994 $args['options'][ $key ] = $option;
@@ -2598,9 +1998,8 @@
2598 1998 }
2599 1999
2600 2000 unset( $args['options'][ $key ]['addon'] );
2601 2001 $fill = array( 'upgrade', 'message', 'content' );
2602 -
2603 2002 foreach ( $fill as $f ) {
2604 2003 unset( $args['options'][ $key ][ $f ], $f );
2605 2004 }
2606 2005 }
@@ -2608,10 +2007,8 @@
2608 2007
2609 2008 /**
2610 2009 * @since 5.0.04
2611 2010 *
2612 - * @param array $option Option.
2613 - *
2614 2011 * @return array
2615 2012 */
2616 2013 private static function fill_image_setting_addon_link( $option ) {
2617 2014 $custom_attrs = array(
@@ -2622,9 +2019,8 @@
2622 2019 // translators: Add-on name.
2623 2020 $custom_attrs['data-upgrade'] = sprintf( __( 'Formidable %s', 'formidable' ), ucwords( $option['addon'] ) );
2624 2021
2625 2022 $fill = array( 'upgrade', 'message', 'content' );
2626 -
2627 2023 foreach ( $fill as $f ) {
2628 2024 if ( isset( $option[ $f ] ) ) {
2629 2025 $custom_attrs[ 'data-' . $f ] = $option[ $f ];
2630 2026 }
@@ -2634,9 +2030,8 @@
2634 2030 return $custom_attrs;
2635 2031 }
2636 2032
2637 2033 $upgrading = FrmAddonsController::install_link( $option['addon'] );
2638 -
2639 2034 if ( isset( $upgrading['url'] ) ) {
2640 2035 $install_data = wp_json_encode( $upgrading );
2641 2036 } else {
2642 2037 $install_data = '';
@@ -2648,156 +2043,92 @@
2648 2043 return $custom_attrs;
2649 2044 }
2650 2045
2651 2046 /**
2652 - * Maybe adjust a field value based on type.
2653 - * Some types require unserializing an array.
2654 - * These types are defined by a array_allowed property on their field model class.
2655 - *
2656 - * @since 6.2
2657 - *
2658 - * @param mixed $value
2659 - * @param string $field_type
2660 - *
2661 - * @return void
2047 + * @deprecated 4.0
2662 2048 */
2663 - public static function prepare_field_value( &$value, $field_type ) {
2664 - $field_object = FrmFieldFactory::get_field_type( $field_type );
2665 - $value = $field_object->maybe_decode_value( $value );
2049 + public static function show_icon_link_js( $atts ) {
2050 + _deprecated_function( __METHOD__, '4.0' );
2051 + $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
2052 + if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
2053 + $atts['icon'] .= 'frm_hidden ';
2054 + }
2055 + echo '<a href="javascript:void(0)" class="frm_bstooltip ' . esc_attr( $atts['icon'] ) . 'frm_default_val_icons frm_action_icon frm_icon_font" title="' . esc_attr( $atts['message'] ) . '"></a>';
2666 2056 }
2667 2057
2668 2058 /**
2669 - * @since 6.8
2670 - *
2671 - * @param int|string $form_id
2672 - * @param array $field_ids If this is not empty, the results will be filtered by field id.
2673 - *
2674 - * @return array
2059 + * @deprecated 4.0
2675 2060 */
2676 - public static function get_draft_field_results( $form_id, $field_ids = array() ) {
2677 - if ( FrmAppHelper::pro_is_installed() ) {
2678 - $child_form_ids = FrmDb::get_col( 'frm_forms', array( 'parent_form_id' => $form_id ) );
2679 - $form_ids = array_merge( array( $form_id ), $child_form_ids );
2680 - } else {
2681 - $form_ids = array( $form_id );
2682 - }
2061 + public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
2062 + _deprecated_function( __METHOD__, '4.0' );
2063 + }
2683 2064
2684 - $where = array(
2685 - 'form_id' => $form_ids,
2686 - // Do a soft check for fields that look like drafts only.
2687 - 'field_options LIKE' => 's:5:"draft";i:1;',
2688 - );
2065 + /**
2066 + * @deprecated 4.0
2067 + */
2068 + public static function clear_on_focus_html( $field, $display, $id = '' ) {
2069 + _deprecated_function( __METHOD__, '4.0' );
2070 + }
2689 2071
2690 - if ( $field_ids ) {
2691 - $where['id'] = $field_ids;
2692 - }
2072 + /**
2073 + * @deprecated 4.0
2074 + */
2075 + public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
2076 + _deprecated_function( __METHOD__, '4.0' );
2077 + }
2693 2078
2694 - $rows = FrmDb::get_results( 'frm_fields', $where, 'id, field_options' );
2079 + /**
2080 + * @deprecated 3.0
2081 + * @codeCoverageIgnore
2082 + */
2083 + public static function display_recaptcha() {
2084 + _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
2085 + }
2695 2086
2696 - return array_filter(
2697 - $rows,
2698 - function ( $row ) {
2699 - FrmAppHelper::unserialize_or_decode( $row->field_options );
2700 - return is_array( $row->field_options ) && ! empty( $row->field_options['draft'] );
2701 - }
2702 - );
2087 + /**
2088 + * @deprecated 3.0
2089 + * @codeCoverageIgnore
2090 + */
2091 + public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
2092 + FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
2703 2093 }
2704 2094
2705 2095 /**
2706 - * This is called when loading the form builder.
2707 - * Any unsaved draft fields get added to a hidden draft_fields input on load.
2708 - *
2709 - * @since 6.8
2710 - *
2711 - * @param int|string $form_id
2712 - *
2713 - * @return array
2096 + * @deprecated 3.0
2097 + * @codeCoverageIgnore
2714 2098 */
2715 - public static function get_all_draft_field_ids( $form_id ) {
2716 - $draft_field_rows = self::get_draft_field_results( $form_id );
2717 - return wp_list_pluck( $draft_field_rows, 'id' );
2099 + public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
2100 + return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
2718 2101 }
2719 2102
2720 2103 /**
2721 - * Render AI generate options button.
2104 + * @deprecated 3.0
2105 + * @codeCoverageIgnore
2722 2106 *
2723 - * @since 6.24
2107 + * @param string $html
2108 + * @param array $field
2109 + * @param array $errors
2110 + * @param object|false $form
2111 + * @param array $args
2724 2112 *
2725 - * @param array $args Field arguments.
2726 - * @param bool $should_hide_bulk_edit Whether to hide bulk edit.
2727 - *
2728 - * @return void
2113 + * @return string
2729 2114 */
2730 - public static function render_ai_generate_options_button( $args, $should_hide_bulk_edit = false ) {
2731 - $attributes = array(
2732 - 'type' => 'button',
2733 - 'class' => self::get_ai_generate_options_button_class(),
2734 - );
2115 + public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
2116 + return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args );
2117 + }
2735 2118
2736 - if ( ! empty( $should_hide_bulk_edit ) ) {
2737 - $attributes['class'] .= ' frm-force-hidden';
2738 - }
2739 -
2740 - $data = FrmAppHelper::get_upgrade_data_params(
2741 - 'ai',
2742 - array(
2743 - 'requires' => 'Business',
2744 - 'upgrade' => __( 'Generate options with AI', 'formidable' ),
2745 - 'medium' => 'builder',
2746 - 'content' => 'generate-options-with-ai',
2747 - ),
2748 - true
2749 - );
2750 -
2751 - if ( in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) && 'active' === $data['plugin-status'] ) {
2752 - // Backwards compatibility "@since 6.24".
2753 - if ( ! method_exists( 'FrmAIAppController', 'get_ai_generated_options_summary' ) ) {
2754 - $data = array(
2755 - 'modal-title' => __( 'Generate options with AI', 'formidable' ),
2756 - 'modal-content' => __( 'Update the Formidable AI add-on to the last version to use this feature.', 'formidable' ),
2757 - );
2758 - } else {
2759 - $attributes['class'] .= ' frm-ai-generate-options-modal-trigger';
2760 - $attributes['data-fid'] = $args['likert_id'] ?? $args['field']['id'];
2761 - }
2762 - }
2763 -
2764 - if ( empty( $attributes['data-fid'] ) ) {
2765 - unset( $data['plugin-status'] );
2766 -
2767 - foreach ( $data as $key => $value ) {
2768 - $attributes[ 'data-' . $key ] = $value;
2769 - }
2770 - }
2771 -
2772 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/generate-options-with-ai.php';
2119 + /**
2120 + * @deprecated 3.0
2121 + * @codeCoverageIgnore
2122 + */
2123 + public static function get_default_field_opts( $type, $field = null, $limit = false ) {
2124 + return FrmDeprecated::get_default_field_opts( $type, $field, $limit );
2773 2125 }
2774 2126
2775 2127 /**
2776 - * Get AI generate options button class.
2777 - *
2778 - * @since 6.24
2779 - *
2780 - * @return string Button class.
2128 + * @deprecated 2.02.07
2129 + * @codeCoverageIgnore
2781 2130 */
2782 - private static function get_ai_generate_options_button_class() {
2783 - return implode(
2784 - ' ',
2785 - array(
2786 - 'frm_form_field',
2787 - 'frm6',
2788 - 'frm6_followed',
2789 - 'frm-h-stack',
2790 - 'button',
2791 - 'frm-button-secondary',
2792 - 'frm-button-gradient',
2793 - 'frm-rounded-6',
2794 - 'frm-max-w-fit',
2795 - 'frm-font-normal',
2796 - 'frm-py-2xs',
2797 - 'frm-px-xs',
2798 - 'frm-mt-xs',
2799 - 'frm-mb-12',
2800 - )
2801 - );
2131 + public static function dropdown_categories( $args ) {
2132 + return FrmDeprecated::dropdown_categories( $args );
2802 2133 }
2803 2134 }