PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.02
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 +199 -565 6.25.1 → 5.2.02 View file →
@@ -4,15 +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 8 public static function setup_new_vars( $type = '', $form_id = '' ) {
16 9
17 10 if ( strpos( $type, '|' ) ) {
18 11 list( $type, $setting ) = explode( '|', $type );
@@ -20,14 +13,9 @@
20 13
21 14 $values = self::get_default_field( $type );
22 15
23 16 global $wpdb;
24 - $field_count = FrmDb::get_var(
25 - 'frm_fields',
26 - array( 'form_id' => $form_id ),
27 - 'field_order',
28 - array( 'order_by' => 'field_order DESC' )
29 - );
17 + $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
30 18
31 19 $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' );
32 20 $values['form_id'] = $form_id;
33 21 $values['field_order'] = $field_count + 1;
@@ -33,10 +21,10 @@
33 21 $values['field_order'] = $field_count + 1;
34 22
35 23 $values['field_options']['custom_html'] = self::get_default_html( $type );
36 24
37 - if ( ! empty( $setting ) ) {
38 - if ( in_array( $type, array( 'data', 'lookup' ), true ) ) {
25 + if ( isset( $setting ) && ! empty( $setting ) ) {
26 + if ( in_array( $type, array( 'data', 'lookup' ) ) ) {
39 27 $values['field_options']['data_type'] = $setting;
40 28 } else {
41 29 $values['field_options'][ $setting ] = 1;
42 30 }
@@ -41,11 +29,8 @@
41 29 $values['field_options'][ $setting ] = 1;
42 30 }
43 31 }
44 32
45 - // Increase the field order of submit field and fields in the same row.
46 - FrmSubmitHelper::update_last_row_fields_order_when_adding_field( $field_count );
47 -
48 33 return $values;
49 34 }
50 35
51 36 public static function get_html_id( $field, $plus = '' ) {
@@ -62,9 +47,9 @@
62 47 $values = (array) $field;
63 48
64 49 self::fill_field_array( $field, $values );
65 50
66 - $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 );
67 52
68 53 return $values;
69 54 }
70 55
@@ -101,13 +86,8 @@
101 86 /**
102 87 * Prepare field while creating a new entry
103 88 *
104 89 * @since 3.0
105 - *
106 - * @param array $field_array
107 - * @param stdClass $field
108 - * @param array $args
109 - * @return void
110 90 */
111 91 private static function prepare_front_field( &$field_array, $field, $args ) {
112 92 self::fill_default_field_opts( $field, $field_array );
113 93 self::fill_cleared_strings( $field, $field_array );
@@ -112,26 +92,15 @@
112 92 self::fill_default_field_opts( $field, $field_array );
113 93 self::fill_cleared_strings( $field, $field_array );
114 94
115 95 // Track the original field's type
116 - $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;
117 97
118 98 self::prepare_field_options_for_display( $field_array, $field, $args );
119 99
120 - if ( $args['action'] === 'edit' ) {
121 - /**
122 - * @param array $field_array
123 - * @param stdClass $field
124 - * @param int|string $entry_id
125 - * @param array $args
126 - */
100 + if ( $args['action'] == 'edit' ) {
127 101 $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args );
128 102 } else {
129 - /**
130 - * @param array $field_array
131 - * @param stdClass $field
132 - * @param array $args
133 - */
134 103 $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args );
135 104 }
136 105 }
137 106
@@ -151,14 +120,14 @@
151 120 /**
152 121 * @since 3.0
153 122 *
154 123 * @param object $field
155 - * @param array $values
124 + * @param array $values
156 125 */
157 126 private static function fill_default_field_opts( $field, array &$values ) {
158 - $check_post = self::context_is_safe_to_load_field_options_from_request_data();
159 - $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
160 128
129 + $defaults = self::get_default_field_options_from_field( $field, $values );
161 130 if ( ! $check_post ) {
162 131 $defaults['required_indicator'] = '';
163 132 $defaults['original_type'] = $field->type;
164 133 }
@@ -163,63 +132,16 @@
163 132 $defaults['original_type'] = $field->type;
164 133 }
165 134
166 135 foreach ( $defaults as $opt => $default ) {
167 - $values[ $opt ] = $field->field_options[ $opt ] ?? $default;
136 + $values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default;
168 137
169 138 if ( $check_post ) {
170 139 self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] );
171 140 }
172 - }
173 - }
174 141
175 - /**
176 - * The fill_default_field_opts method is called when loading a field.
177 - * This is used to preserve the $_POST data after updating settings for a field.
178 - * To prevent this from happening when creating an entry, we need to check the context.
179 - *
180 - * @return bool
181 - */
182 - private static function context_is_safe_to_load_field_options_from_request_data() {
183 - if ( isset( self::$context_is_safe_to_load_field_options_from_request_data ) ) {
184 - return self::$context_is_safe_to_load_field_options_from_request_data;
142 + unset( $opt, $default );
185 143 }
186 -
187 - $function = function () {
188 - if ( ! FrmAppHelper::is_admin_page() ) {
189 - return false;
190 - }
191 -
192 - if ( ! $_POST || ! isset( $_POST['field_options'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
193 - return false;
194 - }
195 -
196 - if ( ! current_user_can( 'frm_edit_forms' ) ) {
197 - return false;
198 - }
199 -
200 - $action = FrmAppHelper::get_post_param( 'action', '', 'sanitize_title' );
201 - if ( 'frm_forms_preview' === $action ) {
202 - // Never trigger when previewing.
203 - return false;
204 - }
205 -
206 - // Confirm an allowed action is being used, and that the correct nonce is being used.
207 - if ( 'update' === $action ) {
208 - $nonce = FrmAppHelper::get_post_param( 'frm_save_form', '', 'sanitize_text_field' );
209 - return wp_verify_nonce( $nonce, 'frm_save_form_nonce' );
210 - }
211 -
212 - $action = FrmAppHelper::get_post_param( 'frm_action', '', 'sanitize_title' );
213 - if ( 'update_settings' === $action ) {
214 - $nonce = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
215 - return wp_verify_nonce( $nonce, 'process_form_nonce' );
216 - }
217 - };
218 -
219 - self::$context_is_safe_to_load_field_options_from_request_data = $function();
220 -
221 - return self::$context_is_safe_to_load_field_options_from_request_data;
222 144 }
223 145
224 146 /**
225 147 * Fill the required message, invalid message,
@@ -227,21 +149,23 @@
227 149 *
228 150 * @since 3.0
229 151 *
230 152 * @param object $field
231 - * @param array $field_array
153 + * @param array $field_array
232 154 */
233 155 private static function fill_cleared_strings( $field, array &$field_array ) {
156 + $frm_settings = FrmAppHelper::get_settings();
157 +
234 158 if ( '' == $field_array['blank'] && '1' === $field_array['required'] ) {
235 - $field_array['blank'] = self::default_blank_msg();
159 + $field_array['blank'] = $frm_settings->blank_msg;
236 160 }
237 161
238 - if ( '' === $field_array['invalid'] ) {
162 + if ( '' == $field_array['invalid'] ) {
239 163 if ( 'captcha' === $field->type ) {
240 - $frm_settings = FrmAppHelper::get_settings();
241 164 $field_array['invalid'] = $frm_settings->re_msg;
242 165 } else {
243 - $field_array['invalid'] = self::default_invalid_msg();
166 + /* translators: %s: Field name */
167 + $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
244 168 }
245 169 }
246 170
247 171 if ( '' == $field_array['custom_html'] ) {
@@ -249,48 +173,12 @@
249 173 }
250 174 }
251 175
252 176 /**
253 - * @since 6.8.3
254 - *
255 - * @return string
256 - */
257 - public static function default_invalid_msg() {
258 - /* translators: %s: [field_name] shortcode (Which gets replaced by a Field Name) */
259 - return sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' );
260 - }
261 -
262 - /**
263 - * @since 6.8.3
264 - *
265 - * @return string
266 - */
267 - public static function default_unique_msg() {
268 - $frm_settings = FrmAppHelper::get_settings();
269 - $unique_message = $frm_settings->unique_msg;
270 - $unique_message = str_replace( 'This value', '[field_name]', $unique_message );
271 - return $unique_message;
272 - }
273 -
274 - /**
275 - * @since 6.8.3
276 - *
277 - * @return string
278 - */
279 - public static function default_blank_msg() {
280 - $frm_settings = FrmAppHelper::get_settings();
281 - $blank_message = $frm_settings->blank_msg;
282 - $blank_message = str_replace( 'This field', '[field_name]', $blank_message );
283 - return $blank_message;
284 - }
285 -
286 - /**
287 - * When loading settings for a field, check the $_POST data and possibly use that instead of the DB value.
288 - *
289 177 * @since 3.0
290 178 *
291 179 * @param string $setting
292 - * @param mixed $value
180 + * @param mixed $value
293 181 */
294 182 private static function get_posted_field_setting( $setting, &$value ) {
295 183 if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
296 184 return;
@@ -296,14 +184,10 @@
296 184 return;
297 185 }
298 186
299 187 if ( strpos( $setting, 'html' ) !== false ) {
188 + // Strip slashes from HTML but not regex or script tags.
300 189 $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
301 -
302 - // Conditionally strip script tags if the user sending $_POST data is not allowed to use unfiltered HTML.
303 - if ( ! FrmAppHelper::allow_unfiltered_html() ) {
304 - $value = FrmAppHelper::kses( $value, 'all' );
305 - }
306 190 } elseif ( strpos( $setting, 'format_' ) === 0 ) {
307 191 // TODO: Remove stripslashes on output, and use on input only.
308 192 $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
309 193 } else {
@@ -315,9 +199,9 @@
315 199 /**
316 200 * @since 3.0
317 201 *
318 202 * @param object $field
319 - * @param array $values The field array is needed for hooks.
203 + * @param array $values The field array is needed for hooks
320 204 *
321 205 * @return array
322 206 */
323 207 public static function get_default_field_options_from_field( $field, $values = array() ) {
@@ -334,9 +218,9 @@
334 218 * @since 3.0
335 219 *
336 220 * @param object $field
337 221 *
338 - * @return FrmFieldType
222 + * @return array
339 223 */
340 224 private static function get_original_field( $field ) {
341 225 $original_type = FrmField::get_option( $field, 'original_type' );
342 226 if ( ! empty( $original_type ) && $field->type != $original_type ) {
@@ -348,11 +232,11 @@
348 232
349 233 /**
350 234 * @since 3.0
351 235 *
352 - * @param array $field_array
236 + * @param array $field_array
353 237 * @param object $field
354 - * @param array $atts
238 + * @param array $atts
355 239 */
356 240 private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
357 241 $field_obj = FrmFieldFactory::get_field_object( $field );
358 242 $field_array = $field_obj->prepare_front_field( $field_array, $atts );
@@ -386,27 +270,29 @@
386 270
387 271 /**
388 272 * @since 2.0
389 273 *
390 - * @param array|object $field
391 - * @param string $error
274 + * @param $field
275 + * @param $error
392 276 *
393 277 * @return string
394 278 */
395 279 public static function get_error_msg( $field, $error ) {
396 - $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;
397 283
398 284 $conf_msg = __( 'The entered values do not match', 'formidable' );
399 285 $defaults = array(
400 286 'unique_msg' => array(
401 - 'full' => self::default_unique_msg(),
287 + 'full' => $default_settings['unique_msg'],
402 288 /* translators: %s: Field name */
403 - 'part' => sprintf( __( '%s must be unique', 'formidable' ), '[field_name]' ),
289 + 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ),
404 290 ),
405 291 'invalid' => array(
406 292 'full' => __( 'This field is invalid', 'formidable' ),
407 293 /* translators: %s: Field name */
408 - 'part' => sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' ),
294 + 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ),
409 295 ),
410 296 'blank' => array(
411 297 'full' => $frm_settings->blank_msg,
412 298 'part' => $frm_settings->blank_msg,
@@ -420,74 +306,11 @@
420 306 $msg = FrmField::get_option( $field, $error );
421 307 $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
422 308 $msg = do_shortcode( $msg );
423 309
424 - $msg = self::maybe_replace_substrings_with_field_name( $msg, $error, $field );
425 -
426 310 return $msg;
427 311 }
428 312
429 - /**
430 - * @since 6.8.3
431 - *
432 - * @param string $msg
433 - * @param string $error
434 - * @param array|object $field
435 - */
436 - private static function maybe_replace_substrings_with_field_name( $msg, $error, $field ) {
437 - $field_name = is_array( $field ) ? $field['name'] : $field->name;
438 - $field_name = FrmAppHelper::maybe_kses( $field_name );
439 - $substrings = self::get_substrings_to_replace_with_field_name( $field_name, compact( 'msg', 'error', 'field' ) );
440 -
441 - // Use the "This value"/"This field" placeholder strings if field name is empty.
442 - if ( ! $field_name ) {
443 - if ( 'unique_msg' === $error ) {
444 - $field_name = __( 'This value', 'formidable' );
445 - } else {
446 - $field_name = __( 'This field', 'formidable' );
447 - }
448 - }
449 -
450 - $msg = str_replace( $substrings, $field_name, $msg );
451 - return $msg;
452 - }
453 -
454 - /**
455 - * @since 6.8.3
456 - *
457 - * @param string $field_name
458 - * @param array $filter_args {
459 - * Filter arguments.
460 - *
461 - * @type string $msg The current error message before the substrings are replaced.
462 - * @type string $error A key including 'unique_msg', 'invalid', 'blank', or 'conf_msg'.
463 - * @type array|object $field The field with the error.
464 - * }
465 - * @return array
466 - */
467 - private static function get_substrings_to_replace_with_field_name( $field_name, $filter_args ) {
468 - $substrings = array( '[field_name]' );
469 - if ( $field_name ) {
470 - array_push( $substrings, 'This value', 'This field' );
471 - }
472 -
473 - /**
474 - * @since 6.8.3
475 - *
476 - * @param array<string> $substrings
477 - * @param array $filter_args
478 - */
479 - $filtered_substrings = apply_filters( 'frm_error_substrings_to_replace_with_field_name', $substrings, $filter_args );
480 -
481 - if ( is_array( $filtered_substrings ) ) {
482 - $substrings = $filtered_substrings;
483 - } else {
484 - _doing_it_wrong( __METHOD__, 'Only arrays should be returned when using the frm_error_substrings_to_replace_with_field_name filter.', '6.8.3' );
485 - }
486 -
487 - return $substrings;
488 - }
489 -
490 313 public static function get_form_fields( $form_id, $error = array() ) {
491 314 $fields = FrmField::get_all_for_form( $form_id );
492 315
493 316 return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
@@ -505,12 +328,12 @@
505 328 return apply_filters( 'frm_custom_html', $default_html, $type );
506 329 }
507 330
508 331 /**
509 - * @param array $fields
510 - * @param array $errors
332 + * @param array $fields
333 + * @param array $errors
511 334 * @param object $form
512 - * @param object $form_action
335 + * @param $form_action
513 336 */
514 337 public static function show_fields( $fields, $errors, $form, $form_action ) {
515 338 foreach ( $fields as $field ) {
516 339 $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field );
@@ -520,13 +343,13 @@
520 343
521 344 /**
522 345 * @since 3.0
523 346 *
524 - * @param array $atts
525 - * @param array|string $value
347 + * @param array $atts
348 + * @param string|array $value
526 349 */
527 350 public static function run_wpautop( $atts, &$value ) {
528 - $autop = $atts['wpautop'] ?? true;
351 + $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true;
529 352 if ( apply_filters( 'frm_use_wpautop', $autop ) ) {
530 353 if ( is_array( $value ) ) {
531 354 $value = implode( "\n", $value );
532 355 }
@@ -540,9 +363,9 @@
540 363 * @since 2.05
541 364 */
542 365 public static function &label_position( $position, $field, $form ) {
543 366 if ( $position && $position != '' ) {
544 - if ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
367 + if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
545 368 $position = 'top';
546 369 }
547 370
548 371 return $position;
@@ -548,18 +371,18 @@
548 371 return $position;
549 372 }
550 373
551 374 $position = FrmStylesController::get_style_val( 'position', $form );
552 - if ( $position === 'none' ) {
375 + if ( $position == 'none' ) {
553 376 $position = 'top';
554 - } elseif ( $position === 'no_label' ) {
377 + } elseif ( $position == 'no_label' ) {
555 378 $position = 'none';
556 - } elseif ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
379 + } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
557 380 $position = 'top';
558 381 }
559 382
560 383 $position = apply_filters( 'frm_html_label_position', $position, $field, $form );
561 - $position = ! empty( $position ) ? $position : 'top';
384 + $position = ( ! empty( $position ) ) ? $position : 'top';
562 385
563 386 return $position;
564 387 }
565 388
@@ -590,12 +413,11 @@
590 413 return;
591 414 }
592 415
593 416 $base_name = 'default_value_' . $field['id'];
594 - $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 );
595 418
596 - $default_type = self::get_default_value_type( $field );
597 - $options_count = count( $field['options'] );
419 + $default_type = self::get_default_value_type( $field );
598 420
599 421 foreach ( $field['options'] as $opt_key => $opt ) {
600 422 $field_val = self::get_value_from_array( $opt, $opt_key, $field );
601 423 $opt = self::get_label_from_array( $opt, $opt_key, $field );
@@ -606,12 +428,12 @@
606 428
607 429 // If this is an "Other" option, get the HTML for it.
608 430 if ( self::is_other_opt( $opt_key ) ) {
609 431 if ( FrmAppHelper::pro_is_installed() ) {
610 - require FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php';
432 + require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' );
611 433 }
612 434 } else {
613 - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
435 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
614 436 }
615 437
616 438 unset( $checked );
617 439 }
@@ -634,14 +456,14 @@
634 456 $field_val = __( 'New Option', 'formidable' );
635 457 $opt = __( 'New Option', 'formidable' );
636 458 $checked = false;
637 459 $field_name = 'default_value_' . $field['id'];
638 - $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 );
639 461
640 462 $default_type = self::get_default_value_type( $field );
641 463 $field_name .= ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
642 464
643 - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
465 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
644 466 }
645 467
646 468 /**
647 469 * @since 4.0
@@ -669,29 +491,22 @@
669 491 return FrmFieldsController::check_label( $opt );
670 492 }
671 493
672 494 /**
673 - * Shows the inline modal.
674 - *
675 495 * @since 4.0
676 - * @since 6.4.1 Added `inside_class` in the arguments.
677 - *
678 - * @param array $args The arguments.
679 496 */
680 497 public static function inline_modal( $args ) {
681 498 $defaults = array(
682 - 'id' => '',
683 - 'class' => '',
684 - 'show' => 0,
685 - 'callback' => array(),
686 - 'args' => array(),
687 - 'title' => '',
688 - 'inside_class' => 'inside',
689 - 'dismiss-icon' => true,
499 + 'id' => '',
500 + 'class' => '',
501 + 'show' => 0,
502 + 'callback' => array(),
503 + 'args' => array(),
504 + 'title' => '',
690 505 );
691 - $args = array_merge( $defaults, $args );
506 + $args = array_merge( $defaults, $args );
692 507
693 - 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' );
694 509 }
695 510
696 511 /**
697 512 * @since 4.0
@@ -702,9 +517,9 @@
702 517 $upgrade_link = array(
703 518 'medium' => 'builder',
704 519 'content' => 'smart-tags',
705 520 );
706 - 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' );
707 522 }
708 523 }
709 524
710 525 /**
@@ -710,9 +525,9 @@
710 525 /**
711 526 * @since 4.0
712 527 */
713 528 public static function input_mask() {
714 - 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' );
715 530 }
716 531
717 532 /**
718 533 * @since 4.0
@@ -717,9 +532,9 @@
717 532 /**
718 533 * @since 4.0
719 534 */
720 535 public static function layout_classes() {
721 - 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' );
722 537 }
723 538
724 539 /**
725 540 * @param int $tax_id
@@ -745,10 +560,10 @@
745 560 return $link;
746 561 }
747 562
748 563 public static function value_meets_condition( $observed_value, $cond, $hide_opt ) {
749 - $hide_opt = self::get_value_for_comparison( $hide_opt );
750 - $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 );
751 566
752 567 if ( is_array( $observed_value ) ) {
753 568 return self::array_value_condition( $observed_value, $cond, $hide_opt );
754 569 }
@@ -768,11 +583,11 @@
768 583 $m = $observed_value <= $hide_opt;
769 584 } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) {
770 585 $m = stripos( $observed_value, $hide_opt );
771 586 if ( $cond === 'not LIKE' ) {
772 - $m = $m === false;
587 + $m = ( $m === false ) ? true : false;
773 588 } else {
774 - $m = $m !== false;
589 + $m = ( $m === false ) ? false : true;
775 590 }
776 591 } elseif ( $cond === '%LIKE' ) {
777 592 // ends with
778 593 $length = strlen( $hide_opt );
@@ -782,9 +597,9 @@
782 597 // starts with
783 598 $length = strlen( $hide_opt );
784 599 $substr = substr( $observed_value, 0, $length );
785 600 $m = 0 === strcasecmp( $substr, $hide_opt );
786 - }//end if
601 + }
787 602
788 603 return $m;
789 604 }
790 605
@@ -792,9 +607,9 @@
792 607 * Trim and sanitize the values
793 608 *
794 609 * @since 2.05
795 610 */
796 - private static function get_value_for_comparison( $value ) {
611 + private static function get_value_for_comparision( $value ) {
797 612 // Remove white space from hide_opt
798 613 if ( ! is_array( $value ) ) {
799 614 $value = trim( $value );
800 615 }
@@ -808,9 +623,9 @@
808 623 $m = false;
809 624 if ( $cond === '==' ) {
810 625 if ( is_array( $hide_opt ) ) {
811 626 $m = array_intersect( $hide_opt, $observed_value );
812 - $m = ! empty( $m );
627 + $m = empty( $m ) ? false : true;
813 628 } else {
814 629 $m = in_array( $hide_opt, $observed_value );
815 630 }
816 631 } elseif ( $cond === '!=' ) {
@@ -830,9 +645,9 @@
830 645 }
831 646 }
832 647
833 648 if ( $cond === 'not LIKE' ) {
834 - $m = $m === false;
649 + $m = ( $m === false ) ? true : false;
835 650 }
836 651 } elseif ( $cond === '%LIKE' ) {
837 652 // ends with
838 653 foreach ( $observed_value as $ob ) {
@@ -848,9 +663,9 @@
848 663 $m = true;
849 664 break;
850 665 }
851 666 }
852 - }//end if
667 + }
853 668
854 669 return $m;
855 670 }
856 671
@@ -899,16 +714,13 @@
899 714 'ip',
900 715 'siteurl',
901 716 'sitename',
902 717 'admin_email',
903 - 'default-email',
904 - 'default-from-email',
905 718 'post[-|_]id',
906 719 'created[-|_]at',
907 720 'updated[-|_]at',
908 721 'updated[-|_]by',
909 722 'parent[-|_]id',
910 - 'form_name',
911 723 );
912 724
913 725 foreach ( $fields as $field ) {
914 726 $tagregexp[] = $field->id;
@@ -947,18 +759,13 @@
947 759
948 760 /**
949 761 * @param string $replace_with
950 762 * @param array $atts
951 - * @return string
952 763 */
953 764 private static function trigger_shortcode_atts( $replace_with, $atts ) {
954 - $supported_atts = array( 'remove_accents', 'sanitize', 'sanitize_url' );
765 + $supported_atts = array( 'sanitize', 'sanitize_url' );
955 766 $included_atts = array_intersect( $supported_atts, array_keys( $atts ) );
956 767 foreach ( $included_atts as $included_att ) {
957 - if ( '0' === $atts[ $included_att ] ) {
958 - // Skip any option that uses 0 so sanitize_url=0 does not encode.
959 - continue;
960 - }
961 768 $function = 'atts_' . $included_att;
962 769 $replace_with = self::$function( $replace_with, $atts );
963 770 }
964 771 return $replace_with;
@@ -964,21 +771,8 @@
964 771 return $replace_with;
965 772 }
966 773
967 774 /**
968 - * Converts all accent characters to ASCII characters.
969 - *
970 - * @since 6.3.1
971 - *
972 - * @param string $replace_with The text to remove accents from.
973 - *
974 - * @return string
975 - */
976 - public static function atts_remove_accents( $replace_with ) {
977 - return remove_accents( $replace_with );
978 - }
979 -
980 - /**
981 775 * @param string $replace_with
982 776 * @return string
983 777 */
984 778 private static function atts_sanitize( $replace_with ) {
@@ -997,17 +791,12 @@
997 791 * Prevent shortcodes in fields from being processed
998 792 *
999 793 * @since 3.01.02
1000 794 *
1001 - * @param array $atts Includes entry object.
1002 - * @param string|null $value
1003 - * @return void
795 + * @param array $atts - includes entry object
796 + * @param string $value
1004 797 */
1005 798 public static function sanitize_embedded_shortcodes( $atts, &$value ) {
1006 - if ( is_null( $value ) ) {
1007 - return;
1008 - }
1009 -
1010 799 $atts['value'] = $value;
1011 800 $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
1012 801 if ( $should_sanitize ) {
1013 802 $value = str_replace( '[', '&#91;', $value );
@@ -1016,9 +805,9 @@
1016 805
1017 806 /**
1018 807 * @since 3.0
1019 808 *
1020 - * @param array $atts
809 + * @param $atts
1021 810 *
1022 811 * @return string
1023 812 */
1024 813 private static function get_value_for_shortcode( $atts ) {
@@ -1029,21 +818,21 @@
1029 818 'key' => $atts['entry']->item_key,
1030 819 'ip' => $atts['entry']->ip,
1031 820 );
1032 821
1033 - $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get', 'default-email', 'default-from-email' );
822 + $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
1034 823
1035 824 if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
1036 825 $replace_with = $shortcode_values[ $atts['tag'] ];
1037 - } elseif ( in_array( $atts['tag'], $dynamic_default, true ) ) {
826 + } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
1038 827 $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
1039 - } elseif ( $clean_tag === 'user_agent' ) {
828 + } elseif ( $clean_tag == 'user_agent' ) {
1040 829 $description = $atts['entry']->description;
1041 830 $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
1042 - } elseif ( $clean_tag === 'created_at' || $clean_tag === 'updated_at' ) {
831 + } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
1043 832 $atts['tag'] = $clean_tag;
1044 833 $replace_with = self::get_entry_timestamp( $atts );
1045 - } elseif ( $clean_tag === 'created_by' || $clean_tag === 'updated_by' ) {
834 + } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
1046 835 $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
1047 836 } else {
1048 837 $replace_with = self::get_field_shortcode_value( $atts );
1049 838 }
@@ -1053,9 +842,9 @@
1053 842
1054 843 /**
1055 844 * @since 3.0
1056 845 *
1057 - * @param array $atts
846 + * @param $atts
1058 847 *
1059 848 * @return string
1060 849 */
1061 850 private static function get_entry_timestamp( $atts ) {
@@ -1071,11 +860,11 @@
1071 860
1072 861 /**
1073 862 * @since 3.0
1074 863 *
1075 - * @param array $atts
864 + * @param $atts
1076 865 *
1077 - * @return string|null
866 + * @return null|string
1078 867 */
1079 868 private static function get_field_shortcode_value( $atts ) {
1080 869 $field = FrmField::getOne( $atts['tag'] );
1081 870 if ( empty( $field ) ) {
@@ -1089,10 +878,10 @@
1089 878 } else {
1090 879 $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
1091 880 $string_value = $replace_with;
1092 881 if ( is_array( $replace_with ) ) {
1093 - $sep = $atts['sep'] ?? ', ';
1094 - $string_value = FrmAppHelper::safe_implode( $sep, $replace_with );
882 + $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
883 + $string_value = implode( $sep, $replace_with );
1095 884 }
1096 885
1097 886 if ( empty( $string_value ) && $string_value != '0' ) {
1098 887 $replace_with = '';
@@ -1117,16 +906,8 @@
1117 906 switch ( $tag ) {
1118 907 case 'admin_email':
1119 908 $new_value = get_option( 'admin_email' );
1120 909 break;
1121 - case 'default-email':
1122 - $frm_settings = FrmAppHelper::get_settings();
1123 - $new_value = ! empty( $frm_settings->default_email ) && is_email( $frm_settings->default_email ) ? $frm_settings->default_email : get_option( 'admin_email' );
1124 - break;
1125 - case 'default-from-email':
1126 - $frm_settings = FrmAppHelper::get_settings();
1127 - $new_value = ! empty( $frm_settings->from_email ) && is_email( $frm_settings->from_email ) ? $frm_settings->from_email : get_option( 'admin_email' );
1128 - break;
1129 910 case 'siteurl':
1130 911 $new_value = FrmAppHelper::site_url();
1131 912 break;
1132 913 case 'frmurl':
@@ -1136,9 +917,9 @@
1136 917 $new_value = FrmAppHelper::site_name();
1137 918 break;
1138 919 case 'get':
1139 920 $new_value = self::process_get_shortcode( $atts, $return_array );
1140 - }//end switch
921 + }
1141 922
1142 923 return $new_value;
1143 924 }
1144 925
@@ -1145,9 +926,9 @@
1145 926 /**
1146 927 * Process the [get] shortcode
1147 928 *
1148 929 * @since 2.0
1149 - * @return array|string
930 + * @return string|array
1150 931 */
1151 932 public static function process_get_shortcode( $atts, $return_array = false ) {
1152 933 if ( ! isset( $atts['param'] ) ) {
1153 934 return '';
@@ -1165,9 +946,9 @@
1165 946 if ( ! isset( $atts['prev_val'] ) ) {
1166 947 $atts['prev_val'] = '';
1167 948 }
1168 949
1169 - $new_value = $atts['default'] ?? $atts['prev_val'];
950 + $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
1170 951 }
1171 952
1172 953 if ( is_array( $new_value ) && ! $return_array ) {
1173 954 $new_value = implode( ', ', $new_value );
@@ -1186,14 +967,14 @@
1186 967 return apply_filters( 'frm_display_value', $value, $field, $atts );
1187 968 }
1188 969
1189 970 /**
1190 - * @param array $atts Includes value, field, and atts.
971 + * @param $atts array Includes value, field, and atts
1191 972 */
1192 973 public static function get_unfiltered_display_value( $atts ) {
1193 974 $value = $atts['value'];
1194 975 $field = $atts['field'];
1195 - $atts = $atts['atts'] ?? $atts;
976 + $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
1196 977
1197 978 if ( is_array( $field ) ) {
1198 979 $field = $field['id'];
1199 980 }
@@ -1206,10 +987,8 @@
1206 987 /**
1207 988 * Get a value from the user profile from the user ID
1208 989 *
1209 990 * @since 3.0
1210 - *
1211 - * @return string
1212 991 */
1213 992 public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
1214 993 $defaults = array(
1215 994 'blank' => false,
@@ -1222,14 +1001,14 @@
1222 1001 $user = get_userdata( $user_id );
1223 1002 $info = '';
1224 1003
1225 1004 if ( $user ) {
1226 - if ( $user_info === 'avatar' ) {
1005 + if ( $user_info == 'avatar' ) {
1227 1006 $info = get_avatar( $user_id, $args['size'] );
1228 - } elseif ( $user_info === 'author_link' ) {
1007 + } elseif ( $user_info == 'author_link' ) {
1229 1008 $info = get_author_posts_url( $user_id );
1230 1009 } else {
1231 - $info = $user->$user_info ?? '';
1010 + $info = isset( $user->$user_info ) ? $user->$user_info : '';
1232 1011 }
1233 1012
1234 1013 if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
1235 1014 $info = $user->user_login;
@@ -1242,21 +1021,18 @@
1242 1021
1243 1022 return $info;
1244 1023 }
1245 1024
1246 - /**
1247 - * @param string $type
1248 - * @return array
1249 - */
1250 1025 public static function get_field_types( $type ) {
1251 - $single_input = self::single_input_fields();
1252 - $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 +
1253 1029 $field_selection = FrmField::all_field_selection();
1254 - $field_types = array();
1255 1030
1256 - if ( in_array( $type, $single_input, true ) ) {
1031 + $field_types = array();
1032 + if ( in_array( $type, $single_input ) ) {
1257 1033 self::field_types_for_input( $single_input, $field_selection, $field_types );
1258 - } elseif ( in_array( $type, $multiple_input, true ) ) {
1034 + } elseif ( in_array( $type, $multiple_input ) ) {
1259 1035 self::field_types_for_input( $multiple_input, $field_selection, $field_types );
1260 1036 } elseif ( isset( $field_selection[ $type ] ) ) {
1261 1037 $field_types[ $type ] = $field_selection[ $type ];
1262 1038 }
@@ -1284,25 +1060,15 @@
1284 1060 'hidden',
1285 1061 'time',
1286 1062 'tag',
1287 1063 'password',
1288 - 'gdpr',
1289 1064 );
1290 1065 return apply_filters( 'frm_single_input_fields', $fields );
1291 1066 }
1292 1067
1293 - /**
1294 - * @param string[] $inputs
1295 - * @param array $fields
1296 - * @param array $field_types
1297 - * @return void
1298 - */
1299 1068 private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1300 1069 foreach ( $inputs as $input ) {
1301 - // This may not be set if a field type was removed using the frm_available_fields or frm_pro_available_fields filters.
1302 - if ( array_key_exists( $input, $fields ) ) {
1303 - $field_types[ $input ] = $fields[ $input ];
1304 - }
1070 + $field_types[ $input ] = $fields[ $input ];
1305 1071 unset( $input );
1306 1072 }
1307 1073 }
1308 1074
@@ -1312,9 +1078,9 @@
1312 1078 * @since 2.0.6
1313 1079 *
1314 1080 * @param string $opt_key
1315 1081 *
1316 - * @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
1317 1083 */
1318 1084 public static function is_other_opt( $opt_key ) {
1319 1085 return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1320 1086 }
@@ -1357,11 +1123,10 @@
1357 1123 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1358 1124 }
1359 1125
1360 1126 return $other_val;
1361 - }
1362 1127
1363 - 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
1364 1129 // For normal fields
1365 1130
1366 1131 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1367 1132 // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -1370,9 +1135,9 @@
1370 1135 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1371 1136 }
1372 1137
1373 1138 return $other_val;
1374 - }//end if
1139 + }
1375 1140
1376 1141 // For checkboxes
1377 1142 if ( $field['type'] === 'checkbox' && is_array( $field['value'] ) ) {
1378 1143 // Check if there is an "other" val in saved value and make sure the
@@ -1384,9 +1149,9 @@
1384 1149 /**
1385 1150 * For radio buttons and dropdowns
1386 1151 * Check if saved value equals any of the options. If not, set it as the other value.
1387 1152 */
1388 - foreach ( $field['options'] as $opt_val ) {
1153 + foreach ( $field['options'] as $opt_key => $opt_val ) {
1389 1154 $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1390 1155 // Multi-select dropdowns - key is not preserved
1391 1156 if ( is_array( $field['value'] ) ) {
1392 1157 $o_key = array_search( $temp_val, $field['value'] );
@@ -1398,15 +1163,15 @@
1398 1163 return '';
1399 1164 } else {
1400 1165 $other_val = $field['value'];
1401 1166 }
1402 - unset( $opt_val, $temp_val );
1167 + unset( $opt_key, $opt_val, $temp_val );
1403 1168 }
1404 1169 // For multi-select dropdowns only
1405 1170 if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1406 1171 $other_val = reset( $field['value'] );
1407 1172 }
1408 - }//end if
1173 + }
1409 1174
1410 1175 return $other_val;
1411 1176 }
1412 1177
@@ -1415,10 +1180,10 @@
1415 1180 * Intended for front-end use
1416 1181 *
1417 1182 * @since 2.0.6
1418 1183 *
1419 - * @param array $args Should include field, opt_key and field name.
1420 - * @param bool $other_opt
1184 + * @param array $args should include field, opt_key and field name
1185 + * @param boolean $other_opt
1421 1186 * @param string $checked
1422 1187 *
1423 1188 * @return array $other_args
1424 1189 */
@@ -1427,14 +1192,14 @@
1427 1192 'name' => '',
1428 1193 'value' => '',
1429 1194 );
1430 1195
1431 - // Check if this is an "Other" option.
1196 + //Check if this is an "Other" option
1432 1197 if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1433 1198 return $other_args;
1434 1199 }
1435 1200
1436 - $other_opt = true;
1201 + $other_opt = true;
1437 1202
1438 1203 self::set_other_name( $args, $other_args );
1439 1204 self::set_other_value( $args, $other_args );
1440 1205
@@ -1441,34 +1206,25 @@
1441 1206 if ( '' !== $other_args['value'] ) {
1442 1207 $checked = 'checked="checked" ';
1443 1208 }
1444 1209
1445 - // If 'other' is selected as one of the default values for a checkbox field, 'checked' attribute should be on.
1446 - if ( ! $checked &&
1447 - $args['field']['type'] === 'checkbox' &&
1448 - is_array( $args['field']['value'] ) &&
1449 - isset( $args['field_val'] ) &&
1450 - in_array( $args['field_val'], $args['field']['value'], true )
1451 - ) {
1452 - $checked = 'checked="checked" ';
1453 - }
1454 -
1455 1210 return $other_args;
1456 1211 }
1457 1212
1458 1213 /**
1459 - * @since 2.0.6
1460 1214 * @param array $args
1461 1215 * @param array $other_args
1216 + *
1217 + * @since 2.0.6
1462 1218 */
1463 1219 private static function set_other_name( $args, &$other_args ) {
1464 - // Set up name for other field
1220 + //Set up name for other field
1465 1221 $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1466 1222 $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] );
1467 1223 $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']';
1468 1224
1469 - // Converts item_meta[field_id] => item_meta[other][field_id] and
1470 - // 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]
1471 1227 if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1472 1228 $other_args['name'] .= '[' . $args['opt_key'] . ']';
1473 1229 }
1474 1230 }
@@ -1475,11 +1231,12 @@
1475 1231
1476 1232 /**
1477 1233 * Find the parent and pointer, and get text for "other" text field
1478 1234 *
1479 - * @since 2.0.6
1480 1235 * @param array $args
1481 1236 * @param array $other_args
1237 + *
1238 + * @since 2.0.6
1482 1239 */
1483 1240 private static function set_other_value( $args, &$other_args ) {
1484 1241 $parent = '';
1485 1242 $pointer = '';
@@ -1506,10 +1263,11 @@
1506 1263
1507 1264 /**
1508 1265 * If this field includes an other option, show it
1509 1266 *
1267 + * @param $args array
1268 + *
1510 1269 * @since 2.0.6
1511 - * @param array $args
1512 1270 */
1513 1271 public static function include_other_input( $args ) {
1514 1272 if ( ! $args['other_opt'] ) {
1515 1273 return;
@@ -1519,9 +1277,9 @@
1519 1277 if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1520 1278 // hide the field if the other option is not selected
1521 1279 $classes[] = 'frm_pos_none';
1522 1280 }
1523 - if ( $args['field']['type'] === 'select' && ! empty( $args['field']['multiple'] ) ) {
1281 + if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1524 1282 $classes[] = 'frm_other_full';
1525 1283 }
1526 1284
1527 1285 // Set up HTML ID for Other field
@@ -1526,9 +1284,9 @@
1526 1284
1527 1285 // Set up HTML ID for Other field
1528 1286 $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1529 1287
1530 - $label = $args['opt_label'] ?? $args['field']['name'];
1288 + $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1531 1289
1532 1290 echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1533 1291 esc_html( $label ) .
1534 1292 '</label>' .
@@ -1542,11 +1300,11 @@
1542 1300 * Note: This does not affect fields in repeating sections
1543 1301 *
1544 1302 * @since 2.0.08
1545 1303 *
1546 - * @param string $type Field type.
1547 - * @param string $html_id
1548 - * @param bool|string $opt_key
1304 + * @param string $type - field type
1305 + * @param string $html_id
1306 + * @param string|boolean $opt_key
1549 1307 *
1550 1308 * @return string $other_id
1551 1309 */
1552 1310 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
@@ -1552,9 +1310,9 @@
1552 1310 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1553 1311 $other_id = $html_id;
1554 1312
1555 1313 // If hidden radio field, add an opt key of 0
1556 - if ( $type === 'radio' && $opt_key === false ) {
1314 + if ( $type == 'radio' && $opt_key === false ) {
1557 1315 $opt_key = 0;
1558 1316 }
1559 1317
1560 1318 if ( $opt_key !== false ) {
@@ -1588,25 +1346,13 @@
1588 1346 $replace[] = '[' . $old . ']';
1589 1347 $replace_with[] = '[' . $new . ']';
1590 1348 $replace[] = '[' . $old . ' ';
1591 1349 $replace_with[] = '[' . $new . ' ';
1592 - $replace[] = 'field_id="' . $old . '"';
1593 - $replace_with[] = 'field_id="' . $new . '"';
1594 - $replace[] = 'field_id=\"' . $old . '\"';
1595 - $replace_with[] = 'field_id=\"' . $new . '\"';
1596 - // This covers conditional logic.
1597 - $replace[] = '_field":"' . $old . '","';
1598 - $replace_with[] = '_field":"' . $new . '","';
1599 1350 unset( $old, $new );
1600 - }//end foreach
1351 + }
1601 1352 if ( is_array( $val ) ) {
1602 1353 foreach ( $val as $k => $v ) {
1603 1354 if ( is_string( $v ) ) {
1604 - if ( 'custom_html' === $k ) {
1605 - $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v );
1606 - unset( $k, $v );
1607 - continue;
1608 - }
1609 1355 $val[ $k ] = str_replace( $replace, $replace_with, $v );
1610 1356 unset( $k, $v );
1611 1357 }
1612 1358 }
@@ -1617,33 +1363,8 @@
1617 1363 return $val;
1618 1364 }
1619 1365
1620 1366 /**
1621 - * Removes exception strings from replacement arrays and replaces the rest in the provided value string.
1622 - *
1623 - * @since 6.14
1624 - *
1625 - * @param array $replace Values to be replaced.
1626 - * @param array $replace_with Replacement values.
1627 - * @param array $exceptions Array of strings to skip.
1628 - * @param string $value Value to be updated.
1629 - *
1630 - * @return string
1631 - */
1632 - private static function switch_ids_except_strings( $replace, $replace_with, $exceptions, $value ) {
1633 - foreach ( $exceptions as $exception ) {
1634 - $index = array_search( $exception, $replace, true );
1635 - if ( false === $index ) {
1636 - continue;
1637 - }
1638 - unset( $replace[ $index ] );
1639 - unset( $replace_with[ $index ] );
1640 - }
1641 - $value = str_replace( $replace, $replace_with, $value );
1642 - return $value;
1643 - }
1644 -
1645 - /**
1646 1367 * @since 4.0
1647 1368 */
1648 1369 public static function bulk_options_overlay() {
1649 1370 $prepop = array();
@@ -1648,9 +1369,9 @@
1648 1369 public static function bulk_options_overlay() {
1649 1370 $prepop = array();
1650 1371 self::get_bulk_prefilled_opts( $prepop, true );
1651 1372
1652 - 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' );
1653 1374 }
1654 1375
1655 1376 public static function get_us_states() {
1656 1377 $states = array(
@@ -2090,9 +1811,9 @@
2090 1811 * Display a field value selector
2091 1812 *
2092 1813 * @since 2.03.05
2093 1814 *
2094 - * @param int $selector_field_id
1815 + * @param int $selector_field_id
2095 1816 * @param array $selector_args
2096 1817 */
2097 1818 public static function display_field_value_selector( $selector_field_id, $selector_args ) {
2098 1819 $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
@@ -2108,9 +1829,9 @@
2108 1829 *
2109 1830 * @return array
2110 1831 */
2111 1832 public static function convert_field_object_to_flat_array( $field ) {
2112 - $field_options = is_array( $field->field_options ) ? $field->field_options : array();
1833 + $field_options = $field->field_options;
2113 1834 $field_array = get_object_vars( $field );
2114 1835 unset( $field_array['field_options'] );
2115 1836
2116 1837 return $field_array + $field_options;
@@ -2117,11 +1838,9 @@
2117 1838 }
2118 1839
2119 1840 /**
2120 1841 * @since 4.04
2121 - *
2122 1842 * @param array $args
2123 - * @return void
2124 1843 */
2125 1844 public static function show_add_field_buttons( $args ) {
2126 1845 $field_key = $args['field_key'];
2127 1846 $field_type = $args['field_type'];
@@ -2128,14 +1847,8 @@
2128 1847 $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
2129 1848 $field_name = FrmFormsHelper::get_field_link_name( $field_type );
2130 1849 $field_label .= ' <span>' . $field_name . '</span>';
2131 1850
2132 - if ( ! empty( $field_type['is_new'] ) ) {
2133 - ob_start();
2134 - FrmAppHelper::show_pill_text();
2135 - $field_label .= ob_get_clean();
2136 - }
2137 -
2138 1851 // If the individual field isn't allowed, disable it.
2139 1852 $run_filter = true;
2140 1853 $single_no_allow = ' ';
2141 1854 $install_data = '';
@@ -2140,9 +1853,9 @@
2140 1853 $single_no_allow = ' ';
2141 1854 $install_data = '';
2142 1855 $requires = '';
2143 1856 $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
2144 - $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' );
2145 1858 $show_upgrade = $has_show_upgrade_class || false !== strpos( $args['no_allow_class'], 'frm_show_upgrade' );
2146 1859
2147 1860 if ( $has_show_upgrade_class ) {
2148 1861 $single_no_allow .= 'frm_show_upgrade';
@@ -2180,16 +1893,8 @@
2180 1893 'data-content' => $field_key,
2181 1894 'data-requires' => $requires,
2182 1895 );
2183 1896
2184 - if ( ! empty( $field_type['hide'] ) ) {
2185 - $li_params['class'] .= ' frm_hidden';
2186 - }
2187 -
2188 - if ( ! empty( $field_type['upsell_image'] ) ) {
2189 - $li_params['data-upsell-image'] = $field_type['upsell_image'];
2190 - }
2191 -
2192 1897 if ( $upgrade_message ) {
2193 1898 $li_params['data-message'] = $upgrade_message;
2194 1899 }
2195 1900 ?>
@@ -2197,9 +1902,9 @@
2197 1902 <?php
2198 1903 if ( $run_filter ) {
2199 1904 $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
2200 1905 }
2201 - 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
2202 1907 ?>
2203 1908 </li>
2204 1909 <?php
2205 1910 }
@@ -2211,29 +1916,12 @@
2211 1916 *
2212 1917 * @param array $field Field data.
2213 1918 */
2214 1919 public static function show_radio_display_format( $field ) {
2215 - $options = self::get_display_format_options( $field );
2216 -
2217 - $args = self::get_display_format_args( $field, $options );
2218 -
2219 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php';
2220 - }
2221 -
2222 - /**
2223 - * Creates an array that contains variables used for display format options setting.
2224 - *
2225 - * @since 6.3.2
2226 - *
2227 - * @param array $field The field.
2228 - *
2229 - * @return array
2230 - */
2231 - public static function get_display_format_options( $field ) {
2232 1920 $options = array(
2233 1921 '0' => array(
2234 - 'text' => __( 'Simple', 'formidable' ),
2235 - 'svg' => 'frm_simple_radio',
1922 + 'text' => __( 'Simple', 'formidable' ),
1923 + 'svg' => 'frm_simple_radio',
2236 1924 ),
2237 1925 '1' => array(
2238 1926 'text' => __( 'Images', 'formidable' ),
2239 1927 'svg' => 'frm_image_as_option',
@@ -2257,13 +1945,14 @@
2257 1945 *
2258 1946 * @since 5.0.04
2259 1947 *
2260 1948 * @param array $options Options.
2261 - * @param array $field
2262 1949 */
2263 - $options = apply_filters( 'frm_' . $field['type'] . '_display_format_options', $options, $field );
1950 + $options = apply_filters( 'frm_radio_display_format_options', $options );
2264 1951
2265 - 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';
2266 1955 }
2267 1956
2268 1957 /**
2269 1958 * Gets display format arguments to pass to the images_dropdown() method.
@@ -2273,9 +1962,9 @@
2273 1962 * @param array $field Field data.
2274 1963 * @param array $options Options array.
2275 1964 * @return array
2276 1965 */
2277 - public static function get_display_format_args( $field, $options ) {
1966 + private static function get_display_format_args( $field, $options ) {
2278 1967 $args = array(
2279 1968 'selected' => '0',
2280 1969 'options' => array(),
2281 1970 'name' => 'field_options[image_options_' . $field['id'] . ']',
@@ -2293,9 +1982,9 @@
2293 1982 *
2294 1983 * @param array $args Arguments.
2295 1984 * @param array $method_args The arguments from the method. Contains `field`, `options`.
2296 1985 */
2297 - 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' ) );
2298 1987 }
2299 1988
2300 1989 /**
2301 1990 * @since 5.0.04
@@ -2354,147 +2043,92 @@
2354 2043 return $custom_attrs;
2355 2044 }
2356 2045
2357 2046 /**
2358 - * Maybe adjust a field value based on type.
2359 - * Some types require unserializing an array.
2360 - * These types are defined by a array_allowed property on their field model class.
2361 - *
2362 - * @since 6.2
2363 - *
2364 - * @param mixed $value
2365 - * @param string $field_type
2366 - * @return void
2047 + * @deprecated 4.0
2367 2048 */
2368 - public static function prepare_field_value( &$value, $field_type ) {
2369 - $field_object = FrmFieldFactory::get_field_type( $field_type );
2370 - $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>';
2371 2056 }
2372 2057
2373 2058 /**
2374 - * @since 6.8
2375 - *
2376 - * @param int|string $form_id
2377 - * @param array $field_ids If this is not empty, the results will be filtered by field id.
2378 - * @return array
2059 + * @deprecated 4.0
2379 2060 */
2380 - public static function get_draft_field_results( $form_id, $field_ids = array() ) {
2381 - if ( FrmAppHelper::pro_is_installed() ) {
2382 - $child_form_ids = FrmDb::get_col( 'frm_forms', array( 'parent_form_id' => $form_id ) );
2383 - $form_ids = array_merge( array( $form_id ), $child_form_ids );
2384 - } else {
2385 - $form_ids = array( $form_id );
2386 - }
2061 + public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
2062 + _deprecated_function( __METHOD__, '4.0' );
2063 + }
2387 2064
2388 - $where = array(
2389 - 'form_id' => $form_ids,
2390 - // Do a soft check for fields that look like drafts only.
2391 - 'field_options LIKE' => 's:5:"draft";i:1;',
2392 - );
2065 + /**
2066 + * @deprecated 4.0
2067 + */
2068 + public static function clear_on_focus_html( $field, $display, $id = '' ) {
2069 + _deprecated_function( __METHOD__, '4.0' );
2070 + }
2393 2071
2394 - if ( $field_ids ) {
2395 - $where['id'] = $field_ids;
2396 - }
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 + }
2397 2078
2398 - $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 + }
2399 2086
2400 - return array_filter(
2401 - $rows,
2402 - function ( $row ) {
2403 - FrmAppHelper::unserialize_or_decode( $row->field_options );
2404 - return is_array( $row->field_options ) && ! empty( $row->field_options['draft'] );
2405 - }
2406 - );
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 );
2407 2093 }
2408 2094
2409 2095 /**
2410 - * This is called when loading the form builder.
2411 - * Any unsaved draft fields get added to a hidden draft_fields input on load.
2412 - *
2413 - * @since 6.8
2414 - *
2415 - * @param int|string $form_id
2416 - * @return array
2096 + * @deprecated 3.0
2097 + * @codeCoverageIgnore
2417 2098 */
2418 - public static function get_all_draft_field_ids( $form_id ) {
2419 - $draft_field_rows = self::get_draft_field_results( $form_id );
2420 - 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 );
2421 2101 }
2422 2102
2423 2103 /**
2424 - * Render AI generate options button.
2104 + * @deprecated 3.0
2105 + * @codeCoverageIgnore
2425 2106 *
2426 - * @since 6.24
2107 + * @param string $html
2108 + * @param array $field
2109 + * @param array $errors
2110 + * @param object|false $form
2111 + * @param array $args
2427 2112 *
2428 - * @param array $args Field arguments.
2429 - * @param bool $should_hide_bulk_edit Whether to hide bulk edit.
2113 + * @return string
2430 2114 */
2431 - public static function render_ai_generate_options_button( $args, $should_hide_bulk_edit = false ) {
2432 - $attributes = array( 'class' => self::get_ai_generate_options_button_class() );
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 + }
2433 2118
2434 - if ( ! empty( $should_hide_bulk_edit ) ) {
2435 - $attributes['class'] .= ' frm-force-hidden';
2436 - }
2437 -
2438 - $data = FrmAppHelper::get_upgrade_data_params(
2439 - 'ai',
2440 - array(
2441 - 'requires' => 'Business',
2442 - 'upgrade' => __( 'Generate options with AI', 'formidable' ),
2443 - 'medium' => 'builder',
2444 - 'content' => 'generate-options-with-ai',
2445 - ),
2446 - true
2447 - );
2448 -
2449 - if ( in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) && 'active' === $data['plugin-status'] ) {
2450 - // Backwards compatibility "@since 6.24".
2451 - if ( ! method_exists( 'FrmAIAppController', 'get_ai_generated_options_summary' ) ) {
2452 - $data = array(
2453 - 'modal-title' => __( 'Generate options with AI', 'formidable' ),
2454 - 'modal-content' => __( 'Update the Formidable AI add-on to the last version to use this feature.', 'formidable' ),
2455 - );
2456 - } else {
2457 - $attributes['class'] .= ' frm-ai-generate-options-modal-trigger';
2458 - $attributes['data-fid'] = $args['likert_id'] ?? $args['field']['id'];
2459 - }
2460 - }
2461 -
2462 - if ( empty( $attributes['data-fid'] ) ) {
2463 - unset( $data['plugin-status'] );
2464 - foreach ( $data as $key => $value ) {
2465 - $attributes[ 'data-' . $key ] = $value;
2466 - }
2467 - }
2468 -
2469 - 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 );
2470 2125 }
2471 2126
2472 2127 /**
2473 - * Get AI generate options button class.
2474 - *
2475 - * @since 6.24
2476 - *
2477 - * @return string Button class.
2128 + * @deprecated 2.02.07
2129 + * @codeCoverageIgnore
2478 2130 */
2479 - private static function get_ai_generate_options_button_class() {
2480 - return implode(
2481 - ' ',
2482 - array(
2483 - 'frm_form_field',
2484 - 'frm6',
2485 - 'frm6_followed',
2486 - 'frm-h-stack',
2487 - 'button',
2488 - 'frm-button-secondary',
2489 - 'frm-button-gradient',
2490 - 'frm-rounded-6',
2491 - 'frm-max-w-fit',
2492 - 'frm-font-normal',
2493 - 'frm-py-2xs',
2494 - 'frm-px-xs',
2495 - 'frm-mt-xs',
2496 - 'frm-mb-12',
2497 - )
2498 - );
2131 + public static function dropdown_categories( $args ) {
2132 + return FrmDeprecated::dropdown_categories( $args );
2499 2133 }
2500 2134 }