PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.1
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmFieldsHelper.php +321 -1058 6.32 → 6.8.1 View file →
@@ -4,23 +4,11 @@
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;
8 + public static function setup_new_vars( $type = '', $form_id = '' ) {
14 9
15 - /**
16 - * @param string $type
17 - * @param int|string $form_id
18 - *
19 - * @return array
20 - */
21 - public static function setup_new_vars( $type = '', $form_id = '' ) {
22 - if ( str_contains( $type, '|' ) ) {
10 + if ( strpos( $type, '|' ) ) {
23 11 list( $type, $setting ) = explode( '|', $type );
24 12 }
25 13
26 14 $values = self::get_default_field( $type );
@@ -46,56 +34,31 @@
46 34 $values['field_options'][ $setting ] = 1;
47 35 }
48 36 }
49 37
50 - // Increase the field order of submit field and fields in the same row.
51 - FrmSubmitHelper::update_last_row_fields_order_when_adding_field( $field_count );
52 -
53 38 return $values;
54 39 }
55 40
56 - /**
57 - * @param array $field
58 - * @param string $plus
59 - *
60 - * @return string
61 - */
62 41 public static function get_html_id( $field, $plus = '' ) {
63 42 return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
64 43 }
65 44
66 - /**
67 - * @param object $field
68 - * @param bool $doing_ajax
69 - *
70 - * @return array
71 - */
72 45 public static function setup_edit_vars( $field, $doing_ajax = false ) {
73 46 $values = self::field_object_to_array( $field );
47 +
74 48 return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
75 49 }
76 50
77 - /**
78 - * @param object $field
79 - *
80 - * @return array
81 - */
82 51 public static function field_object_to_array( $field ) {
83 52 $values = (array) $field;
84 53
85 54 self::fill_field_array( $field, $values );
86 55
87 - $values['custom_html'] = $field->field_options['custom_html'] ?? self::get_default_html( $field->type );
56 + $values['custom_html'] = ( isset( $field->field_options['custom_html'] ) ) ? $field->field_options['custom_html'] : self::get_default_html( $field->type );
88 57
89 58 return $values;
90 59 }
91 60
92 - /**
93 - * @param object $field
94 - * @param array $field_array
95 - *
96 - * @return void
97 - */
98 61 private static function fill_field_array( $field, array &$field_array ) {
99 62 $field_array['options'] = $field->options;
100 63 $field_array['value'] = $field->default_value;
101 64
@@ -104,17 +67,11 @@
104 67 $field_array = array_merge( (array) $field->field_options, $field_array );
105 68 }
106 69
107 70 /**
108 - * Prepare field while creating a new entry.
71 + * Prepare field while creating a new entry
109 72 *
110 73 * @since 3.0
111 - *
112 - * @param array $field_array Field values array, passed by reference.
113 - * @param stdClass $field Field object.
114 - * @param array $args Additional arguments.
115 - *
116 - * @return void
117 74 */
118 75 public static function prepare_new_front_field( &$field_array, $field, $args = array() ) {
119 76 $args['action'] = 'new';
120 77 self::prepare_front_field( $field_array, $field, $args );
@@ -120,18 +77,11 @@
120 77 self::prepare_front_field( $field_array, $field, $args );
121 78 }
122 79
123 80 /**
124 - * Prepare field while editing an entry.
81 + * Prepare field while editing an entry
125 82 *
126 83 * @since 3.0
127 - *
128 - * @param array $field_array Field values array, passed by reference.
129 - * @param array|stdClass $field Field object or array.
130 - * @param int $entry_id Entry ID.
131 - * @param array $args Additional arguments.
132 - *
133 - * @return void
134 84 */
135 85 public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) {
136 86 $args['entry_id'] = $entry_id;
137 87 $args['action'] = 'edit';
@@ -141,14 +91,8 @@
141 91 /**
142 92 * Prepare field while creating a new entry
143 93 *
144 94 * @since 3.0
145 - *
146 - * @param array $field_array
147 - * @param stdClass $field
148 - * @param array $args
149 - *
150 - * @return void
151 95 */
152 96 private static function prepare_front_field( &$field_array, $field, $args ) {
153 97 self::fill_default_field_opts( $field, $field_array );
154 98 self::fill_cleared_strings( $field, $field_array );
@@ -153,30 +97,17 @@
153 97 self::fill_default_field_opts( $field, $field_array );
154 98 self::fill_cleared_strings( $field, $field_array );
155 99
156 100 // Track the original field's type
157 - $field_array['original_type'] = $field->field_options['original_type'] ?? $field->type;
101 + $field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
158 102
159 103 self::prepare_field_options_for_display( $field_array, $field, $args );
160 104
161 - if ( $args['action'] === 'edit' ) {
162 - /**
163 - * @param array $field_array
164 - * @param stdClass $field
165 - * @param int|string $entry_id
166 - * @param array $args
167 - */
105 + if ( $args['action'] == 'edit' ) {
168 106 $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args );
169 -
170 - return;
107 + } else {
108 + $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args );
171 109 }
172 -
173 - /**
174 - * @param array $field_array
175 - * @param stdClass $field
176 - * @param array $args
177 - */
178 - $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args );
179 110 }
180 111
181 112 /**
182 113 * @since 3.0
@@ -186,8 +117,9 @@
186 117 * @return array
187 118 */
188 119 public static function get_default_field_options( $type ) {
189 120 $field_type = FrmFieldFactory::get_field_type( $type );
121 +
190 122 return $field_type->get_default_field_options();
191 123 }
192 124
193 125 /**
@@ -194,15 +126,13 @@
194 126 * @since 3.0
195 127 *
196 128 * @param object $field
197 129 * @param array $values
198 - *
199 - * @return void
200 130 */
201 131 private static function fill_default_field_opts( $field, array &$values ) {
202 - $check_post = self::context_is_safe_to_load_field_options_from_request_data();
203 - $defaults = self::get_default_field_options_from_field( $field, $values );
132 + $check_post = FrmAppHelper::is_admin_page() && $_POST && isset( $_POST['field_options'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
204 133
134 + $defaults = self::get_default_field_options_from_field( $field, $values );
205 135 if ( ! $check_post ) {
206 136 $defaults['required_indicator'] = '';
207 137 $defaults['original_type'] = $field->type;
208 138 }
@@ -207,65 +137,16 @@
207 137 $defaults['original_type'] = $field->type;
208 138 }
209 139
210 140 foreach ( $defaults as $opt => $default ) {
211 - $values[ $opt ] = $field->field_options[ $opt ] ?? $default;
141 + $values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default;
212 142
213 143 if ( $check_post ) {
214 144 self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] );
215 145 }
216 - }
217 - }
218 146
219 - /**
220 - * The fill_default_field_opts method is called when loading a field.
221 - * This is used to preserve the $_POST data after updating settings for a field.
222 - * To prevent this from happening when creating an entry, we need to check the context.
223 - *
224 - * @return bool
225 - */
226 - private static function context_is_safe_to_load_field_options_from_request_data() {
227 - if ( isset( self::$context_is_safe_to_load_field_options_from_request_data ) ) {
228 - return self::$context_is_safe_to_load_field_options_from_request_data;
147 + unset( $opt, $default );
229 148 }
230 -
231 - $function = function () {
232 - if ( ! FrmAppHelper::is_admin_page() ) {
233 - return false;
234 - }
235 -
236 - if ( ! $_POST || ! isset( $_POST['field_options'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
237 - return false;
238 - }
239 -
240 - if ( ! current_user_can( 'frm_edit_forms' ) ) {
241 - return false;
242 - }
243 -
244 - $action = FrmAppHelper::get_post_param( 'action', '', 'sanitize_title' );
245 -
246 - if ( 'frm_forms_preview' === $action ) {
247 - // Never trigger when previewing.
248 - return false;
249 - }
250 -
251 - // Confirm an allowed action is being used, and that the correct nonce is being used.
252 - if ( 'update' === $action ) {
253 - $nonce = FrmAppHelper::get_post_param( 'frm_save_form', '', 'sanitize_text_field' );
254 - return wp_verify_nonce( $nonce, 'frm_save_form_nonce' );
255 - }
256 -
257 - $action = FrmAppHelper::get_post_param( 'frm_action', '', 'sanitize_title' );
258 -
259 - if ( 'update_settings' === $action ) {
260 - $nonce = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
261 - return wp_verify_nonce( $nonce, 'process_form_nonce' );
262 - }
263 - };
264 -
265 - self::$context_is_safe_to_load_field_options_from_request_data = $function();
266 -
267 - return self::$context_is_safe_to_load_field_options_from_request_data;
268 149 }
269 150
270 151 /**
271 152 * Fill the required message, invalid message,
@@ -274,27 +155,25 @@
274 155 * @since 3.0
275 156 *
276 157 * @param object $field
277 158 * @param array $field_array
278 - *
279 - * @return void
280 159 */
281 160 private static function fill_cleared_strings( $field, array &$field_array ) {
282 - // phpcs:ignore Universal.Operators.StrictComparisons
161 + $frm_settings = FrmAppHelper::get_settings();
162 +
283 163 if ( '' == $field_array['blank'] && '1' === $field_array['required'] ) {
284 - $field_array['blank'] = self::default_blank_msg();
164 + $field_array['blank'] = $frm_settings->blank_msg;
285 165 }
286 166
287 167 if ( '' === $field_array['invalid'] ) {
288 168 if ( 'captcha' === $field->type ) {
289 - $frm_settings = FrmAppHelper::get_settings();
290 169 $field_array['invalid'] = $frm_settings->re_msg;
291 170 } else {
292 - $field_array['invalid'] = self::default_invalid_msg();
171 + /* translators: %s: Field name */
172 + $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
293 173 }
294 174 }
295 175
296 - // phpcs:ignore Universal.Operators.StrictComparisons
297 176 if ( '' == $field_array['custom_html'] ) {
298 177 $field_array['custom_html'] = self::get_default_html( $field->type );
299 178 }
300 179 }
@@ -299,48 +178,12 @@
299 178 }
300 179 }
301 180
302 181 /**
303 - * @since 6.8.3
304 - *
305 - * @return string
306 - */
307 - public static function default_invalid_msg() {
308 - /* translators: %s: [field_name] shortcode (Which gets replaced by a Field Name) */
309 - return sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' );
310 - }
311 -
312 - /**
313 - * @since 6.8.3
314 - *
315 - * @return string
316 - */
317 - public static function default_unique_msg() {
318 - $frm_settings = FrmAppHelper::get_settings();
319 - $unique_message = $frm_settings->unique_msg;
320 - return str_replace( 'This value', '[field_name]', $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 - return str_replace( 'This field', '[field_name]', $blank_message );
332 - }
333 -
334 - /**
335 - * When loading settings for a field, check the $_POST data and possibly use that instead of the DB value.
336 - *
337 182 * @since 3.0
338 183 *
339 184 * @param string $setting
340 185 * @param mixed $value
341 - *
342 - * @return void
343 186 */
344 187 private static function get_posted_field_setting( $setting, &$value ) {
345 188 if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
346 189 return;
@@ -345,20 +188,16 @@
345 188 if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
346 189 return;
347 190 }
348 191
349 - if ( str_contains( $setting, 'html' ) ) {
350 - $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
351 -
352 - // Conditionally strip script tags if the user sending $_POST data is not allowed to use unfiltered HTML.
353 - if ( ! FrmAppHelper::allow_unfiltered_html() ) {
354 - $value = FrmAppHelper::kses( $value, 'all' );
355 - }
356 - } elseif ( str_starts_with( $setting, 'format_' ) ) {
192 + if ( strpos( $setting, 'html' ) !== false ) {
193 + // Strip slashes from HTML but not regex or script tags.
194 + $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
195 + } elseif ( strpos( $setting, 'format_' ) === 0 ) {
357 196 // TODO: Remove stripslashes on output, and use on input only.
358 - $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
197 + $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
359 198 } else {
360 - $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
199 + $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
361 200 FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
362 201 }
363 202 }
364 203
@@ -372,11 +211,13 @@
372 211 */
373 212 public static function get_default_field_options_from_field( $field, $values = array() ) {
374 213 $field_type = self::get_original_field( $field );
375 214 $opts = $field_type->get_default_field_options();
376 - $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
377 215
378 - return apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
216 + $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
217 + $opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
218 +
219 + return $opts;
379 220 }
380 221
381 222 /**
382 223 * @since 3.0
@@ -382,14 +223,13 @@
382 223 * @since 3.0
383 224 *
384 225 * @param object $field
385 226 *
386 - * @return FrmFieldType
227 + * @return array
387 228 */
388 229 private static function get_original_field( $field ) {
389 230 $original_type = FrmField::get_option( $field, 'original_type' );
390 -
391 - if ( $original_type && $field->type !== $original_type ) {
231 + if ( ! empty( $original_type ) && $field->type != $original_type ) {
392 232 $field->type = $original_type;
393 233 }
394 234
395 235 return FrmFieldFactory::get_field_object( $field );
@@ -400,10 +240,8 @@
400 240 *
401 241 * @param array $field_array
402 242 * @param object $field
403 243 * @param array $atts
404 - *
405 - * @return void
406 244 */
407 245 private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
408 246 $field_obj = FrmFieldFactory::get_field_object( $field );
409 247 $field_array = $field_obj->prepare_front_field( $field_array, $atts );
@@ -417,19 +255,12 @@
417 255 * @return array
418 256 */
419 257 public static function get_default_field( $type ) {
420 258 $field_type = FrmFieldFactory::get_field_type( $type );
259 +
421 260 return $field_type->get_new_field_defaults();
422 261 }
423 262
424 - /**
425 - * @param array $values
426 - * @param object $field
427 - * @param int|string $form_id
428 - * @param string $new_key
429 - *
430 - * @return void
431 - */
432 263 public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
433 264 global $wpdb;
434 265
435 266 $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
@@ -444,26 +275,29 @@
444 275
445 276 /**
446 277 * @since 2.0
447 278 *
448 - * @param array|object $field
449 - * @param string $error
279 + * @param object|array|int $field
280 + * @param string $error
450 281 *
451 282 * @return string
452 283 */
453 284 public static function get_error_msg( $field, $error ) {
454 - $frm_settings = FrmAppHelper::get_settings();
455 - $conf_msg = __( 'The entered values do not match', 'formidable' );
456 - $defaults = array(
285 + $frm_settings = FrmAppHelper::get_settings();
286 + $default_settings = $frm_settings->default_options();
287 + $field_name = is_array( $field ) ? $field['name'] : $field->name;
288 +
289 + $conf_msg = __( 'The entered values do not match', 'formidable' );
290 + $defaults = array(
457 291 'unique_msg' => array(
458 - 'full' => self::default_unique_msg(),
292 + 'full' => $default_settings['unique_msg'],
459 293 /* translators: %s: Field name */
460 - 'part' => sprintf( __( '%s must be unique', 'formidable' ), '[field_name]' ),
294 + 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ),
461 295 ),
462 296 'invalid' => array(
463 297 'full' => __( 'This field is invalid', 'formidable' ),
464 298 /* translators: %s: Field name */
465 - 'part' => sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' ),
299 + 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ),
466 300 ),
467 301 'blank' => array(
468 302 'full' => $frm_settings->blank_msg,
469 303 'part' => $frm_settings->blank_msg,
@@ -473,107 +307,26 @@
473 307 'part' => $conf_msg,
474 308 ),
475 309 );
476 310
477 - /**
478 - * @since 6.28
479 - *
480 - * @param array $defaults
481 - * @param array|object $field
482 - */
483 - $defaults = apply_filters( 'frm_default_field_validation_messages', $defaults, $field );
484 -
485 311 $msg = FrmField::get_option( $field, $error );
486 - $msg = $msg ? $msg : $defaults[ $error ]['part'];
312 + $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
487 313 $msg = do_shortcode( $msg );
488 314
489 - return self::maybe_replace_substrings_with_field_name( $msg, $error, $field );
315 + return $msg;
490 316 }
491 317
492 - /**
493 - * @since 6.8.3
494 - *
495 - * @param string $msg
496 - * @param string $error
497 - * @param array|object $field
498 - *
499 - * @return string
500 - */
501 - private static function maybe_replace_substrings_with_field_name( $msg, $error, $field ) {
502 - $field_name = is_array( $field ) ? $field['name'] : $field->name;
503 - $field_name = FrmAppHelper::maybe_kses( $field_name );
504 - $substrings = self::get_substrings_to_replace_with_field_name( $field_name, compact( 'msg', 'error', 'field' ) );
505 -
506 - // Use the "This value"/"This field" placeholder strings if field name is empty.
507 - if ( ! $field_name ) {
508 - $field_name = 'unique_msg' === $error ? __( 'This value', 'formidable' ) : __( 'This field', 'formidable' );
509 - }
510 -
511 - return str_replace( $substrings, $field_name, $msg );
512 - }
513 -
514 - /**
515 - * @since 6.8.3
516 - *
517 - * @param string $field_name
518 - * @param array $filter_args {
519 - * Filter arguments.
520 - *
521 - * @type string $msg The current error message before the substrings are replaced.
522 - * @type string $error A key including 'unique_msg', 'invalid', 'blank', or 'conf_msg'.
523 - * @type array|object $field The field with the error.
524 - * }
525 - *
526 - * @return array
527 - */
528 - private static function get_substrings_to_replace_with_field_name( $field_name, $filter_args ) {
529 - $substrings = array( '[field_name]' );
530 -
531 - if ( $field_name ) {
532 - array_push( $substrings, 'This value', 'This field' );
533 - }
534 -
535 - /**
536 - * @since 6.8.3
537 - *
538 - * @param array<string> $substrings
539 - * @param array $filter_args
540 - */
541 - $filtered_substrings = apply_filters( 'frm_error_substrings_to_replace_with_field_name', $substrings, $filter_args );
542 -
543 - if ( is_array( $filtered_substrings ) ) {
544 - $substrings = $filtered_substrings;
545 - } else {
546 - _doing_it_wrong( __METHOD__, 'Only arrays should be returned when using the frm_error_substrings_to_replace_with_field_name filter.', '6.8.3' );
547 - }
548 -
549 - return $substrings;
550 - }
551 -
552 - /**
553 - * @param int|string $form_id
554 - * @param array $error
555 - *
556 - * @return array
557 - */
558 318 public static function get_form_fields( $form_id, $error = array() ) {
559 319 $fields = FrmField::get_all_for_form( $form_id );
560 320
561 - FrmFieldName::track_first_name_field( $fields );
562 -
563 321 return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
564 322 }
565 323
566 - /**
567 - * @param string $type
568 - *
569 - * @return string
570 - */
571 324 public static function get_default_html( $type = 'text' ) {
572 325 $field = FrmFieldFactory::get_field_type( $type );
573 326 $default_html = $field->default_html();
574 327
575 - // These hooks are here for reverse compatibility since 3.0
328 + // these hooks are here for reverse compatibility since 3.0
576 329 if ( ! apply_filters( 'frm_normal_field_type_html', true, $type ) ) {
577 330 $default_html = apply_filters( 'frm_other_custom_html', '', $type );
578 331 }
579 332
@@ -584,17 +337,11 @@
584 337 * @param array $fields
585 338 * @param array $errors
586 339 * @param object $form
587 340 * @param object $form_action
588 - *
589 - * @return void
590 341 */
591 342 public static function show_fields( $fields, $errors, $form, $form_action ) {
592 343 foreach ( $fields as $field ) {
593 - if ( ! is_array( $field ) ) {
594 - continue;
595 - }
596 -
597 344 $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field );
598 345 $field_obj->show_field( compact( 'errors', 'form', 'form_action' ) );
599 346 }
600 347 }
@@ -602,24 +349,18 @@
602 349 /**
603 350 * @since 3.0
604 351 *
605 352 * @param array $atts
606 - * @param array|string $value
607 - *
608 - * @return void
353 + * @param string|array $value
609 354 */
610 355 public static function run_wpautop( $atts, &$value ) {
611 - $autop = $atts['wpautop'] ?? true;
612 -
613 - if ( ! apply_filters( 'frm_use_wpautop', $autop ) ) {
614 - return;
356 + $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true;
357 + if ( apply_filters( 'frm_use_wpautop', $autop ) ) {
358 + if ( is_array( $value ) ) {
359 + $value = implode( "\n", $value );
360 + }
361 + $value = wpautop( $value );
615 362 }
616 -
617 - if ( is_array( $value ) ) {
618 - $value = implode( "\n", $value );
619 - }
620 -
621 - $value = wpautop( $value );
622 363 }
623 364
624 365 /**
625 366 * Get the class to use for the label position
@@ -624,19 +365,13 @@
624 365 /**
625 366 * Get the class to use for the label position
626 367 *
627 368 * @since 2.05
628 - *
629 - * @param string $position
630 - * @param array $field
631 - * @param bool|object|string $form
632 - *
633 - * @return string
634 369 */
635 - public static function label_position( $position, $field, $form ) {
636 - if ( $position ) {
637 - if ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
638 - return 'top';
370 + public static function &label_position( $position, $field, $form ) {
371 + if ( $position && $position != '' ) {
372 + if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
373 + $position = 'top';
639 374 }
640 375
641 376 return $position;
642 377 }
@@ -641,19 +376,20 @@
641 376 return $position;
642 377 }
643 378
644 379 $position = FrmStylesController::get_style_val( 'position', $form );
645 -
646 - if ( $position === 'none' ) {
380 + if ( $position == 'none' ) {
647 381 $position = 'top';
648 - } elseif ( $position === 'no_label' ) {
382 + } elseif ( $position == 'no_label' ) {
649 383 $position = 'none';
650 - } elseif ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
384 + } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
651 385 $position = 'top';
652 386 }
653 387
654 388 $position = apply_filters( 'frm_html_label_position', $position, $field, $form );
655 - return $position ? $position : 'top';
389 + $position = ( ! empty( $position ) ) ? $position : 'top';
390 +
391 + return $position;
656 392 }
657 393
658 394 /**
659 395 * Check if this field type allows placeholders
@@ -658,11 +394,9 @@
658 394 /**
659 395 * Check if this field type allows placeholders
660 396 *
661 397 * @since 2.05
662 - *
663 398 * @param string $type
664 - *
665 399 * @return bool
666 400 */
667 401 public static function is_placeholder_field_type( $type ) {
668 402 return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true );
@@ -667,19 +401,11 @@
667 401 public static function is_placeholder_field_type( $type ) {
668 402 return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true );
669 403 }
670 404
671 - /**
672 - * @param array $field
673 - * @param int|string $opt_key
674 - * @param string $type
675 - *
676 - * @return string
677 - */
678 405 public static function get_checkbox_id( $field, $opt_key, $type = 'checkbox' ) {
679 406 $id = $field['id'];
680 -
681 - if ( ! empty( $field['in_section'] ) && ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
407 + if ( isset( $field['in_section'] ) && $field['in_section'] && ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
682 408 $id .= '-' . $field['in_section'];
683 409 }
684 410
685 411 return 'frm_' . $type . '_' . $id . '-' . $opt_key;
@@ -684,13 +410,8 @@
684 410
685 411 return 'frm_' . $type . '_' . $id . '-' . $opt_key;
686 412 }
687 413
688 - /**
689 - * @param array $field
690 - *
691 - * @return void
692 - */
693 414 public static function show_single_option( $field ) {
694 415 self::hidden_field_option( $field );
695 416
696 417 if ( ! is_array( $field['options'] ) ) {
@@ -696,28 +417,28 @@
696 417 if ( ! is_array( $field['options'] ) ) {
697 418 return;
698 419 }
699 420
700 - $base_name = 'default_value_' . $field['id'];
701 - $html_id = $field['html_id'] ?? self::get_html_id( $field );
702 - $default_type = self::get_default_value_type( $field );
703 - $options_count = count( $field['options'] );
421 + $base_name = 'default_value_' . $field['id'];
422 + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
704 423
424 + $default_type = self::get_default_value_type( $field );
425 +
705 426 foreach ( $field['options'] as $opt_key => $opt ) {
706 - $field_val = self::get_value_from_array( $opt, $opt_key, $field );
707 - $opt = self::get_label_from_array( $opt, $opt_key, $field );
427 + $field_val = self::get_value_from_array( $opt, $opt_key, $field );
428 + $opt = self::get_label_from_array( $opt, $opt_key, $field );
429 +
708 430 $field_name = $base_name . ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
709 431
710 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict, Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong
711 - $checked = isset( $field['default_value'] ) && ( is_array( $field['default_value'] ) ? in_array( $field_val, $field['default_value'] ) : $field['default_value'] == $field_val );
432 + $checked = ( isset( $field['default_value'] ) && ( ( ! is_array( $field['default_value'] ) && $field['default_value'] == $field_val ) || ( is_array( $field['default_value'] ) && in_array( $field_val, $field['default_value'] ) ) ) );
712 433
713 434 // If this is an "Other" option, get the HTML for it.
714 435 if ( self::is_other_opt( $opt_key ) ) {
715 436 if ( FrmAppHelper::pro_is_installed() ) {
716 - require FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php';
437 + require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' );
717 438 }
718 439 } else {
719 - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
440 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
720 441 }
721 442
722 443 unset( $checked );
723 444 }
@@ -726,31 +447,28 @@
726 447 /**
727 448 * Include hidden row for javascript to duplicate.
728 449 *
729 450 * @since 4.0
730 - *
731 451 * @param array $field
732 - *
733 - * @return void
734 452 */
735 453 private static function hidden_field_option( $field ) {
736 454 // Don't duplicate during an ajax add option.
737 455 $ajax_action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' );
738 -
739 456 if ( $ajax_action === 'frm_add_field_option' ) {
740 457 return;
741 458 }
742 459
743 - $opt_key = '000';
744 - $field_val = __( 'New Option', 'formidable' );
745 - $opt = __( 'New Option', 'formidable' );
746 - $checked = false;
747 - $field_name = 'default_value_' . $field['id'];
748 - $html_id = $field['html_id'] ?? self::get_html_id( $field );
460 + $opt_key = '000';
461 + $field_val = __( 'New Option', 'formidable' );
462 + $opt = __( 'New Option', 'formidable' );
463 + $checked = false;
464 + $field_name = 'default_value_' . $field['id'];
465 + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
466 +
749 467 $default_type = self::get_default_value_type( $field );
750 - $field_name .= $default_type === 'checkbox' ? '[' . $opt_key . ']' : '';
468 + $field_name .= ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
751 469
752 - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
470 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
753 471 }
754 472
755 473 /**
756 474 * @since 4.0
@@ -755,39 +473,27 @@
755 473 /**
756 474 * @since 4.0
757 475 *
758 476 * @param array $field
759 - *
760 477 * @return string radio or checkbox
761 478 */
762 479 private static function get_default_value_type( $field ) {
480 + $default_type = $field['type'];
763 481 if ( $field['type'] === 'select' ) {
764 - return FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio';
482 + $default_type = FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio';
765 483 }
766 - return $field['type'];
484 + return $default_type;
767 485 }
768 486
769 - /**
770 - * @param array|string $opt
771 - * @param int|string $opt_key
772 - * @param array $field
773 - *
774 - * @return mixed
775 - */
776 487 public static function get_value_from_array( $opt, $opt_key, $field ) {
777 488 $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
489 +
778 490 return FrmFieldsController::check_value( $opt, $opt_key, $field );
779 491 }
780 492
781 - /**
782 - * @param array|string $opt
783 - * @param int|string $opt_key
784 - * @param array $field
785 - *
786 - * @return string
787 - */
788 493 public static function get_label_from_array( $opt, $opt_key, $field ) {
789 494 $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
495 +
790 496 return FrmFieldsController::check_label( $opt );
791 497 }
792 498
793 499 /**
@@ -796,62 +502,50 @@
796 502 * @since 4.0
797 503 * @since 6.4.1 Added `inside_class` in the arguments.
798 504 *
799 505 * @param array $args The arguments.
800 - *
801 - * @return void
802 506 */
803 507 public static function inline_modal( $args ) {
804 508 $defaults = array(
805 - 'id' => '',
806 - 'class' => '',
807 - 'show' => 0,
808 - 'callback' => array(),
809 - 'args' => array(),
810 - 'title' => '',
509 + 'id' => '',
510 + 'class' => '',
511 + 'show' => 0,
512 + 'callback' => array(),
513 + 'args' => array(),
514 + 'title' => '',
811 515 'inside_class' => 'inside',
812 - 'dismiss-icon' => true,
813 516 );
814 - $args = array_merge( $defaults, $args );
517 + $args = array_merge( $defaults, $args );
815 518
816 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php';
519 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php' );
817 520 }
818 521
819 522 /**
820 523 * @since 4.0
821 - *
822 - * @return void
823 524 */
824 525 public static function smart_values() {
825 526 $continue = apply_filters( 'frm_smart_values_box', true );
826 -
827 - if ( $continue !== true ) {
828 - return;
527 + if ( $continue === true ) {
528 + $upgrade_link = array(
529 + 'medium' => 'builder',
530 + 'content' => 'smart-tags',
531 + );
532 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php' );
829 533 }
830 -
831 - $upgrade_link = array(
832 - 'medium' => 'builder',
833 - 'content' => 'smart-tags',
834 - );
835 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php';
836 534 }
837 535
838 536 /**
839 537 * @since 4.0
840 - *
841 - * @return void
842 538 */
843 539 public static function input_mask() {
844 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php';
540 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php' );
845 541 }
846 542
847 543 /**
848 544 * @since 4.0
849 - *
850 - * @return void
851 545 */
852 546 public static function layout_classes() {
853 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php';
547 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php' );
854 548 }
855 549
856 550 /**
857 551 * @param int $tax_id
@@ -859,33 +553,28 @@
859 553 * @return string
860 554 */
861 555 public static function get_term_link( $tax_id ) {
862 556 $tax = get_taxonomy( $tax_id );
863 -
864 557 if ( ! $tax ) {
865 558 return '';
866 559 }
867 560
868 - return sprintf(
561 + $link = sprintf(
869 562 /* translators: %1$s: Start HTML link, %2$s: Content type label, %3$s: Content type, %4$s: End HTML link */
870 563 esc_html__( 'Options are dynamically created from your %1$s%2$s: %3$s%4$s', 'formidable' ),
871 564 '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">',
872 565 esc_html__( 'taxonomy', 'formidable' ),
873 - ! empty( $tax->labels->name ) ? $tax->labels->name : esc_html__( 'Categories', 'formidable' ),
566 + empty( $tax->labels->name ) ? esc_html__( 'Categories', 'formidable' ) : $tax->labels->name,
874 567 '</a>'
875 568 );
569 + unset( $tax );
570 +
571 + return $link;
876 572 }
877 573
878 - /**
879 - * @param array|string $observed_value
880 - * @param string $cond
881 - * @param array|string $hide_opt
882 - *
883 - * @return bool
884 - */
885 574 public static function value_meets_condition( $observed_value, $cond, $hide_opt ) {
886 - $hide_opt = self::get_value_for_comparison( $hide_opt );
887 - $observed_value = self::get_value_for_comparison( $observed_value );
575 + $hide_opt = self::get_value_for_comparision( $hide_opt );
576 + $observed_value = self::get_value_for_comparision( $observed_value );
888 577
889 578 if ( is_array( $observed_value ) ) {
890 579 return self::array_value_condition( $observed_value, $cond, $hide_opt );
891 580 }
@@ -890,13 +579,12 @@
890 579 return self::array_value_condition( $observed_value, $cond, $hide_opt );
891 580 }
892 581
893 582 $m = false;
894 -
895 583 if ( $cond === '==' ) {
896 - $m = $observed_value == $hide_opt; // phpcs:ignore Universal.Operators.StrictComparisons
584 + $m = $observed_value == $hide_opt;
897 585 } elseif ( $cond === '!=' ) {
898 - $m = $observed_value != $hide_opt; // phpcs:ignore Universal.Operators.StrictComparisons
586 + $m = $observed_value != $hide_opt;
899 587 } elseif ( $cond === '>' ) {
900 588 $m = $observed_value > $hide_opt;
901 589 } elseif ( $cond === '>=' ) {
902 590 $m = $observed_value >= $hide_opt;
@@ -905,16 +593,20 @@
905 593 } elseif ( $cond === '<=' ) {
906 594 $m = $observed_value <= $hide_opt;
907 595 } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) {
908 596 $m = stripos( $observed_value, $hide_opt );
909 - $m = $cond === 'not LIKE' ? $m === false : $m !== false;
597 + if ( $cond === 'not LIKE' ) {
598 + $m = ( $m === false ) ? true : false;
599 + } else {
600 + $m = ( $m === false ) ? false : true;
601 + }
910 602 } elseif ( $cond === '%LIKE' ) {
911 - // Ends with
603 + // ends with
912 604 $length = strlen( $hide_opt );
913 605 $substr = substr( $observed_value, strlen( $observed_value ) - $length );
914 606 $m = 0 === strcasecmp( $substr, $hide_opt );
915 607 } elseif ( 'LIKE%' === $cond ) {
916 - // Starts with
608 + // starts with
917 609 $length = strlen( $hide_opt );
918 610 $substr = substr( $observed_value, 0, $length );
919 611 $m = 0 === strcasecmp( $substr, $hide_opt );
920 612 }//end if
@@ -925,14 +617,10 @@
925 617 /**
926 618 * Trim and sanitize the values
927 619 *
928 620 * @since 2.05
929 - *
930 - * @param array|string $value
931 - *
932 - * @return array|string
933 621 */
934 - private static function get_value_for_comparison( $value ) {
622 + private static function get_value_for_comparision( $value ) {
935 623 // Remove white space from hide_opt
936 624 if ( ! is_array( $value ) ) {
937 625 $value = trim( $value );
938 626 }
@@ -941,37 +629,28 @@
941 629
942 630 return $value;
943 631 }
944 632
945 - /**
946 - * @param array $observed_value
947 - * @param string $cond
948 - * @param array|string $hide_opt
949 - *
950 - * @return bool
951 - */
952 633 public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
953 634 $m = false;
954 -
955 635 if ( $cond === '==' ) {
956 636 if ( is_array( $hide_opt ) ) {
957 637 $m = array_intersect( $hide_opt, $observed_value );
958 - $m = $m !== array();
638 + $m = empty( $m ) ? false : true;
959 639 } else {
960 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
961 640 $m = in_array( $hide_opt, $observed_value );
962 641 }
963 642 } elseif ( $cond === '!=' ) {
964 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
965 643 $m = ! in_array( $hide_opt, $observed_value );
966 644 } elseif ( $cond === '>' ) {
967 - $m = min( $observed_value ) > $hide_opt;
645 + $min = min( $observed_value );
646 + $m = $min > $hide_opt;
968 647 } elseif ( $cond === '<' ) {
969 - $m = max( $observed_value ) < $hide_opt;
648 + $max = max( $observed_value );
649 + $m = $max < $hide_opt;
970 650 } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) {
971 651 foreach ( $observed_value as $ob ) {
972 652 $m = strpos( $ob, $hide_opt );
973 -
974 653 if ( $m !== false ) {
975 654 $m = true;
976 655 break;
977 656 }
@@ -977,12 +656,12 @@
977 656 }
978 657 }
979 658
980 659 if ( $cond === 'not LIKE' ) {
981 - $m = $m === false;
660 + $m = ( $m === false ) ? true : false;
982 661 }
983 662 } elseif ( $cond === '%LIKE' ) {
984 - // Ends with
663 + // ends with
985 664 foreach ( $observed_value as $ob ) {
986 665 if ( $hide_opt === substr( $ob, strlen( $ob ) - strlen( $hide_opt ) ) ) {
987 666 $m = true;
988 667 break;
@@ -988,11 +667,11 @@
988 667 break;
989 668 }
990 669 }
991 670 } elseif ( $cond === 'LIKE%' ) {
992 - // Starts with
671 + // starts with
993 672 foreach ( $observed_value as $ob ) {
994 - if ( str_starts_with( $ob, $hide_opt ) ) {
673 + if ( $hide_opt === substr( $ob, 0, strlen( $hide_opt ) ) ) {
995 674 $m = true;
996 675 break;
997 676 }
998 677 }
@@ -1004,32 +683,22 @@
1004 683 /**
1005 684 * Replace a few basic shortcodes and field ids
1006 685 *
1007 686 * @since 2.0
1008 - *
1009 - * @param string $value
1010 - * @param object $form
1011 - * @param object $entry
1012 - *
1013 687 * @return string
1014 688 */
1015 689 public static function basic_replace_shortcodes( $value, $form, $entry ) {
1016 - if ( str_contains( $value, '[sitename]' ) ) {
690 + if ( strpos( $value, '[sitename]' ) !== false ) {
1017 691 $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
1018 692 $value = str_replace( '[sitename]', $new_value, $value );
1019 693 }
1020 694
1021 695 $value = apply_filters( 'frm_content', $value, $form, $entry );
696 + $value = do_shortcode( $value );
1022 697
1023 - return do_shortcode( $value );
698 + return $value;
1024 699 }
1025 700
1026 - /**
1027 - * @param string $content
1028 - * @param int|string $form_id
1029 - *
1030 - * @return array
1031 - */
1032 701 public static function get_shortcodes( $content, $form_id ) {
1033 702 if ( FrmAppHelper::pro_is_installed() ) {
1034 703 return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
1035 704 }
@@ -1047,13 +716,8 @@
1047 716
1048 717 return $matches;
1049 718 }
1050 719
1051 - /**
1052 - * @param array $fields
1053 - *
1054 - * @return string
1055 - */
1056 720 public static function allowed_shortcodes( $fields = array() ) {
1057 721 $tagregexp = array(
1058 722 'editlink',
1059 723 'id',
@@ -1061,16 +725,13 @@
1061 725 'ip',
1062 726 'siteurl',
1063 727 'sitename',
1064 728 'admin_email',
1065 - 'default-email',
1066 - 'default-from-email',
1067 729 'post[-|_]id',
1068 730 'created[-|_]at',
1069 731 'updated[-|_]at',
1070 732 'updated[-|_]by',
1071 733 'parent[-|_]id',
1072 - 'form_name',
1073 734 );
1074 735
1075 736 foreach ( $fields as $field ) {
1076 737 $tagregexp[] = $field->id;
@@ -1076,21 +737,16 @@
1076 737 $tagregexp[] = $field->id;
1077 738 $tagregexp[] = $field->field_key;
1078 739 }
1079 740
1080 - return implode( '|', $tagregexp );
741 + $tagregexp = implode( '|', $tagregexp );
742 +
743 + return $tagregexp;
1081 744 }
1082 745
1083 - /**
1084 - * @param string $content
1085 - * @param false|object $entry
1086 - * @param array $shortcodes
1087 - *
1088 - * @return string
1089 - */
1090 746 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1091 747 foreach ( $shortcodes[0] as $short_key => $tag ) {
1092 - if ( ! $tag ) {
748 + if ( empty( $tag ) ) {
1093 749 continue;
1094 750 }
1095 751
1096 752 $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
@@ -1114,25 +770,21 @@
1114 770
1115 771 /**
1116 772 * @param string $replace_with
1117 773 * @param array $atts
1118 - *
1119 774 * @return string
1120 775 */
1121 776 private static function trigger_shortcode_atts( $replace_with, $atts ) {
1122 777 $supported_atts = array( 'remove_accents', 'sanitize', 'sanitize_url' );
1123 778 $included_atts = array_intersect( $supported_atts, array_keys( $atts ) );
1124 -
1125 779 foreach ( $included_atts as $included_att ) {
1126 780 if ( '0' === $atts[ $included_att ] ) {
1127 781 // Skip any option that uses 0 so sanitize_url=0 does not encode.
1128 782 continue;
1129 783 }
1130 -
1131 784 $function = 'atts_' . $included_att;
1132 - $replace_with = self::$function( $replace_with );
785 + $replace_with = self::$function( $replace_with, $atts );
1133 786 }
1134 -
1135 787 return $replace_with;
1136 788 }
1137 789
1138 790 /**
@@ -1149,9 +801,8 @@
1149 801 }
1150 802
1151 803 /**
1152 804 * @param string $replace_with
1153 - *
1154 805 * @return string
1155 806 */
1156 807 private static function atts_sanitize( $replace_with ) {
1157 808 return sanitize_title_with_dashes( $replace_with );
@@ -1158,9 +809,8 @@
1158 809 }
1159 810
1160 811 /**
1161 812 * @param string $replace_with
1162 - *
1163 813 * @return string
1164 814 */
1165 815 private static function atts_sanitize_url( $replace_with ) {
1166 816 return urlencode( $replace_with );
@@ -1170,21 +820,14 @@
1170 820 * Prevent shortcodes in fields from being processed
1171 821 *
1172 822 * @since 3.01.02
1173 823 *
1174 - * @param array $atts Includes entry object.
1175 - * @param string|null $value
1176 - *
1177 - * @return void
824 + * @param array $atts Includes entry object.
825 + * @param string $value
1178 826 */
1179 827 public static function sanitize_embedded_shortcodes( $atts, &$value ) {
1180 - if ( is_null( $value ) ) {
1181 - return;
1182 - }
1183 -
1184 828 $atts['value'] = $value;
1185 829 $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
1186 -
1187 830 if ( $should_sanitize ) {
1188 831 $value = str_replace( '[', '&#91;', $value );
1189 832 }
1190 833 }
@@ -1204,13 +847,13 @@
1204 847 'key' => $atts['entry']->item_key,
1205 848 'ip' => $atts['entry']->ip,
1206 849 );
1207 850
1208 - $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get', 'default-email', 'default-from-email' );
851 + $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
1209 852
1210 853 if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
1211 854 $replace_with = $shortcode_values[ $atts['tag'] ];
1212 - } elseif ( in_array( $atts['tag'], $dynamic_default, true ) ) {
855 + } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
1213 856 $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
1214 857 } elseif ( $clean_tag === 'user_agent' ) {
1215 858 $description = $atts['entry']->description;
1216 859 $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
@@ -1248,14 +891,13 @@
1248 891 * @since 3.0
1249 892 *
1250 893 * @param array $atts
1251 894 *
1252 - * @return string|null
895 + * @return null|string
1253 896 */
1254 897 private static function get_field_shortcode_value( $atts ) {
1255 898 $field = FrmField::getOne( $atts['tag'] );
1256 -
1257 - if ( ! $field ) {
899 + if ( empty( $field ) ) {
1258 900 return null;
1259 901 }
1260 902
1261 903 if ( isset( $atts['show'] ) && $atts['show'] === 'field_label' ) {
@@ -1264,16 +906,14 @@
1264 906 $replace_with = $field->description;
1265 907 } else {
1266 908 $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
1267 909 $string_value = $replace_with;
1268 -
1269 910 if ( is_array( $replace_with ) ) {
1270 - $sep = $atts['sep'] ?? ', ';
1271 - $string_value = FrmAppHelper::safe_implode( $sep, $replace_with );
911 + $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
912 + $string_value = implode( $sep, $replace_with );
1272 913 }
1273 914
1274 - // phpcs:ignore Universal.Operators.StrictComparisons
1275 - if ( ! $string_value && $string_value != '0' ) {
915 + if ( empty( $string_value ) && $string_value != '0' ) {
1276 916 $replace_with = '';
1277 917 } else {
1278 918 $atts['entry_id'] = $atts['entry']->id;
1279 919 $atts['entry_key'] = $atts['entry']->item_key;
@@ -1278,9 +918,9 @@
1278 918 $atts['entry_id'] = $atts['entry']->id;
1279 919 $atts['entry_key'] = $atts['entry']->item_key;
1280 920 $replace_with = self::get_display_value( $replace_with, $field, $atts );
1281 921 }
1282 - }//end if
922 + }
1283 923
1284 924 return $replace_with;
1285 925 }
1286 926
@@ -1287,13 +927,8 @@
1287 927 /**
1288 928 * Get the value to replace a few standard shortcodes
1289 929 *
1290 930 * @since 2.0
1291 - *
1292 - * @param string $tag
1293 - * @param array $atts
1294 - * @param bool $return_array
1295 - *
1296 931 * @return string
1297 932 */
1298 933 public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
1299 934 $new_value = '';
@@ -1300,16 +935,8 @@
1300 935 switch ( $tag ) {
1301 936 case 'admin_email':
1302 937 $new_value = get_option( 'admin_email' );
1303 938 break;
1304 - case 'default-email':
1305 - $frm_settings = FrmAppHelper::get_settings();
1306 - $new_value = ! empty( $frm_settings->default_email ) && is_email( $frm_settings->default_email ) ? $frm_settings->default_email : get_option( 'admin_email' );
1307 - break;
1308 - case 'default-from-email':
1309 - $frm_settings = FrmAppHelper::get_settings();
1310 - $new_value = ! empty( $frm_settings->from_email ) && is_email( $frm_settings->from_email ) ? $frm_settings->from_email : get_option( 'admin_email' );
1311 - break;
1312 939 case 'siteurl':
1313 940 $new_value = FrmAppHelper::site_url();
1314 941 break;
1315 942 case 'frmurl':
@@ -1319,9 +946,9 @@
1319 946 $new_value = FrmAppHelper::site_name();
1320 947 break;
1321 948 case 'get':
1322 949 $new_value = self::process_get_shortcode( $atts, $return_array );
1323 - }//end switch
950 + }
1324 951
1325 952 return $new_value;
1326 953 }
1327 954
@@ -1328,13 +955,9 @@
1328 955 /**
1329 956 * Process the [get] shortcode
1330 957 *
1331 958 * @since 2.0
1332 - *
1333 - * @param array $atts
1334 - * @param bool $return_array
1335 - *
1336 - * @return array|string
959 + * @return string|array
1337 960 */
1338 961 public static function process_get_shortcode( $atts, $return_array = false ) {
1339 962 if ( ! isset( $atts['param'] ) ) {
1340 963 return '';
@@ -1339,9 +962,9 @@
1339 962 if ( ! isset( $atts['param'] ) ) {
1340 963 return '';
1341 964 }
1342 965
1343 - if ( str_contains( $atts['param'], '&#91;' ) ) {
966 + if ( strpos( $atts['param'], '&#91;' ) ) {
1344 967 $atts['param'] = str_replace( '&#91;', '[', $atts['param'] );
1345 968 $atts['param'] = str_replace( '&#93;', ']', $atts['param'] );
1346 969 }
1347 970
@@ -1347,34 +970,28 @@
1347 970
1348 971 $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
1349 972 $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
1350 973
1351 - // phpcs:ignore Universal.Operators.StrictComparisons
1352 974 if ( $new_value == '' ) {
1353 975 if ( ! isset( $atts['prev_val'] ) ) {
1354 976 $atts['prev_val'] = '';
1355 977 }
1356 978
1357 - $new_value = $atts['default'] ?? $atts['prev_val'];
979 + $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
1358 980 }
1359 981
1360 982 if ( is_array( $new_value ) && ! $return_array ) {
1361 - return implode( ', ', $new_value );
983 + $new_value = implode( ', ', $new_value );
1362 984 }
1363 985
1364 986 return $new_value;
1365 987 }
1366 988
1367 - /**
1368 - * @param mixed $value
1369 - * @param object $field
1370 - * @param array $atts
1371 - *
1372 - * @return mixed
1373 - */
1374 989 public static function get_display_value( $value, $field, $atts = array() ) {
990 +
1375 991 $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts );
1376 992 $value = apply_filters( 'frm_get_display_value', $value, $field, $atts );
993 +
1377 994 $value = self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
1378 995
1379 996 return apply_filters( 'frm_display_value', $value, $field, $atts );
1380 997 }
@@ -1380,15 +997,13 @@
1380 997 }
1381 998
1382 999 /**
1383 1000 * @param array $atts Includes value, field, and atts.
1384 - *
1385 - * @return mixed
1386 1001 */
1387 1002 public static function get_unfiltered_display_value( $atts ) {
1388 1003 $value = $atts['value'];
1389 1004 $field = $atts['field'];
1390 - $atts = $atts['atts'] ?? $atts;
1005 + $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
1391 1006
1392 1007 if ( is_array( $field ) ) {
1393 1008 $field = $field['id'];
1394 1009 }
@@ -1401,14 +1016,8 @@
1401 1016 /**
1402 1017 * Get a value from the user profile from the user ID
1403 1018 *
1404 1019 * @since 3.0
1405 - *
1406 - * @param int|string $user_id
1407 - * @param string $user_info
1408 - * @param array $args
1409 - *
1410 - * @return string
1411 1020 */
1412 1021 public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
1413 1022 $defaults = array(
1414 1023 'blank' => false,
@@ -1416,52 +1025,51 @@
1416 1025 'size' => 96,
1417 1026 );
1418 1027
1419 1028 $args = wp_parse_args( $args, $defaults );
1029 +
1420 1030 $user = get_userdata( $user_id );
1421 1031 $info = '';
1422 1032
1423 1033 if ( $user ) {
1424 - if ( $user_info === 'avatar' ) {
1034 + if ( $user_info == 'avatar' ) {
1425 1035 $info = get_avatar( $user_id, $args['size'] );
1426 - } elseif ( $user_info === 'author_link' ) {
1036 + } elseif ( $user_info == 'author_link' ) {
1427 1037 $info = get_author_posts_url( $user_id );
1428 1038 } else {
1429 - $info = $user->$user_info ?? '';
1039 + $info = isset( $user->$user_info ) ? $user->$user_info : '';
1430 1040 }
1431 1041
1432 - if ( 'display_name' === $user_info && ! $info && ! $args['blank'] ) {
1042 + if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
1433 1043 $info = $user->user_login;
1434 1044 }
1435 1045 }
1436 1046
1437 1047 if ( $args['link'] ) {
1438 - return '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
1048 + $info = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
1439 1049 }
1440 1050
1441 1051 return $info;
1442 1052 }
1443 1053
1444 - /**
1445 - * @param string $type
1446 - *
1447 - * @return array
1448 - */
1449 1054 public static function get_field_types( $type ) {
1450 - $single_input = self::single_input_fields();
1451 - $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
1055 + $single_input = self::single_input_fields();
1056 + $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
1057 +
1452 1058 $field_selection = FrmField::all_field_selection();
1453 - $field_types = array();
1454 1059
1455 - if ( in_array( $type, $single_input, true ) ) {
1060 + $field_types = array();
1061 + if ( in_array( $type, $single_input ) ) {
1456 1062 self::field_types_for_input( $single_input, $field_selection, $field_types );
1457 - } elseif ( in_array( $type, $multiple_input, true ) ) {
1063 + } elseif ( in_array( $type, $multiple_input ) ) {
1458 1064 self::field_types_for_input( $multiple_input, $field_selection, $field_types );
1459 1065 } elseif ( isset( $field_selection[ $type ] ) ) {
1460 1066 $field_types[ $type ] = $field_selection[ $type ];
1461 1067 }
1462 1068
1463 - return apply_filters( 'frm_switch_field_types', $field_types, compact( 'type', 'field_selection' ) );
1069 + $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type', 'field_selection' ) );
1070 +
1071 + return $field_types;
1464 1072 }
1465 1073
1466 1074 /**
1467 1075 * Get a list of all fields that use a single value input.
@@ -1466,10 +1074,8 @@
1466 1074 /**
1467 1075 * Get a list of all fields that use a single value input.
1468 1076 *
1469 1077 * @since 4.0
1470 - *
1471 - * @return array
1472 1078 */
1473 1079 public static function single_input_fields() {
1474 1080 $fields = array(
1475 1081 'text',
@@ -1483,26 +1089,15 @@
1483 1089 'hidden',
1484 1090 'time',
1485 1091 'tag',
1486 1092 'password',
1487 - 'gdpr',
1488 1093 );
1489 1094 return apply_filters( 'frm_single_input_fields', $fields );
1490 1095 }
1491 1096
1492 - /**
1493 - * @param string[] $inputs
1494 - * @param array $fields
1495 - * @param array $field_types
1496 - *
1497 - * @return void
1498 - */
1499 1097 private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1500 1098 foreach ( $inputs as $input ) {
1501 - // This may not be set if a field type was removed using the frm_available_fields or frm_pro_available_fields filters.
1502 - if ( array_key_exists( $input, $fields ) ) {
1503 - $field_types[ $input ] = $fields[ $input ];
1504 - }
1099 + $field_types[ $input ] = $fields[ $input ];
1505 1100 unset( $input );
1506 1101 }
1507 1102 }
1508 1103
@@ -1512,12 +1107,12 @@
1512 1107 * @since 2.0.6
1513 1108 *
1514 1109 * @param string $opt_key
1515 1110 *
1516 - * @return bool Returns true if current field option is an "Other" option
1111 + * @return boolean Returns true if current field option is an "Other" option
1517 1112 */
1518 1113 public static function is_other_opt( $opt_key ) {
1519 - return $opt_key && str_starts_with( $opt_key, 'other_' );
1114 + return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1520 1115 }
1521 1116
1522 1117 /**
1523 1118 * Get value that belongs in "Other" text box
@@ -1524,19 +1119,18 @@
1524 1119 *
1525 1120 * @since 2.0.6
1526 1121 *
1527 1122 * @param array $args
1528 - *
1529 - * @return string
1530 1123 */
1531 - public static function get_other_val( $args ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
1532 - $defaults = array(
1124 + public static function get_other_val( $args ) {
1125 + $defaults = array(
1533 1126 'opt_key' => 0,
1534 1127 'field' => array(),
1535 1128 'parent' => false,
1536 1129 'pointer' => false,
1537 1130 );
1538 - $args = wp_parse_args( $args, $defaults );
1131 + $args = wp_parse_args( $args, $defaults );
1132 +
1539 1133 $opt_key = $args['opt_key'];
1540 1134 $field = $args['field'];
1541 1135 $parent = $args['parent'];
1542 1136 $pointer = $args['pointer'];
@@ -1542,9 +1136,9 @@
1542 1136 $pointer = $args['pointer'];
1543 1137 $other_val = '';
1544 1138
1545 1139 // If option is an "other" option and there is a value set for this field,
1546 - // Check if the value belongs in the current "Other" option text field
1140 + // check if the value belongs in the current "Other" option text field
1547 1141 if ( ! self::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) {
1548 1142 return $other_val;
1549 1143 }
1550 1144
@@ -1551,22 +1145,21 @@
1551 1145 // Check posted vals before checking saved values
1552 1146 // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
1553 1147 if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1554 1148 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1555 - $other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
1149 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
1150 + $other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ) : '';
1556 1151 } else {
1557 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
1558 - $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) );
1152 + $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1559 1153 }
1560 1154
1561 1155 return $other_val;
1562 - }
1563 1156
1564 - if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1157 + } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1565 1158 // For normal fields
1566 1159
1567 1160 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1568 - // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
1161 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
1569 1162 $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ) : '';
1570 1163 } else {
1571 1164 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1572 1165 }
@@ -1577,9 +1170,8 @@
1577 1170 // For checkboxes
1578 1171 if ( $field['type'] === 'checkbox' && is_array( $field['value'] ) ) {
1579 1172 // Check if there is an "other" val in saved value and make sure the
1580 1173 // "other" val is not equal to the Other checkbox option
1581 - // phpcs:ignore Universal.Operators.StrictComparisons
1582 1174 if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
1583 1175 $other_val = $field['value'][ $opt_key ];
1584 1176 }
1585 1177 } else {
@@ -1586,30 +1178,26 @@
1586 1178 /**
1587 1179 * For radio buttons and dropdowns
1588 1180 * Check if saved value equals any of the options. If not, set it as the other value.
1589 1181 */
1590 - foreach ( $field['options'] as $opt_val ) {
1182 + foreach ( $field['options'] as $opt_key => $opt_val ) {
1591 1183 $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1592 -
1593 1184 // Multi-select dropdowns - key is not preserved
1594 1185 if ( is_array( $field['value'] ) ) {
1595 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1596 1186 $o_key = array_search( $temp_val, $field['value'] );
1597 -
1598 1187 if ( isset( $field['value'][ $o_key ] ) ) {
1599 1188 unset( $field['value'][ $o_key ], $o_key );
1600 1189 }
1601 - } elseif ( $temp_val == $field['value'] ) { // phpcs:ignore Universal.Operators.StrictComparisons
1190 + } elseif ( $temp_val == $field['value'] ) {
1602 1191 // For radio and regular dropdowns
1603 1192 return '';
1604 1193 } else {
1605 1194 $other_val = $field['value'];
1606 1195 }
1607 - unset( $opt_val, $temp_val );
1196 + unset( $opt_key, $opt_val, $temp_val );
1608 1197 }
1609 -
1610 1198 // For multi-select dropdowns only
1611 - if ( is_array( $field['value'] ) && $field['value'] ) {
1199 + if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1612 1200 $other_val = reset( $field['value'] );
1613 1201 }
1614 1202 }//end if
1615 1203
@@ -1621,13 +1209,13 @@
1621 1209 * Intended for front-end use
1622 1210 *
1623 1211 * @since 2.0.6
1624 1212 *
1625 - * @param array $args Should include field, opt_key and field name.
1626 - * @param bool $other_opt
1627 - * @param string $checked
1213 + * @param array $args Should include field, opt_key and field name.
1214 + * @param boolean $other_opt
1215 + * @param string $checked
1628 1216 *
1629 - * @return array Other args.
1217 + * @return array $other_args
1630 1218 */
1631 1219 public static function prepare_other_input( $args, &$other_opt, &$checked ) {
1632 1220 $other_args = array(
1633 1221 'name' => '',
@@ -1638,9 +1226,9 @@
1638 1226 if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1639 1227 return $other_args;
1640 1228 }
1641 1229
1642 - $other_opt = true;
1230 + $other_opt = true;
1643 1231
1644 1232 self::set_other_name( $args, $other_args );
1645 1233 self::set_other_value( $args, $other_args );
1646 1234
@@ -1661,14 +1249,12 @@
1661 1249 return $other_args;
1662 1250 }
1663 1251
1664 1252 /**
1665 - * @since 2.0.6
1666 - *
1667 1253 * @param array $args
1668 1254 * @param array $other_args
1669 1255 *
1670 - * @return void
1256 + * @since 2.0.6
1671 1257 */
1672 1258 private static function set_other_name( $args, &$other_args ) {
1673 1259 // Set up name for other field
1674 1260 $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
@@ -1684,14 +1270,12 @@
1684 1270
1685 1271 /**
1686 1272 * Find the parent and pointer, and get text for "other" text field
1687 1273 *
1688 - * @since 2.0.6
1689 - *
1690 1274 * @param array $args
1691 1275 * @param array $other_args
1692 1276 *
1693 - * @return void
1277 + * @since 2.0.6
1694 1278 */
1695 1279 private static function set_other_value( $args, &$other_args ) {
1696 1280 $parent = '';
1697 1281 $pointer = '';
@@ -1718,13 +1302,11 @@
1718 1302
1719 1303 /**
1720 1304 * If this field includes an other option, show it
1721 1305 *
1722 - * @since 2.0.6
1723 - *
1724 1306 * @param array $args
1725 1307 *
1726 - * @return void
1308 + * @since 2.0.6
1727 1309 */
1728 1310 public static function include_other_input( $args ) {
1729 1311 if ( ! $args['other_opt'] ) {
1730 1312 return;
@@ -1730,15 +1312,13 @@
1730 1312 return;
1731 1313 }
1732 1314
1733 1315 $classes = array( 'frm_other_input' );
1734 -
1735 - if ( ! $args['checked'] || trim( $args['checked'] ) === '' ) {
1736 - // Hide the field if the other option is not selected
1316 + if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1317 + // hide the field if the other option is not selected
1737 1318 $classes[] = 'frm_pos_none';
1738 1319 }
1739 -
1740 - if ( $args['field']['type'] === 'select' && ! empty( $args['field']['multiple'] ) ) {
1320 + if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1741 1321 $classes[] = 'frm_other_full';
1742 1322 }
1743 1323
1744 1324 // Set up HTML ID for Other field
@@ -1743,11 +1323,10 @@
1743 1323
1744 1324 // Set up HTML ID for Other field
1745 1325 $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1746 1326
1747 - $label = $args['opt_label'] ?? $args['field']['name'];
1327 + $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1748 1328
1749 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1750 1329 echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1751 1330 esc_html( $label ) .
1752 1331 '</label>' .
1753 1332 '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
@@ -1752,9 +1331,8 @@
1752 1331 '</label>' .
1753 1332 '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
1754 1333 ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) .
1755 1334 ' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />';
1756 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1757 1335 }
1758 1336
1759 1337 /**
1760 1338 * Get the HTML id for an "Other" text field
@@ -1761,19 +1339,19 @@
1761 1339 * Note: This does not affect fields in repeating sections
1762 1340 *
1763 1341 * @since 2.0.08
1764 1342 *
1765 - * @param string $type Field type.
1766 - * @param string $html_id
1767 - * @param bool|string $opt_key
1343 + * @param string $type Field type.
1344 + * @param string $html_id
1345 + * @param string|boolean $opt_key
1768 1346 *
1769 - * @return string Other ID.
1347 + * @return string $other_id
1770 1348 */
1771 1349 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1772 1350 $other_id = $html_id;
1773 1351
1774 1352 // If hidden radio field, add an opt key of 0
1775 - if ( $type === 'radio' && $opt_key === false ) {
1353 + if ( $type == 'radio' && $opt_key === false ) {
1776 1354 $opt_key = 0;
1777 1355 }
1778 1356
1779 1357 if ( $opt_key !== false ) {
@@ -1779,21 +1357,17 @@
1779 1357 if ( $opt_key !== false ) {
1780 1358 $other_id .= '-' . $opt_key;
1781 1359 }
1782 1360
1783 - return $other_id . '-otext';
1361 + $other_id .= '-otext';
1362 +
1363 + return $other_id;
1784 1364 }
1785 1365
1786 - /**
1787 - * @param array|string $val
1788 - *
1789 - * @return array|string
1790 - */
1791 1366 public static function switch_field_ids( $val ) {
1792 1367 global $frm_duplicate_ids;
1793 1368 $replace = array();
1794 1369 $replace_with = array();
1795 -
1796 1370 foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1797 1371 $replace[] = '[if ' . $old . ']';
1798 1372 $replace_with[] = '[if ' . $new . ']';
1799 1373 $replace[] = '[if ' . $old . ' ';
@@ -1815,31 +1389,19 @@
1815 1389 $replace[] = 'field_id="' . $old . '"';
1816 1390 $replace_with[] = 'field_id="' . $new . '"';
1817 1391 $replace[] = 'field_id=\"' . $old . '\"';
1818 1392 $replace_with[] = 'field_id=\"' . $new . '\"';
1819 - // This covers conditional logic.
1820 - $replace[] = '_field":"' . $old . '","';
1821 - $replace_with[] = '_field":"' . $new . '","';
1822 1393 unset( $old, $new );
1823 1394 }//end foreach
1824 -
1825 - if ( ! is_array( $val ) ) {
1826 - return str_replace( $replace, $replace_with, $val );
1827 - }
1828 -
1829 - foreach ( $val as $k => $v ) {
1830 - if ( ! is_string( $v ) ) {
1831 - continue;
1395 + if ( is_array( $val ) ) {
1396 + foreach ( $val as $k => $v ) {
1397 + if ( is_string( $v ) ) {
1398 + $val[ $k ] = str_replace( $replace, $replace_with, $v );
1399 + unset( $k, $v );
1400 + }
1832 1401 }
1833 -
1834 - if ( 'custom_html' === $k ) {
1835 - $val[ $k ] = self::switch_ids_except_strings( $replace, $replace_with, array( '[if description]', '[description]', '[/if description]' ), $v );
1836 - unset( $k, $v );
1837 - continue;
1838 - }
1839 -
1840 - $val[ $k ] = str_replace( $replace, $replace_with, $v );
1841 - unset( $k, $v );
1402 + } else {
1403 + $val = str_replace( $replace, $replace_with, $val );
1842 1404 }
1843 1405
1844 1406 return $val;
1845 1407 }
@@ -1844,48 +1406,17 @@
1844 1406 return $val;
1845 1407 }
1846 1408
1847 1409 /**
1848 - * Removes exception strings from replacement arrays and replaces the rest in the provided value string.
1849 - *
1850 - * @since 6.14
1851 - *
1852 - * @param array $replace Values to be replaced.
1853 - * @param array $replace_with Replacement values.
1854 - * @param array $exceptions Array of strings to skip.
1855 - * @param string $value Value to be updated.
1856 - *
1857 - * @return string
1858 - */
1859 - private static function switch_ids_except_strings( $replace, $replace_with, $exceptions, $value ) {
1860 - foreach ( $exceptions as $exception ) {
1861 - $index = array_search( $exception, $replace, true );
1862 -
1863 - if ( false === $index ) {
1864 - continue;
1865 - }
1866 - unset( $replace[ $index ] );
1867 - unset( $replace_with[ $index ] );
1868 - }
1869 -
1870 - return str_replace( $replace, $replace_with, $value );
1871 - }
1872 -
1873 - /**
1874 1410 * @since 4.0
1875 - *
1876 - * @return void
1877 1411 */
1878 1412 public static function bulk_options_overlay() {
1879 1413 $prepop = array();
1880 1414 self::get_bulk_prefilled_opts( $prepop, true );
1881 1415
1882 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php';
1416 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1883 1417 }
1884 1418
1885 - /**
1886 - * @return array
1887 - */
1888 1419 public static function get_us_states() {
1889 1420 $states = array(
1890 1421 'AL' => 'Alabama',
1891 1422 'AK' => 'Alaska',
@@ -1942,11 +1473,8 @@
1942 1473
1943 1474 return apply_filters( 'frm_us_states', $states );
1944 1475 }
1945 1476
1946 - /**
1947 - * @return array
1948 - */
1949 1477 public static function get_countries() {
1950 1478 $countries = array(
1951 1479 __( 'Afghanistan', 'formidable' ),
1952 1480 __( 'Aland Islands', 'formidable' ),
@@ -2211,15 +1739,12 @@
2211 1739 * @since 5.0.04 Add `$include_class` param.
2212 1740 *
2213 1741 * @param array $prepop Bulk options.
2214 1742 * @param array|false $include_class Include the class in the bulk options.
2215 - *
2216 - * @return void
2217 1743 */
2218 1744 public static function get_bulk_prefilled_opts( array &$prepop, $include_class = false ) {
2219 1745 // Countries.
2220 1746 $countries = self::get_countries();
2221 -
2222 1747 if ( $include_class ) {
2223 1748 $countries['class'] = 'frm-countries-opts';
2224 1749 }
2225 1750
@@ -2228,9 +1753,8 @@
2228 1753 // State abv.
2229 1754 $states = self::get_us_states();
2230 1755 $state_abv = array_keys( $states );
2231 1756 sort( $state_abv );
2232 -
2233 1757 if ( $include_class ) {
2234 1758 $state_abv['class'] = 'frm-state-abv-opts';
2235 1759 }
2236 1760
@@ -2238,9 +1762,8 @@
2238 1762
2239 1763 // States.
2240 1764 $states = array_values( $states );
2241 1765 sort( $states );
2242 -
2243 1766 if ( $include_class ) {
2244 1767 $states['class'] = 'frm-states-opts';
2245 1768 }
2246 1769
@@ -2257,9 +1780,8 @@
2257 1780 __( '55-64', 'formidable' ),
2258 1781 __( '65 or Above', 'formidable' ),
2259 1782 __( 'Prefer Not to Answer', 'formidable' ),
2260 1783 );
2261 -
2262 1784 if ( $include_class ) {
2263 1785 $ages['class'] = 'frm-age-opts';
2264 1786 }
2265 1787
@@ -2273,9 +1795,8 @@
2273 1795 __( 'Satisfied', 'formidable' ),
2274 1796 __( 'Very Satisfied', 'formidable' ),
2275 1797 __( 'N/A', 'formidable' ),
2276 1798 );
2277 -
2278 1799 if ( $include_class ) {
2279 1800 $satisfaction['class'] = 'frm-satisfaction-opts';
2280 1801 }
2281 1802
@@ -2289,9 +1810,8 @@
2289 1810 __( 'Important', 'formidable' ),
2290 1811 __( 'Very Important', 'formidable' ),
2291 1812 __( 'N/A', 'formidable' ),
2292 1813 );
2293 -
2294 1814 if ( $include_class ) {
2295 1815 $importance['class'] = 'frm-importance-opts';
2296 1816 }
2297 1817
@@ -2305,9 +1825,8 @@
2305 1825 __( 'Agree', 'formidable' ),
2306 1826 __( 'Strongly Agree', 'formidable' ),
2307 1827 __( 'N/A', 'formidable' ),
2308 1828 );
2309 -
2310 1829 if ( $include_class ) {
2311 1830 $agreement['class'] = 'frm-agreement-opts';
2312 1831 }
2313 1832
@@ -2321,9 +1840,8 @@
2321 1840 __( 'Likely', 'formidable' ),
2322 1841 __( 'Extremely Likely', 'formidable' ),
2323 1842 __( 'N/A', 'formidable' ),
2324 1843 );
2325 -
2326 1844 if ( $include_class ) {
2327 1845 $likely['class'] = 'frm-likely-opts';
2328 1846 }
2329 1847
@@ -2338,10 +1856,8 @@
2338 1856 * @since 2.03.05
2339 1857 *
2340 1858 * @param int $selector_field_id
2341 1859 * @param array $selector_args
2342 - *
2343 - * @return void
2344 1860 */
2345 1861 public static function display_field_value_selector( $selector_field_id, $selector_args ) {
2346 1862 $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
2347 1863 $field_value_selector->display();
@@ -2356,9 +1872,9 @@
2356 1872 *
2357 1873 * @return array
2358 1874 */
2359 1875 public static function convert_field_object_to_flat_array( $field ) {
2360 - $field_options = is_array( $field->field_options ) ? $field->field_options : array();
1876 + $field_options = $field->field_options;
2361 1877 $field_array = get_object_vars( $field );
2362 1878 unset( $field_array['field_options'] );
2363 1879
2364 1880 return $field_array + $field_options;
@@ -2364,43 +1880,11 @@
2364 1880 return $field_array + $field_options;
2365 1881 }
2366 1882
2367 1883 /**
2368 - * Shows add field link.
2369 - *
2370 - * @since 6.30
2371 - *
2372 - * @param array $field_type See file `classes/views/frm-forms/add_field_links.php`.
2373 - *
2374 - * @return void
2375 - */
2376 - public static function show_add_field_link( $field_type ) {
2377 - $field_label = FrmFormsHelper::get_field_link_name( $field_type );
2378 - $classes = 'frmbutton frm6 frm_t' . $field_type['key'];
2379 -
2380 - if ( ! empty( $field_type['hide'] ) ) {
2381 - $classes .= ' frm_hidden';
2382 - }
2383 - ?>
2384 -<li class="<?php echo esc_attr( $classes ); ?>" id="<?php echo esc_attr( $field_type['key'] ); ?>">
2385 - <a href="#" class="frm_add_field" title="<?php echo esc_attr( $field_label ); ?>" role="button" aria-label="<?php echo esc_attr( $field_label ); ?>">
2386 - <?php FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ) ); ?>
2387 - <span><?php echo esc_html( $field_label ); ?></span>
2388 - <?php
2389 - if ( 'credit_card' === $field_type['key'] && ! FrmTransLiteAppHelper::payments_table_exists() ) {
2390 - FrmAppHelper::show_pill_text();
2391 - }
2392 - ?>
2393 - </a>
2394 -</li>
2395 - <?php
2396 - }
2397 -
2398 - /**
2399 1884 * @since 4.04
2400 1885 *
2401 1886 * @param array $args
2402 - *
2403 1887 * @return void
2404 1888 */
2405 1889 public static function show_add_field_buttons( $args ) {
2406 1890 $field_key = $args['field_key'];
@@ -2408,32 +1892,34 @@
2408 1892 $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
2409 1893 $field_name = FrmFormsHelper::get_field_link_name( $field_type );
2410 1894 $field_label .= ' <span>' . $field_name . '</span>';
2411 1895
2412 - if ( ! empty( $field_type['is_new'] ) ) {
2413 - ob_start();
2414 - FrmAppHelper::show_pill_text();
2415 - $field_label .= ob_get_clean();
2416 - }
2417 -
2418 1896 // If the individual field isn't allowed, disable it.
2419 - $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1897 + $run_filter = true;
1898 + $single_no_allow = ' ';
1899 + $install_data = '';
1900 + $requires = '';
1901 + $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1902 + $has_show_upgrade_class = strpos( $field_type['icon'], ' frm_show_upgrade' );
1903 + $show_upgrade = $has_show_upgrade_class || false !== strpos( $args['no_allow_class'], 'frm_show_upgrade' );
2420 1904
2421 - list(
2422 - $run_filter,
2423 - $single_no_allow,
2424 - $install_data,
2425 - $requires,
2426 - $has_show_upgrade_class,
2427 - $has_show_update_class,
2428 - $upgrading,
2429 - $update_addon_name
2430 - ) = self::get_field_upgrade_state( $field_type );
1905 + if ( $has_show_upgrade_class ) {
1906 + $single_no_allow .= 'frm_show_upgrade';
1907 + $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
1908 + $run_filter = false;
1909 + if ( isset( $field_type['addon'] ) ) {
1910 + $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
1911 + if ( isset( $upgrading['url'] ) ) {
1912 + $install_data = json_encode( $upgrading );
1913 + }
1914 + $requires = FrmFormsHelper::get_plan_required( $upgrading );
1915 + } elseif ( isset( $field_type['require'] ) ) {
1916 + $requires = $field_type['require'];
1917 + }
1918 + }
2431 1919
2432 - $show_upgrade = $has_show_upgrade_class || $has_show_update_class || str_contains( $args['no_allow_class'], 'frm_show_upgrade' );
2433 1920 $upgrade_label = '';
2434 1921 $upgrade_message = '';
2435 -
2436 1922 if ( $show_upgrade ) {
2437 1923 /* translators: %s: Field name */
2438 1924 $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
2439 1925
@@ -2452,45 +1938,11 @@
2452 1938 'data-content' => $field_key,
2453 1939 'data-requires' => $requires,
2454 1940 );
2455 1941
2456 - if ( ! empty( $field_type['hide'] ) ) {
2457 - $li_params['class'] .= ' frm_hidden';
2458 - }
2459 -
2460 - if ( ! $show_upgrade && ! empty( $field_type['limit'] ) ) {
2461 - $li_params = self::update_params_with_limit_data( $li_params, $args['id'], $field_key, $field_type['limit'] );
2462 - }
2463 -
2464 - if ( ! empty( $field_type['upsell_image'] ) ) {
2465 - $li_params['data-upsell-image'] = $field_type['upsell_image'];
2466 - }
2467 -
2468 - if ( ! empty( $field_type['learn-more'] ) ) {
2469 - $li_params['data-learn-more'] = FrmAppHelper::get_doc_url(
2470 - $field_type['learn-more'],
2471 - 'form-builder-add-fields',
2472 - str_contains( $field_type['learn-more'], '/' )
2473 - );
2474 - }
2475 -
2476 - if ( $has_show_update_class ) {
2477 - $li_params['data-message'] = sprintf(
2478 - // translators: %1$s: Add-on name, %2$s: Field type name.
2479 - esc_html__( 'You need a newer version of %1$s for %2$s fields.', 'formidable' ),
2480 - $update_addon_name,
2481 - $field_name
2482 - );
2483 - } elseif ( isset( $upgrading['url'] ) ) {
2484 - $li_params['data-message'] = sprintf(
2485 - // translators: %s: Field name
2486 - esc_html__( 'You already have access to %s fields, you\'ll just need to activate to start using them.', 'formidable' ),
2487 - $field_name
2488 - );
2489 - } elseif ( $upgrade_message ) {
1942 + if ( $upgrade_message ) {
2490 1943 $li_params['data-message'] = $upgrade_message;
2491 1944 }
2492 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
2493 1945 ?>
2494 1946 <li <?php FrmAppHelper::array_to_html_params( $li_params, true ); ?>>
2495 1947 <?php
2496 1948 if ( $run_filter ) {
@@ -2495,130 +1947,26 @@
2495 1947 <?php
2496 1948 if ( $run_filter ) {
2497 1949 $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
2498 1950 }
2499 -
2500 - FrmAppHelper::kses_echo( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) );
1951 + echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2501 1952 ?>
2502 1953 </li>
2503 1954 <?php
2504 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
2505 1955 }
2506 1956
2507 1957 /**
2508 - * Parse the upgrade and update flags from a field type's icon class.
2509 - *
2510 - * @since 6.29
2511 - *
2512 - * @param array $field_type Field type configuration, modified in place to strip icon flag classes.
2513 - *
2514 - * @return array Upgrade and update state values for the field button, in positional order.
2515 - */
2516 - private static function get_field_upgrade_state( &$field_type ) {
2517 - $single_no_allow = ' ';
2518 - $run_filter = true;
2519 - $has_show_upgrade_class = false;
2520 - $has_show_update_class = false;
2521 - $install_data = '';
2522 - $requires = '';
2523 - $upgrading = array();
2524 - $update_addon_name = '';
2525 -
2526 - if ( isset( $field_type['icon'] ) ) {
2527 - $has_show_upgrade_class = str_contains( $field_type['icon'], ' frm_show_upgrade' );
2528 - $has_show_update_class = str_contains( $field_type['icon'], ' frm_show_update' );
2529 - }
2530 -
2531 - if ( $has_show_upgrade_class ) {
2532 - $single_no_allow .= 'frm_show_upgrade';
2533 - $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
2534 - $run_filter = false;
2535 -
2536 - if ( isset( $field_type['addon'] ) ) {
2537 - $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
2538 -
2539 - if ( isset( $upgrading['url'] ) ) {
2540 - $install_data = json_encode( $upgrading );
2541 - }
2542 -
2543 - $requires = FrmFormsHelper::get_plan_required( $upgrading );
2544 - } elseif ( isset( $field_type['require'] ) ) {
2545 - $requires = $field_type['require'];
2546 - }
2547 - }
2548 -
2549 - if ( $has_show_update_class ) {
2550 - $single_no_allow .= ' frm_show_update';
2551 - $field_type['icon'] = str_replace( ' frm_show_update', '', $field_type['icon'] );
2552 - $run_filter = false;
2553 - $addon_slug = $field_type['addon'] ?? 'pro';
2554 -
2555 - if ( 'pro' === $addon_slug ) {
2556 - $update_addon_name = __( 'Formidable Pro', 'formidable' );
2557 - } else {
2558 - $addon_data = FrmAddonsController::get_addon( $addon_slug );
2559 - $update_addon_name = $addon_data && ! empty( $addon_data['title'] ) ? $addon_data['title'] : ucfirst( $addon_slug );
2560 - }
2561 -
2562 - $install_data = FrmAddonsController::get_update_install_data( $addon_slug );
2563 - }
2564 -
2565 - return array(
2566 - $run_filter,
2567 - $single_no_allow,
2568 - $install_data,
2569 - $requires,
2570 - $has_show_upgrade_class,
2571 - $has_show_update_class,
2572 - $upgrading,
2573 - $update_addon_name,
2574 - );
2575 - }
2576 -
2577 - /**
2578 - * Updates the params with limit data (the data-limit attribute, and possibly the frm_at_limit class).
2579 - * Some field types are limited to a certain number per form, including coupon fields.
2580 - *
2581 - * @since 6.27
2582 - *
2583 - * @param array $li_params The params.
2584 - * @param int $form_id The form ID.
2585 - * @param string $field_type The field type.
2586 - * @param int $limit The limit.
2587 - *
2588 - * @return array The updated params.
2589 - */
2590 - private static function update_params_with_limit_data( $li_params, $form_id, $field_type, $limit ) {
2591 - $fields_in_form = FrmDb::get_count(
2592 - 'frm_fields',
2593 - array(
2594 - 'form_id' => $form_id,
2595 - 'type' => $field_type,
2596 - )
2597 - );
2598 -
2599 - if ( $fields_in_form >= $limit ) {
2600 - $li_params['class'] .= ' frm_at_limit';
2601 - }
2602 -
2603 - $li_params['data-limit'] = $limit;
2604 -
2605 - return $li_params;
2606 - }
2607 -
2608 - /**
2609 1958 * Shows Display format option.
2610 1959 *
2611 1960 * @since 5.0.04
2612 1961 *
2613 1962 * @param array $field Field data.
2614 - *
2615 - * @return void
2616 1963 */
2617 1964 public static function show_radio_display_format( $field ) {
2618 1965 $options = self::get_display_format_options( $field );
2619 - $args = self::get_display_format_args( $field, $options );
2620 1966
1967 + $args = self::get_display_format_args( $field, $options );
1968 +
2621 1969 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php';
2622 1970 }
2623 1971
2624 1972 /**
@@ -2632,10 +1980,10 @@
2632 1980 */
2633 1981 public static function get_display_format_options( $field ) {
2634 1982 $options = array(
2635 1983 '0' => array(
2636 - 'text' => __( 'Simple', 'formidable' ),
2637 - 'svg' => 'frm_simple_radio',
1984 + 'text' => __( 'Simple', 'formidable' ),
1985 + 'svg' => 'frm_simple_radio',
2638 1986 ),
2639 1987 '1' => array(
2640 1988 'text' => __( 'Images', 'formidable' ),
2641 1989 'svg' => 'frm_image_as_option',
@@ -2640,9 +1988,9 @@
2640 1988 'text' => __( 'Images', 'formidable' ),
2641 1989 'svg' => 'frm_image_as_option',
2642 1990 'addon' => 'pro',
2643 1991 'upgrade' => __( 'Image Options', 'formidable' ),
2644 - 'message' => __( 'Show images instead of radio buttons or check boxes. This is ideal for polls, surveys, segmenting questionnaires and more.', 'formidable' ) . '<img src="' . esc_url( FrmAppHelper::plugin_url() ) . '/images/image-options.png" />', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1992 + 'message' => __( 'Show images instead of radio buttons or check boxes. This is ideal for polls, surveys, segmenting questionnaires and more.', 'formidable' ) . '<img src="' . esc_url( FrmAppHelper::plugin_url() ) . '/images/image-options.png" />',
2645 1993 'content' => 'image-options',
2646 1994 ),
2647 1995 'buttons' => array(
2648 1996 'text' => __( 'Buttons', 'formidable' ),
@@ -2653,12 +2001,8 @@
2653 2001 'content' => 'button-options',
2654 2002 ),
2655 2003 );
2656 2004
2657 - if ( 'product' === FrmField::get_field_type( $field ) ) {
2658 - unset( $options['buttons'] );
2659 - }
2660 -
2661 2005 /**
2662 2006 * Allows modifying the options of Display format setting of Radio field.
2663 2007 *
2664 2008 * @since 5.0.04
@@ -2665,9 +2009,11 @@
2665 2009 *
2666 2010 * @param array $options Options.
2667 2011 * @param array $field
2668 2012 */
2669 - return apply_filters( 'frm_' . $field['type'] . '_display_format_options', $options, $field );
2013 + $options = apply_filters( 'frm_' . $field['type'] . '_display_format_options', $options, $field );
2014 +
2015 + return $options;
2670 2016 }
2671 2017
2672 2018 /**
2673 2019 * Gets display format arguments to pass to the images_dropdown() method.
@@ -2675,9 +2021,8 @@
2675 2021 * @since 5.0.04
2676 2022 *
2677 2023 * @param array $field Field data.
2678 2024 * @param array $options Options array.
2679 - *
2680 2025 * @return array
2681 2026 */
2682 2027 public static function get_display_format_args( $field, $options ) {
2683 2028 $args = array(
@@ -2703,13 +2048,8 @@
2703 2048 }
2704 2049
2705 2050 /**
2706 2051 * @since 5.0.04
2707 - *
2708 - * @param array $options Options.
2709 - * @param array $args Arguments.
2710 - *
2711 - * @return void
2712 2052 */
2713 2053 private static function fill_image_setting_options( $options, &$args ) {
2714 2054 foreach ( $options as $key => $option ) {
2715 2055 $args['options'][ $key ] = $option;
@@ -2719,9 +2059,8 @@
2719 2059 }
2720 2060
2721 2061 unset( $args['options'][ $key ]['addon'] );
2722 2062 $fill = array( 'upgrade', 'message', 'content' );
2723 -
2724 2063 foreach ( $fill as $f ) {
2725 2064 unset( $args['options'][ $key ][ $f ], $f );
2726 2065 }
2727 2066 }
@@ -2729,10 +2068,8 @@
2729 2068
2730 2069 /**
2731 2070 * @since 5.0.04
2732 2071 *
2733 - * @param array $option Option.
2734 - *
2735 2072 * @return array
2736 2073 */
2737 2074 private static function fill_image_setting_addon_link( $option ) {
2738 2075 $custom_attrs = array(
@@ -2743,9 +2080,8 @@
2743 2080 // translators: Add-on name.
2744 2081 $custom_attrs['data-upgrade'] = sprintf( __( 'Formidable %s', 'formidable' ), ucwords( $option['addon'] ) );
2745 2082
2746 2083 $fill = array( 'upgrade', 'message', 'content' );
2747 -
2748 2084 foreach ( $fill as $f ) {
2749 2085 if ( isset( $option[ $f ] ) ) {
2750 2086 $custom_attrs[ 'data-' . $f ] = $option[ $f ];
2751 2087 }
@@ -2755,10 +2091,15 @@
2755 2091 return $custom_attrs;
2756 2092 }
2757 2093
2758 2094 $upgrading = FrmAddonsController::install_link( $option['addon'] );
2095 + if ( isset( $upgrading['url'] ) ) {
2096 + $install_data = wp_json_encode( $upgrading );
2097 + } else {
2098 + $install_data = '';
2099 + }
2759 2100
2760 - $custom_attrs['data-oneclick'] = isset( $upgrading['url'] ) ? wp_json_encode( $upgrading ) : '';
2101 + $custom_attrs['data-oneclick'] = $install_data;
2761 2102 $custom_attrs['data-requires'] = FrmFormsHelper::get_plan_required( $upgrading );
2762 2103
2763 2104 return $custom_attrs;
2764 2105 }
@@ -2764,16 +2105,14 @@
2764 2105 }
2765 2106
2766 2107 /**
2767 2108 * Maybe adjust a field value based on type.
2768 - * Some types require unserializing an array.
2769 - * These types are defined by a array_allowed property on their field model class.
2109 + * Some types require unserializing an array (@see self::field_type_requires_unserialize).
2770 2110 *
2771 2111 * @since 6.2
2772 2112 *
2773 2113 * @param mixed $value
2774 2114 * @param string $field_type
2775 - *
2776 2115 * @return void
2777 2116 */
2778 2117 public static function prepare_field_value( &$value, $field_type ) {
2779 2118 $field_object = FrmFieldFactory::get_field_type( $field_type );
@@ -2782,11 +2121,10 @@
2782 2121
2783 2122 /**
2784 2123 * @since 6.8
2785 2124 *
2786 - * @param int|string $form_id
2125 + * @param string|int $form_id
2787 2126 * @param array $field_ids If this is not empty, the results will be filtered by field id.
2788 - *
2789 2127 * @return array
2790 2128 */
2791 2129 public static function get_draft_field_results( $form_id, $field_ids = array() ) {
2792 2130 if ( FrmAppHelper::pro_is_installed() ) {
@@ -2796,9 +2134,9 @@
2796 2134 $form_ids = array( $form_id );
2797 2135 }
2798 2136
2799 2137 $where = array(
2800 - 'form_id' => $form_ids,
2138 + 'form_id' => $form_ids,
2801 2139 // Do a soft check for fields that look like drafts only.
2802 2140 'field_options LIKE' => 's:5:"draft";i:1;',
2803 2141 );
2804 2142
@@ -2809,9 +2147,9 @@
2809 2147 $rows = FrmDb::get_results( 'frm_fields', $where, 'id, field_options' );
2810 2148
2811 2149 return array_filter(
2812 2150 $rows,
2813 - function ( $row ) {
2151 + function( $row ) {
2814 2152 FrmAppHelper::unserialize_or_decode( $row->field_options );
2815 2153 return is_array( $row->field_options ) && ! empty( $row->field_options['draft'] );
2816 2154 }
2817 2155 );
@@ -2822,10 +2160,9 @@
2822 2160 * Any unsaved draft fields get added to a hidden draft_fields input on load.
2823 2161 *
2824 2162 * @since 6.8
2825 2163 *
2826 - * @param int|string $form_id
2827 - *
2164 + * @param string|int $form_id
2828 2165 * @return array
2829 2166 */
2830 2167 public static function get_all_draft_field_ids( $form_id ) {
2831 2168 $draft_field_rows = self::get_draft_field_results( $form_id );
@@ -2832,169 +2169,95 @@
2832 2169 return wp_list_pluck( $draft_field_rows, 'id' );
2833 2170 }
2834 2171
2835 2172 /**
2836 - * Render AI generate options button.
2837 - *
2838 - * @since 6.24
2839 - *
2840 - * @param array $args Field arguments.
2841 - * @param bool $should_hide_bulk_edit Whether to hide bulk edit.
2842 - *
2843 - * @return void
2173 + * @deprecated 4.0
2844 2174 */
2845 - public static function render_ai_generate_options_button( $args, $should_hide_bulk_edit = false ) {
2846 - $attributes = array(
2847 - 'type' => 'button',
2848 - );
2849 -
2850 - $attributes['class'] = ! empty( $args['class'] ) ? $args['class'] : self::get_ai_generate_options_button_class();
2851 -
2852 - if ( $should_hide_bulk_edit ) {
2853 - $attributes['class'] .= ' frm-force-hidden';
2175 + public static function show_icon_link_js( $atts ) {
2176 + _deprecated_function( __METHOD__, '4.0' );
2177 + $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
2178 + if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
2179 + $atts['icon'] .= 'frm_hidden ';
2854 2180 }
2181 + 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>';
2182 + }
2855 2183
2856 - $data = FrmAppHelper::get_upgrade_data_params(
2857 - 'ai',
2858 - array(
2859 - 'requires' => 'Business',
2860 - 'upgrade' => $args['upgrade_text'] ?? __( 'Generate options with AI', 'formidable' ),
2861 - 'medium' => 'builder',
2862 - 'content' => 'generate-options-with-ai',
2863 - ),
2864 - true
2865 - );
2184 + /**
2185 + * @deprecated 4.0
2186 + */
2187 + public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
2188 + _deprecated_function( __METHOD__, '4.0' );
2189 + }
2866 2190
2867 - if ( in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) && 'active' === $data['plugin-status'] ) {
2868 - // Backwards compatibility "@since 6.24".
2869 - if ( method_exists( 'FrmAIAppController', 'get_ai_generated_options_summary' ) ) {
2870 - $attributes['class'] .= ' frm-ai-generate-options-modal-trigger';
2871 - $attributes['data-fid'] = $args['likert_id'] ?? $args['field']['id'];
2872 - } else {
2873 - $data = array(
2874 - 'modal-title' => __( 'Generate options with AI', 'formidable' ),
2875 - 'modal-content' => __( 'Update the Formidable AI add-on to the last version to use this feature.', 'formidable' ),
2876 - );
2877 - }
2878 - }
2191 + /**
2192 + * @deprecated 4.0
2193 + */
2194 + public static function clear_on_focus_html( $field, $display, $id = '' ) {
2195 + _deprecated_function( __METHOD__, '4.0' );
2196 + }
2879 2197
2880 - if ( empty( $attributes['data-fid'] ) ) {
2881 - unset( $data['plugin-status'] );
2198 + /**
2199 + * @deprecated 4.0
2200 + */
2201 + public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
2202 + _deprecated_function( __METHOD__, '4.0' );
2203 + }
2882 2204
2883 - foreach ( $data as $key => $value ) {
2884 - $attributes[ 'data-' . $key ] = $value;
2885 - }
2886 - }
2887 -
2888 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/generate-options-with-ai.php';
2205 + /**
2206 + * @deprecated 3.0
2207 + * @codeCoverageIgnore
2208 + */
2209 + public static function display_recaptcha() {
2210 + _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
2889 2211 }
2890 2212
2891 2213 /**
2892 - * Get AI generate options button class.
2893 - *
2894 - * @since 6.24
2895 - *
2896 - * @return string Button class.
2214 + * @deprecated 3.0
2215 + * @codeCoverageIgnore
2897 2216 */
2898 - private static function get_ai_generate_options_button_class() {
2899 - return implode(
2900 - ' ',
2901 - array(
2902 - 'frm_form_field',
2903 - 'frm6',
2904 - 'frm6_followed',
2905 - 'frm-h-stack',
2906 - 'button',
2907 - 'frm-button-secondary',
2908 - 'frm-button-gradient',
2909 - 'frm-rounded-6',
2910 - 'frm-max-w-fit',
2911 - 'frm-font-normal',
2912 - 'frm-py-2xs',
2913 - 'frm-px-xs',
2914 - 'frm-mt-xs',
2915 - 'frm-mb-12',
2916 - )
2917 - );
2217 + public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
2218 + FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
2918 2219 }
2919 2220
2920 2221 /**
2921 - * Checks if the field choice should be hidden due to choice limit being reached.
2922 - *
2923 - * @since 6.28
2924 - *
2925 - * @param string $choice_key
2926 - * @param array $field
2927 - *
2928 - * @return bool
2222 + * @deprecated 3.0
2223 + * @codeCoverageIgnore
2929 2224 */
2930 - public static function should_hide_field_choice( $choice_key, $field ) {
2931 - /**
2932 - * @since 6.28
2933 - *
2934 - * @param bool $hide_field_choice
2935 - * @param string $choice_key
2936 - * @param array $field
2937 - */
2938 - return (bool) apply_filters( 'frm_hide_field_choice', false, $choice_key, $field );
2225 + public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
2226 + return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
2939 2227 }
2940 2228
2941 2229 /**
2942 - * @since 6.28
2230 + * @deprecated 3.0
2231 + * @codeCoverageIgnore
2943 2232 *
2944 - * @param array $field
2233 + * @param string $html
2234 + * @param array $field
2235 + * @param array $errors
2236 + * @param object|false $form
2237 + * @param array $args
2945 2238 *
2946 - * @return bool
2239 + * @return string
2947 2240 */
2948 - public static function should_skip_rendering_choices_for_field( $field ) {
2949 - /**
2950 - * @since 6.28
2951 - *
2952 - * @param bool $skip_rendering_options_for_field
2953 - * @param array $field
2954 - */
2955 - return (bool) apply_filters( 'frm_should_skip_rendering_choices_for_field', false, $field );
2241 + public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
2242 + return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args );
2956 2243 }
2957 2244
2958 2245 /**
2959 - * Determine if 'disabled' attribute should be echoed in a field choice's HTML.
2960 - *
2961 - * @since 6.28
2962 - *
2963 - * @param string $choice_key
2964 - * @param bool $is_selected_choice
2965 - * @param array $field
2966 - *
2967 - * @return bool
2246 + * @deprecated 3.0
2247 + * @codeCoverageIgnore
2968 2248 */
2969 - public static function should_disable_choice( $choice_key, $is_selected_choice, $field ) {
2970 - /**
2971 - * @since 6.28
2972 - *
2973 - * @param bool $echo_disabled_attribute
2974 - * @param string $choice_key
2975 - * @param bool $is_selected_choice
2976 - * @param array $field
2977 - */
2978 - return (bool) apply_filters( 'frm_disable_choice', false, $choice_key, $is_selected_choice, $field );
2249 + public static function get_default_field_opts( $type, $field = null, $limit = false ) {
2250 + return FrmDeprecated::get_default_field_opts( $type, $field, $limit );
2979 2251 }
2980 2252
2981 2253 /**
2982 - * @since 6.28
2254 + * @deprecated 2.02.07 This is still referenced in the Highrise add on as of v1.06.
2255 + * @codeCoverageIgnore
2983 2256 *
2984 - * @param array $field
2985 - * @param string $choice_key
2986 - *
2987 - * @return void
2257 + * @param array $args
2258 + * @return string
2988 2259 */
2989 - public static function after_choice_input( $field, $choice_key ) {
2990 - /**
2991 - * Allows adding content after checkbox, radio button, or dropdown fields.
2992 - *
2993 - * @since 6.28
2994 - *
2995 - * @param array $field The field data.
2996 - * @param string $choice_key The option key.
2997 - */
2998 - do_action( 'frm_after_choice_input', $field, $choice_key );
2260 + public static function dropdown_categories( $args ) {
2261 + return FrmDeprecated::dropdown_categories( $args );
2999 2262 }
3000 2263 }