PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2.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 +343 -1180 6.32.1 → 6.2.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 );
@@ -25,14 +13,9 @@
25 13
26 14 $values = self::get_default_field( $type );
27 15
28 16 global $wpdb;
29 - $field_count = FrmDb::get_var(
30 - 'frm_fields',
31 - array( 'form_id' => $form_id ),
32 - 'field_order',
33 - array( 'order_by' => 'field_order DESC' )
34 - );
17 + $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
35 18
36 19 $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' );
37 20 $values['form_id'] = $form_id;
38 21 $values['field_order'] = $field_count + 1;
@@ -38,10 +21,10 @@
38 21 $values['field_order'] = $field_count + 1;
39 22
40 23 $values['field_options']['custom_html'] = self::get_default_html( $type );
41 24
42 - if ( ! empty( $setting ) ) {
43 - if ( in_array( $type, array( 'data', 'lookup' ), true ) ) {
25 + if ( isset( $setting ) && ! empty( $setting ) ) {
26 + if ( in_array( $type, array( 'data', 'lookup' ) ) ) {
44 27 $values['field_options']['data_type'] = $setting;
45 28 } else {
46 29 $values['field_options'][ $setting ] = 1;
47 30 }
@@ -46,56 +29,31 @@
46 29 $values['field_options'][ $setting ] = 1;
47 30 }
48 31 }
49 32
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 33 return $values;
54 34 }
55 35
56 - /**
57 - * @param array $field
58 - * @param string $plus
59 - *
60 - * @return string
61 - */
62 36 public static function get_html_id( $field, $plus = '' ) {
63 37 return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
64 38 }
65 39
66 - /**
67 - * @param object $field
68 - * @param bool $doing_ajax
69 - *
70 - * @return array
71 - */
72 40 public static function setup_edit_vars( $field, $doing_ajax = false ) {
73 41 $values = self::field_object_to_array( $field );
42 +
74 43 return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
75 44 }
76 45
77 - /**
78 - * @param object $field
79 - *
80 - * @return array
81 - */
82 46 public static function field_object_to_array( $field ) {
83 47 $values = (array) $field;
84 48
85 49 self::fill_field_array( $field, $values );
86 50
87 - $values['custom_html'] = $field->field_options['custom_html'] ?? self::get_default_html( $field->type );
51 + $values['custom_html'] = ( isset( $field->field_options['custom_html'] ) ) ? $field->field_options['custom_html'] : self::get_default_html( $field->type );
88 52
89 53 return $values;
90 54 }
91 55
92 - /**
93 - * @param object $field
94 - * @param array $field_array
95 - *
96 - * @return void
97 - */
98 56 private static function fill_field_array( $field, array &$field_array ) {
99 57 $field_array['options'] = $field->options;
100 58 $field_array['value'] = $field->default_value;
101 59
@@ -104,17 +62,11 @@
104 62 $field_array = array_merge( (array) $field->field_options, $field_array );
105 63 }
106 64
107 65 /**
108 - * Prepare field while creating a new entry.
66 + * Prepare field while creating a new entry
109 67 *
110 68 * @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 69 */
118 70 public static function prepare_new_front_field( &$field_array, $field, $args = array() ) {
119 71 $args['action'] = 'new';
120 72 self::prepare_front_field( $field_array, $field, $args );
@@ -120,18 +72,11 @@
120 72 self::prepare_front_field( $field_array, $field, $args );
121 73 }
122 74
123 75 /**
124 - * Prepare field while editing an entry.
76 + * Prepare field while editing an entry
125 77 *
126 78 * @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 79 */
135 80 public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) {
136 81 $args['entry_id'] = $entry_id;
137 82 $args['action'] = 'edit';
@@ -141,14 +86,8 @@
141 86 /**
142 87 * Prepare field while creating a new entry
143 88 *
144 89 * @since 3.0
145 - *
146 - * @param array $field_array
147 - * @param stdClass $field
148 - * @param array $args
149 - *
150 - * @return void
151 90 */
152 91 private static function prepare_front_field( &$field_array, $field, $args ) {
153 92 self::fill_default_field_opts( $field, $field_array );
154 93 self::fill_cleared_strings( $field, $field_array );
@@ -153,30 +92,17 @@
153 92 self::fill_default_field_opts( $field, $field_array );
154 93 self::fill_cleared_strings( $field, $field_array );
155 94
156 95 // Track the original field's type
157 - $field_array['original_type'] = $field->field_options['original_type'] ?? $field->type;
96 + $field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
158 97
159 98 self::prepare_field_options_for_display( $field_array, $field, $args );
160 99
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 - */
100 + if ( $args['action'] == 'edit' ) {
168 101 $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args );
169 -
170 - return;
102 + } else {
103 + $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args );
171 104 }
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 105 }
180 106
181 107 /**
182 108 * @since 3.0
@@ -186,8 +112,9 @@
186 112 * @return array
187 113 */
188 114 public static function get_default_field_options( $type ) {
189 115 $field_type = FrmFieldFactory::get_field_type( $type );
116 +
190 117 return $field_type->get_default_field_options();
191 118 }
192 119
193 120 /**
@@ -193,16 +120,14 @@
193 120 /**
194 121 * @since 3.0
195 122 *
196 123 * @param object $field
197 - * @param array $values
198 - *
199 - * @return void
124 + * @param array $values
200 125 */
201 126 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 );
127 + $check_post = FrmAppHelper::is_admin_page() && $_POST && isset( $_POST['field_options'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
204 128
129 + $defaults = self::get_default_field_options_from_field( $field, $values );
205 130 if ( ! $check_post ) {
206 131 $defaults['required_indicator'] = '';
207 132 $defaults['original_type'] = $field->type;
208 133 }
@@ -207,65 +132,16 @@
207 132 $defaults['original_type'] = $field->type;
208 133 }
209 134
210 135 foreach ( $defaults as $opt => $default ) {
211 - $values[ $opt ] = $field->field_options[ $opt ] ?? $default;
136 + $values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default;
212 137
213 138 if ( $check_post ) {
214 139 self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] );
215 140 }
216 - }
217 - }
218 141
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;
142 + unset( $opt, $default );
229 143 }
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 144 }
269 145
270 146 /**
271 147 * Fill the required message, invalid message,
@@ -273,28 +149,26 @@
273 149 *
274 150 * @since 3.0
275 151 *
276 152 * @param object $field
277 - * @param array $field_array
278 - *
279 - * @return void
153 + * @param array $field_array
280 154 */
281 155 private static function fill_cleared_strings( $field, array &$field_array ) {
282 - // phpcs:ignore Universal.Operators.StrictComparisons
156 + $frm_settings = FrmAppHelper::get_settings();
157 +
283 158 if ( '' == $field_array['blank'] && '1' === $field_array['required'] ) {
284 - $field_array['blank'] = self::default_blank_msg();
159 + $field_array['blank'] = $frm_settings->blank_msg;
285 160 }
286 161
287 162 if ( '' === $field_array['invalid'] ) {
288 163 if ( 'captcha' === $field->type ) {
289 - $frm_settings = FrmAppHelper::get_settings();
290 164 $field_array['invalid'] = $frm_settings->re_msg;
291 165 } else {
292 - $field_array['invalid'] = self::default_invalid_msg();
166 + /* translators: %s: Field name */
167 + $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
293 168 }
294 169 }
295 170
296 - // phpcs:ignore Universal.Operators.StrictComparisons
297 171 if ( '' == $field_array['custom_html'] ) {
298 172 $field_array['custom_html'] = self::get_default_html( $field->type );
299 173 }
300 174 }
@@ -299,48 +173,12 @@
299 173 }
300 174 }
301 175
302 176 /**
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 177 * @since 3.0
338 178 *
339 179 * @param string $setting
340 - * @param mixed $value
341 - *
342 - * @return void
180 + * @param mixed $value
343 181 */
344 182 private static function get_posted_field_setting( $setting, &$value ) {
345 183 if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
346 184 return;
@@ -345,20 +183,16 @@
345 183 if ( ! isset( $_POST['field_options'][ $setting ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
346 184 return;
347 185 }
348 186
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_' ) ) {
187 + if ( strpos( $setting, 'html' ) !== false ) {
188 + // Strip slashes from HTML but not regex or script tags.
189 + $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
190 + } elseif ( strpos( $setting, 'format_' ) === 0 ) {
357 191 // 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
192 + $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
359 193 } else {
360 - $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
194 + $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
361 195 FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
362 196 }
363 197 }
364 198
@@ -365,9 +199,9 @@
365 199 /**
366 200 * @since 3.0
367 201 *
368 202 * @param object $field
369 - * @param array $values The field array is needed for hooks.
203 + * @param array $values The field array is needed for hooks
370 204 *
371 205 * @return array
372 206 */
373 207 public static function get_default_field_options_from_field( $field, $values = array() ) {
@@ -372,11 +206,13 @@
372 206 */
373 207 public static function get_default_field_options_from_field( $field, $values = array() ) {
374 208 $field_type = self::get_original_field( $field );
375 209 $opts = $field_type->get_default_field_options();
376 - $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
377 210
378 - return apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
211 + $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
212 + $opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
213 +
214 + return $opts;
379 215 }
380 216
381 217 /**
382 218 * @since 3.0
@@ -382,14 +218,13 @@
382 218 * @since 3.0
383 219 *
384 220 * @param object $field
385 221 *
386 - * @return FrmFieldType
222 + * @return array
387 223 */
388 224 private static function get_original_field( $field ) {
389 225 $original_type = FrmField::get_option( $field, 'original_type' );
390 -
391 - if ( $original_type && $field->type !== $original_type ) {
226 + if ( ! empty( $original_type ) && $field->type != $original_type ) {
392 227 $field->type = $original_type;
393 228 }
394 229
395 230 return FrmFieldFactory::get_field_object( $field );
@@ -397,13 +232,11 @@
397 232
398 233 /**
399 234 * @since 3.0
400 235 *
401 - * @param array $field_array
236 + * @param array $field_array
402 237 * @param object $field
403 - * @param array $atts
404 - *
405 - * @return void
238 + * @param array $atts
406 239 */
407 240 private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
408 241 $field_obj = FrmFieldFactory::get_field_object( $field );
409 242 $field_array = $field_obj->prepare_front_field( $field_array, $atts );
@@ -417,19 +250,12 @@
417 250 * @return array
418 251 */
419 252 public static function get_default_field( $type ) {
420 253 $field_type = FrmFieldFactory::get_field_type( $type );
254 +
421 255 return $field_type->get_new_field_defaults();
422 256 }
423 257
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 258 public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
433 259 global $wpdb;
434 260
435 261 $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
@@ -444,26 +270,29 @@
444 270
445 271 /**
446 272 * @since 2.0
447 273 *
448 - * @param array|object $field
449 - * @param string $error
274 + * @param $field
275 + * @param $error
450 276 *
451 277 * @return string
452 278 */
453 279 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(
280 + $frm_settings = FrmAppHelper::get_settings();
281 + $default_settings = $frm_settings->default_options();
282 + $field_name = is_array( $field ) ? $field['name'] : $field->name;
283 +
284 + $conf_msg = __( 'The entered values do not match', 'formidable' );
285 + $defaults = array(
457 286 'unique_msg' => array(
458 - 'full' => self::default_unique_msg(),
287 + 'full' => $default_settings['unique_msg'],
459 288 /* translators: %s: Field name */
460 - 'part' => sprintf( __( '%s must be unique', 'formidable' ), '[field_name]' ),
289 + 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ),
461 290 ),
462 291 'invalid' => array(
463 292 'full' => __( 'This field is invalid', 'formidable' ),
464 293 /* translators: %s: Field name */
465 - 'part' => sprintf( __( '%s is invalid', 'formidable' ), '[field_name]' ),
294 + 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ),
466 295 ),
467 296 'blank' => array(
468 297 'full' => $frm_settings->blank_msg,
469 298 'part' => $frm_settings->blank_msg,
@@ -473,107 +302,26 @@
473 302 'part' => $conf_msg,
474 303 ),
475 304 );
476 305
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 306 $msg = FrmField::get_option( $field, $error );
486 - $msg = $msg ? $msg : $defaults[ $error ]['part'];
307 + $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
487 308 $msg = do_shortcode( $msg );
488 309
489 - return self::maybe_replace_substrings_with_field_name( $msg, $error, $field );
310 + return $msg;
490 311 }
491 312
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 313 public static function get_form_fields( $form_id, $error = array() ) {
559 314 $fields = FrmField::get_all_for_form( $form_id );
560 315
561 - FrmFieldName::track_first_name_field( $fields );
562 -
563 316 return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
564 317 }
565 318
566 - /**
567 - * @param string $type
568 - *
569 - * @return string
570 - */
571 319 public static function get_default_html( $type = 'text' ) {
572 320 $field = FrmFieldFactory::get_field_type( $type );
573 321 $default_html = $field->default_html();
574 322
575 - // These hooks are here for reverse compatibility since 3.0
323 + // these hooks are here for reverse compatibility since 3.0
576 324 if ( ! apply_filters( 'frm_normal_field_type_html', true, $type ) ) {
577 325 $default_html = apply_filters( 'frm_other_custom_html', '', $type );
578 326 }
579 327
@@ -580,21 +328,15 @@
580 328 return apply_filters( 'frm_custom_html', $default_html, $type );
581 329 }
582 330
583 331 /**
584 - * @param array $fields
585 - * @param array $errors
332 + * @param array $fields
333 + * @param array $errors
586 334 * @param object $form
587 - * @param object $form_action
588 - *
589 - * @return void
335 + * @param $form_action
590 336 */
591 337 public static function show_fields( $fields, $errors, $form, $form_action ) {
592 338 foreach ( $fields as $field ) {
593 - if ( ! is_array( $field ) ) {
594 - continue;
595 - }
596 -
597 339 $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field );
598 340 $field_obj->show_field( compact( 'errors', 'form', 'form_action' ) );
599 341 }
600 342 }
@@ -601,25 +343,19 @@
601 343
602 344 /**
603 345 * @since 3.0
604 346 *
605 - * @param array $atts
606 - * @param array|string $value
607 - *
608 - * @return void
347 + * @param array $atts
348 + * @param string|array $value
609 349 */
610 350 public static function run_wpautop( $atts, &$value ) {
611 - $autop = $atts['wpautop'] ?? true;
612 -
613 - if ( ! apply_filters( 'frm_use_wpautop', $autop ) ) {
614 - return;
351 + $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true;
352 + if ( apply_filters( 'frm_use_wpautop', $autop ) ) {
353 + if ( is_array( $value ) ) {
354 + $value = implode( "\n", $value );
355 + }
356 + $value = wpautop( $value );
615 357 }
616 -
617 - if ( is_array( $value ) ) {
618 - $value = implode( "\n", $value );
619 - }
620 -
621 - $value = wpautop( $value );
622 358 }
623 359
624 360 /**
625 361 * Get the class to use for the label position
@@ -624,19 +360,13 @@
624 360 /**
625 361 * Get the class to use for the label position
626 362 *
627 363 * @since 2.05
628 - *
629 - * @param string $position
630 - * @param array $field
631 - * @param bool|object|string $form
632 - *
633 - * @return string
634 364 */
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';
365 + public static function &label_position( $position, $field, $form ) {
366 + if ( $position && $position != '' ) {
367 + if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
368 + $position = 'top';
639 369 }
640 370
641 371 return $position;
642 372 }
@@ -641,19 +371,20 @@
641 371 return $position;
642 372 }
643 373
644 374 $position = FrmStylesController::get_style_val( 'position', $form );
645 -
646 - if ( $position === 'none' ) {
375 + if ( $position == 'none' ) {
647 376 $position = 'top';
648 - } elseif ( $position === 'no_label' ) {
377 + } elseif ( $position == 'no_label' ) {
649 378 $position = 'none';
650 - } elseif ( $position === 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
379 + } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
651 380 $position = 'top';
652 381 }
653 382
654 383 $position = apply_filters( 'frm_html_label_position', $position, $field, $form );
655 - return $position ? $position : 'top';
384 + $position = ( ! empty( $position ) ) ? $position : 'top';
385 +
386 + return $position;
656 387 }
657 388
658 389 /**
659 390 * Check if this field type allows placeholders
@@ -658,11 +389,9 @@
658 389 /**
659 390 * Check if this field type allows placeholders
660 391 *
661 392 * @since 2.05
662 - *
663 393 * @param string $type
664 - *
665 394 * @return bool
666 395 */
667 396 public static function is_placeholder_field_type( $type ) {
668 397 return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true );
@@ -667,19 +396,11 @@
667 396 public static function is_placeholder_field_type( $type ) {
668 397 return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true );
669 398 }
670 399
671 - /**
672 - * @param array $field
673 - * @param int|string $opt_key
674 - * @param string $type
675 - *
676 - * @return string
677 - */
678 400 public static function get_checkbox_id( $field, $opt_key, $type = 'checkbox' ) {
679 401 $id = $field['id'];
680 -
681 - if ( ! empty( $field['in_section'] ) && ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
402 + if ( isset( $field['in_section'] ) && $field['in_section'] && ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
682 403 $id .= '-' . $field['in_section'];
683 404 }
684 405
685 406 return 'frm_' . $type . '_' . $id . '-' . $opt_key;
@@ -684,13 +405,8 @@
684 405
685 406 return 'frm_' . $type . '_' . $id . '-' . $opt_key;
686 407 }
687 408
688 - /**
689 - * @param array $field
690 - *
691 - * @return void
692 - */
693 409 public static function show_single_option( $field ) {
694 410 self::hidden_field_option( $field );
695 411
696 412 if ( ! is_array( $field['options'] ) ) {
@@ -696,28 +412,28 @@
696 412 if ( ! is_array( $field['options'] ) ) {
697 413 return;
698 414 }
699 415
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'] );
416 + $base_name = 'default_value_' . $field['id'];
417 + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
704 418
419 + $default_type = self::get_default_value_type( $field );
420 +
705 421 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 );
422 + $field_val = self::get_value_from_array( $opt, $opt_key, $field );
423 + $opt = self::get_label_from_array( $opt, $opt_key, $field );
424 +
708 425 $field_name = $base_name . ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
709 426
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 );
427 + $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 428
713 429 // If this is an "Other" option, get the HTML for it.
714 430 if ( self::is_other_opt( $opt_key ) ) {
715 431 if ( FrmAppHelper::pro_is_installed() ) {
716 - require FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php';
432 + require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' );
717 433 }
718 434 } else {
719 - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
435 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
720 436 }
721 437
722 438 unset( $checked );
723 439 }
@@ -726,31 +442,28 @@
726 442 /**
727 443 * Include hidden row for javascript to duplicate.
728 444 *
729 445 * @since 4.0
730 - *
731 446 * @param array $field
732 - *
733 - * @return void
734 447 */
735 448 private static function hidden_field_option( $field ) {
736 449 // Don't duplicate during an ajax add option.
737 450 $ajax_action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' );
738 -
739 451 if ( $ajax_action === 'frm_add_field_option' ) {
740 452 return;
741 453 }
742 454
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 );
455 + $opt_key = '000';
456 + $field_val = __( 'New Option', 'formidable' );
457 + $opt = __( 'New Option', 'formidable' );
458 + $checked = false;
459 + $field_name = 'default_value_' . $field['id'];
460 + $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
461 +
749 462 $default_type = self::get_default_value_type( $field );
750 - $field_name .= $default_type === 'checkbox' ? '[' . $opt_key . ']' : '';
463 + $field_name .= ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
751 464
752 - require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
465 + require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
753 466 }
754 467
755 468 /**
756 469 * @since 4.0
@@ -755,103 +468,73 @@
755 468 /**
756 469 * @since 4.0
757 470 *
758 471 * @param array $field
759 - *
760 472 * @return string radio or checkbox
761 473 */
762 474 private static function get_default_value_type( $field ) {
475 + $default_type = $field['type'];
763 476 if ( $field['type'] === 'select' ) {
764 - return FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio';
477 + $default_type = FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio';
765 478 }
766 - return $field['type'];
479 + return $default_type;
767 480 }
768 481
769 - /**
770 - * @param array|string $opt
771 - * @param int|string $opt_key
772 - * @param array $field
773 - *
774 - * @return mixed
775 - */
776 482 public static function get_value_from_array( $opt, $opt_key, $field ) {
777 483 $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
484 +
778 485 return FrmFieldsController::check_value( $opt, $opt_key, $field );
779 486 }
780 487
781 - /**
782 - * @param array|string $opt
783 - * @param int|string $opt_key
784 - * @param array $field
785 - *
786 - * @return string
787 - */
788 488 public static function get_label_from_array( $opt, $opt_key, $field ) {
789 489 $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
490 +
790 491 return FrmFieldsController::check_label( $opt );
791 492 }
792 493
793 494 /**
794 - * Shows the inline modal.
795 - *
796 495 * @since 4.0
797 - * @since 6.4.1 Added `inside_class` in the arguments.
798 - *
799 - * @param array $args The arguments.
800 - *
801 - * @return void
802 496 */
803 497 public static function inline_modal( $args ) {
804 498 $defaults = array(
805 - 'id' => '',
806 - 'class' => '',
807 - 'show' => 0,
808 - 'callback' => array(),
809 - 'args' => array(),
810 - 'title' => '',
811 - 'inside_class' => 'inside',
812 - 'dismiss-icon' => true,
499 + 'id' => '',
500 + 'class' => '',
501 + 'show' => 0,
502 + 'callback' => array(),
503 + 'args' => array(),
504 + 'title' => '',
813 505 );
814 - $args = array_merge( $defaults, $args );
506 + $args = array_merge( $defaults, $args );
815 507
816 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php';
508 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php' );
817 509 }
818 510
819 511 /**
820 512 * @since 4.0
821 - *
822 - * @return void
823 513 */
824 514 public static function smart_values() {
825 515 $continue = apply_filters( 'frm_smart_values_box', true );
826 -
827 - if ( $continue !== true ) {
828 - return;
516 + if ( $continue === true ) {
517 + $upgrade_link = array(
518 + 'medium' => 'builder',
519 + 'content' => 'smart-tags',
520 + );
521 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php' );
829 522 }
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 523 }
837 524
838 525 /**
839 526 * @since 4.0
840 - *
841 - * @return void
842 527 */
843 528 public static function input_mask() {
844 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php';
529 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php' );
845 530 }
846 531
847 532 /**
848 533 * @since 4.0
849 - *
850 - * @return void
851 534 */
852 535 public static function layout_classes() {
853 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php';
536 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php' );
854 537 }
855 538
856 539 /**
857 540 * @param int $tax_id
@@ -859,33 +542,28 @@
859 542 * @return string
860 543 */
861 544 public static function get_term_link( $tax_id ) {
862 545 $tax = get_taxonomy( $tax_id );
863 -
864 546 if ( ! $tax ) {
865 547 return '';
866 548 }
867 549
868 - return sprintf(
550 + $link = sprintf(
869 551 /* translators: %1$s: Start HTML link, %2$s: Content type label, %3$s: Content type, %4$s: End HTML link */
870 552 esc_html__( 'Options are dynamically created from your %1$s%2$s: %3$s%4$s', 'formidable' ),
871 553 '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">',
872 554 esc_html__( 'taxonomy', 'formidable' ),
873 - ! empty( $tax->labels->name ) ? $tax->labels->name : esc_html__( 'Categories', 'formidable' ),
555 + empty( $tax->labels->name ) ? esc_html__( 'Categories', 'formidable' ) : $tax->labels->name,
874 556 '</a>'
875 557 );
558 + unset( $tax );
559 +
560 + return $link;
876 561 }
877 562
878 - /**
879 - * @param array|string $observed_value
880 - * @param string $cond
881 - * @param array|string $hide_opt
882 - *
883 - * @return bool
884 - */
885 563 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 );
564 + $hide_opt = self::get_value_for_comparision( $hide_opt );
565 + $observed_value = self::get_value_for_comparision( $observed_value );
888 566
889 567 if ( is_array( $observed_value ) ) {
890 568 return self::array_value_condition( $observed_value, $cond, $hide_opt );
891 569 }
@@ -890,13 +568,12 @@
890 568 return self::array_value_condition( $observed_value, $cond, $hide_opt );
891 569 }
892 570
893 571 $m = false;
894 -
895 572 if ( $cond === '==' ) {
896 - $m = $observed_value == $hide_opt; // phpcs:ignore Universal.Operators.StrictComparisons
573 + $m = $observed_value == $hide_opt;
897 574 } elseif ( $cond === '!=' ) {
898 - $m = $observed_value != $hide_opt; // phpcs:ignore Universal.Operators.StrictComparisons
575 + $m = $observed_value != $hide_opt;
899 576 } elseif ( $cond === '>' ) {
900 577 $m = $observed_value > $hide_opt;
901 578 } elseif ( $cond === '>=' ) {
902 579 $m = $observed_value >= $hide_opt;
@@ -905,20 +582,24 @@
905 582 } elseif ( $cond === '<=' ) {
906 583 $m = $observed_value <= $hide_opt;
907 584 } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) {
908 585 $m = stripos( $observed_value, $hide_opt );
909 - $m = $cond === 'not LIKE' ? $m === false : $m !== false;
586 + if ( $cond === 'not LIKE' ) {
587 + $m = ( $m === false ) ? true : false;
588 + } else {
589 + $m = ( $m === false ) ? false : true;
590 + }
910 591 } elseif ( $cond === '%LIKE' ) {
911 - // Ends with
592 + // ends with
912 593 $length = strlen( $hide_opt );
913 594 $substr = substr( $observed_value, strlen( $observed_value ) - $length );
914 595 $m = 0 === strcasecmp( $substr, $hide_opt );
915 596 } elseif ( 'LIKE%' === $cond ) {
916 - // Starts with
597 + // starts with
917 598 $length = strlen( $hide_opt );
918 599 $substr = substr( $observed_value, 0, $length );
919 600 $m = 0 === strcasecmp( $substr, $hide_opt );
920 - }//end if
601 + }
921 602
922 603 return $m;
923 604 }
924 605
@@ -925,14 +606,10 @@
925 606 /**
926 607 * Trim and sanitize the values
927 608 *
928 609 * @since 2.05
929 - *
930 - * @param array|string $value
931 - *
932 - * @return array|string
933 610 */
934 - private static function get_value_for_comparison( $value ) {
611 + private static function get_value_for_comparision( $value ) {
935 612 // Remove white space from hide_opt
936 613 if ( ! is_array( $value ) ) {
937 614 $value = trim( $value );
938 615 }
@@ -941,37 +618,28 @@
941 618
942 619 return $value;
943 620 }
944 621
945 - /**
946 - * @param array $observed_value
947 - * @param string $cond
948 - * @param array|string $hide_opt
949 - *
950 - * @return bool
951 - */
952 622 public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
953 623 $m = false;
954 -
955 624 if ( $cond === '==' ) {
956 625 if ( is_array( $hide_opt ) ) {
957 626 $m = array_intersect( $hide_opt, $observed_value );
958 - $m = $m !== array();
627 + $m = empty( $m ) ? false : true;
959 628 } else {
960 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
961 629 $m = in_array( $hide_opt, $observed_value );
962 630 }
963 631 } elseif ( $cond === '!=' ) {
964 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
965 632 $m = ! in_array( $hide_opt, $observed_value );
966 633 } elseif ( $cond === '>' ) {
967 - $m = min( $observed_value ) > $hide_opt;
634 + $min = min( $observed_value );
635 + $m = $min > $hide_opt;
968 636 } elseif ( $cond === '<' ) {
969 - $m = max( $observed_value ) < $hide_opt;
637 + $max = max( $observed_value );
638 + $m = $max < $hide_opt;
970 639 } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) {
971 640 foreach ( $observed_value as $ob ) {
972 641 $m = strpos( $ob, $hide_opt );
973 -
974 642 if ( $m !== false ) {
975 643 $m = true;
976 644 break;
977 645 }
@@ -977,12 +645,12 @@
977 645 }
978 646 }
979 647
980 648 if ( $cond === 'not LIKE' ) {
981 - $m = $m === false;
649 + $m = ( $m === false ) ? true : false;
982 650 }
983 651 } elseif ( $cond === '%LIKE' ) {
984 - // Ends with
652 + // ends with
985 653 foreach ( $observed_value as $ob ) {
986 654 if ( $hide_opt === substr( $ob, strlen( $ob ) - strlen( $hide_opt ) ) ) {
987 655 $m = true;
988 656 break;
@@ -988,16 +656,16 @@
988 656 break;
989 657 }
990 658 }
991 659 } elseif ( $cond === 'LIKE%' ) {
992 - // Starts with
660 + // starts with
993 661 foreach ( $observed_value as $ob ) {
994 - if ( str_starts_with( $ob, $hide_opt ) ) {
662 + if ( $hide_opt === substr( $ob, 0, strlen( $hide_opt ) ) ) {
995 663 $m = true;
996 664 break;
997 665 }
998 666 }
999 - }//end if
667 + }
1000 668
1001 669 return $m;
1002 670 }
1003 671
@@ -1004,32 +672,22 @@
1004 672 /**
1005 673 * Replace a few basic shortcodes and field ids
1006 674 *
1007 675 * @since 2.0
1008 - *
1009 - * @param string $value
1010 - * @param object $form
1011 - * @param object $entry
1012 - *
1013 676 * @return string
1014 677 */
1015 678 public static function basic_replace_shortcodes( $value, $form, $entry ) {
1016 - if ( str_contains( $value, '[sitename]' ) ) {
679 + if ( strpos( $value, '[sitename]' ) !== false ) {
1017 680 $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
1018 681 $value = str_replace( '[sitename]', $new_value, $value );
1019 682 }
1020 683
1021 684 $value = apply_filters( 'frm_content', $value, $form, $entry );
685 + $value = do_shortcode( $value );
1022 686
1023 - return do_shortcode( $value );
687 + return $value;
1024 688 }
1025 689
1026 - /**
1027 - * @param string $content
1028 - * @param int|string $form_id
1029 - *
1030 - * @return array
1031 - */
1032 690 public static function get_shortcodes( $content, $form_id ) {
1033 691 if ( FrmAppHelper::pro_is_installed() ) {
1034 692 return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
1035 693 }
@@ -1047,13 +705,8 @@
1047 705
1048 706 return $matches;
1049 707 }
1050 708
1051 - /**
1052 - * @param array $fields
1053 - *
1054 - * @return string
1055 - */
1056 709 public static function allowed_shortcodes( $fields = array() ) {
1057 710 $tagregexp = array(
1058 711 'editlink',
1059 712 'id',
@@ -1061,16 +714,13 @@
1061 714 'ip',
1062 715 'siteurl',
1063 716 'sitename',
1064 717 'admin_email',
1065 - 'default-email',
1066 - 'default-from-email',
1067 718 'post[-|_]id',
1068 719 'created[-|_]at',
1069 720 'updated[-|_]at',
1070 721 'updated[-|_]by',
1071 722 'parent[-|_]id',
1072 - 'form_name',
1073 723 );
1074 724
1075 725 foreach ( $fields as $field ) {
1076 726 $tagregexp[] = $field->id;
@@ -1076,21 +726,16 @@
1076 726 $tagregexp[] = $field->id;
1077 727 $tagregexp[] = $field->field_key;
1078 728 }
1079 729
1080 - return implode( '|', $tagregexp );
730 + $tagregexp = implode( '|', $tagregexp );
731 +
732 + return $tagregexp;
1081 733 }
1082 734
1083 - /**
1084 - * @param string $content
1085 - * @param false|object $entry
1086 - * @param array $shortcodes
1087 - *
1088 - * @return string
1089 - */
1090 735 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1091 736 foreach ( $shortcodes[0] as $short_key => $tag ) {
1092 - if ( ! $tag ) {
737 + if ( empty( $tag ) ) {
1093 738 continue;
1094 739 }
1095 740
1096 741 $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
@@ -1114,44 +759,26 @@
1114 759
1115 760 /**
1116 761 * @param string $replace_with
1117 762 * @param array $atts
1118 - *
1119 763 * @return string
1120 764 */
1121 765 private static function trigger_shortcode_atts( $replace_with, $atts ) {
1122 - $supported_atts = array( 'remove_accents', 'sanitize', 'sanitize_url' );
766 + $supported_atts = array( 'sanitize', 'sanitize_url' );
1123 767 $included_atts = array_intersect( $supported_atts, array_keys( $atts ) );
1124 -
1125 768 foreach ( $included_atts as $included_att ) {
1126 769 if ( '0' === $atts[ $included_att ] ) {
1127 770 // Skip any option that uses 0 so sanitize_url=0 does not encode.
1128 771 continue;
1129 772 }
1130 -
1131 773 $function = 'atts_' . $included_att;
1132 - $replace_with = self::$function( $replace_with );
774 + $replace_with = self::$function( $replace_with, $atts );
1133 775 }
1134 -
1135 776 return $replace_with;
1136 777 }
1137 778
1138 779 /**
1139 - * Converts all accent characters to ASCII characters.
1140 - *
1141 - * @since 6.3.1
1142 - *
1143 - * @param string $replace_with The text to remove accents from.
1144 - *
1145 - * @return string
1146 - */
1147 - public static function atts_remove_accents( $replace_with ) {
1148 - return remove_accents( $replace_with );
1149 - }
1150 -
1151 - /**
1152 780 * @param string $replace_with
1153 - *
1154 781 * @return string
1155 782 */
1156 783 private static function atts_sanitize( $replace_with ) {
1157 784 return sanitize_title_with_dashes( $replace_with );
@@ -1158,9 +785,8 @@
1158 785 }
1159 786
1160 787 /**
1161 788 * @param string $replace_with
1162 - *
1163 789 * @return string
1164 790 */
1165 791 private static function atts_sanitize_url( $replace_with ) {
1166 792 return urlencode( $replace_with );
@@ -1170,21 +796,14 @@
1170 796 * Prevent shortcodes in fields from being processed
1171 797 *
1172 798 * @since 3.01.02
1173 799 *
1174 - * @param array $atts Includes entry object.
1175 - * @param string|null $value
1176 - *
1177 - * @return void
800 + * @param array $atts - includes entry object
801 + * @param string $value
1178 802 */
1179 803 public static function sanitize_embedded_shortcodes( $atts, &$value ) {
1180 - if ( is_null( $value ) ) {
1181 - return;
1182 - }
1183 -
1184 804 $atts['value'] = $value;
1185 805 $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
1186 -
1187 806 if ( $should_sanitize ) {
1188 807 $value = str_replace( '[', '&#91;', $value );
1189 808 }
1190 809 }
@@ -1191,9 +810,9 @@
1191 810
1192 811 /**
1193 812 * @since 3.0
1194 813 *
1195 - * @param array $atts
814 + * @param $atts
1196 815 *
1197 816 * @return string
1198 817 */
1199 818 private static function get_value_for_shortcode( $atts ) {
@@ -1204,21 +823,21 @@
1204 823 'key' => $atts['entry']->item_key,
1205 824 'ip' => $atts['entry']->ip,
1206 825 );
1207 826
1208 - $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get', 'default-email', 'default-from-email' );
827 + $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
1209 828
1210 829 if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
1211 830 $replace_with = $shortcode_values[ $atts['tag'] ];
1212 - } elseif ( in_array( $atts['tag'], $dynamic_default, true ) ) {
831 + } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
1213 832 $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
1214 - } elseif ( $clean_tag === 'user_agent' ) {
833 + } elseif ( $clean_tag == 'user_agent' ) {
1215 834 $description = $atts['entry']->description;
1216 835 $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
1217 - } elseif ( $clean_tag === 'created_at' || $clean_tag === 'updated_at' ) {
836 + } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
1218 837 $atts['tag'] = $clean_tag;
1219 838 $replace_with = self::get_entry_timestamp( $atts );
1220 - } elseif ( $clean_tag === 'created_by' || $clean_tag === 'updated_by' ) {
839 + } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
1221 840 $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
1222 841 } else {
1223 842 $replace_with = self::get_field_shortcode_value( $atts );
1224 843 }
@@ -1228,9 +847,9 @@
1228 847
1229 848 /**
1230 849 * @since 3.0
1231 850 *
1232 - * @param array $atts
851 + * @param $atts
1233 852 *
1234 853 * @return string
1235 854 */
1236 855 private static function get_entry_timestamp( $atts ) {
@@ -1246,16 +865,15 @@
1246 865
1247 866 /**
1248 867 * @since 3.0
1249 868 *
1250 - * @param array $atts
869 + * @param $atts
1251 870 *
1252 - * @return string|null
871 + * @return null|string
1253 872 */
1254 873 private static function get_field_shortcode_value( $atts ) {
1255 874 $field = FrmField::getOne( $atts['tag'] );
1256 -
1257 - if ( ! $field ) {
875 + if ( empty( $field ) ) {
1258 876 return null;
1259 877 }
1260 878
1261 879 if ( isset( $atts['show'] ) && $atts['show'] === 'field_label' ) {
@@ -1264,16 +882,14 @@
1264 882 $replace_with = $field->description;
1265 883 } else {
1266 884 $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
1267 885 $string_value = $replace_with;
1268 -
1269 886 if ( is_array( $replace_with ) ) {
1270 - $sep = $atts['sep'] ?? ', ';
1271 - $string_value = FrmAppHelper::safe_implode( $sep, $replace_with );
887 + $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
888 + $string_value = implode( $sep, $replace_with );
1272 889 }
1273 890
1274 - // phpcs:ignore Universal.Operators.StrictComparisons
1275 - if ( ! $string_value && $string_value != '0' ) {
891 + if ( empty( $string_value ) && $string_value != '0' ) {
1276 892 $replace_with = '';
1277 893 } else {
1278 894 $atts['entry_id'] = $atts['entry']->id;
1279 895 $atts['entry_key'] = $atts['entry']->item_key;
@@ -1278,9 +894,9 @@
1278 894 $atts['entry_id'] = $atts['entry']->id;
1279 895 $atts['entry_key'] = $atts['entry']->item_key;
1280 896 $replace_with = self::get_display_value( $replace_with, $field, $atts );
1281 897 }
1282 - }//end if
898 + }
1283 899
1284 900 return $replace_with;
1285 901 }
1286 902
@@ -1287,13 +903,8 @@
1287 903 /**
1288 904 * Get the value to replace a few standard shortcodes
1289 905 *
1290 906 * @since 2.0
1291 - *
1292 - * @param string $tag
1293 - * @param array $atts
1294 - * @param bool $return_array
1295 - *
1296 907 * @return string
1297 908 */
1298 909 public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
1299 910 $new_value = '';
@@ -1300,16 +911,8 @@
1300 911 switch ( $tag ) {
1301 912 case 'admin_email':
1302 913 $new_value = get_option( 'admin_email' );
1303 914 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 915 case 'siteurl':
1313 916 $new_value = FrmAppHelper::site_url();
1314 917 break;
1315 918 case 'frmurl':
@@ -1319,9 +922,9 @@
1319 922 $new_value = FrmAppHelper::site_name();
1320 923 break;
1321 924 case 'get':
1322 925 $new_value = self::process_get_shortcode( $atts, $return_array );
1323 - }//end switch
926 + }
1324 927
1325 928 return $new_value;
1326 929 }
1327 930
@@ -1328,13 +931,9 @@
1328 931 /**
1329 932 * Process the [get] shortcode
1330 933 *
1331 934 * @since 2.0
1332 - *
1333 - * @param array $atts
1334 - * @param bool $return_array
1335 - *
1336 - * @return array|string
935 + * @return string|array
1337 936 */
1338 937 public static function process_get_shortcode( $atts, $return_array = false ) {
1339 938 if ( ! isset( $atts['param'] ) ) {
1340 939 return '';
@@ -1339,9 +938,9 @@
1339 938 if ( ! isset( $atts['param'] ) ) {
1340 939 return '';
1341 940 }
1342 941
1343 - if ( str_contains( $atts['param'], '&#91;' ) ) {
942 + if ( strpos( $atts['param'], '&#91;' ) ) {
1344 943 $atts['param'] = str_replace( '&#91;', '[', $atts['param'] );
1345 944 $atts['param'] = str_replace( '&#93;', ']', $atts['param'] );
1346 945 }
1347 946
@@ -1347,34 +946,28 @@
1347 946
1348 947 $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
1349 948 $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
1350 949
1351 - // phpcs:ignore Universal.Operators.StrictComparisons
1352 950 if ( $new_value == '' ) {
1353 951 if ( ! isset( $atts['prev_val'] ) ) {
1354 952 $atts['prev_val'] = '';
1355 953 }
1356 954
1357 - $new_value = $atts['default'] ?? $atts['prev_val'];
955 + $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
1358 956 }
1359 957
1360 958 if ( is_array( $new_value ) && ! $return_array ) {
1361 - return implode( ', ', $new_value );
959 + $new_value = implode( ', ', $new_value );
1362 960 }
1363 961
1364 962 return $new_value;
1365 963 }
1366 964
1367 - /**
1368 - * @param mixed $value
1369 - * @param object $field
1370 - * @param array $atts
1371 - *
1372 - * @return mixed
1373 - */
1374 965 public static function get_display_value( $value, $field, $atts = array() ) {
966 +
1375 967 $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts );
1376 968 $value = apply_filters( 'frm_get_display_value', $value, $field, $atts );
969 +
1377 970 $value = self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
1378 971
1379 972 return apply_filters( 'frm_display_value', $value, $field, $atts );
1380 973 }
@@ -1379,16 +972,14 @@
1379 972 return apply_filters( 'frm_display_value', $value, $field, $atts );
1380 973 }
1381 974
1382 975 /**
1383 - * @param array $atts Includes value, field, and atts.
1384 - *
1385 - * @return mixed
976 + * @param $atts array Includes value, field, and atts
1386 977 */
1387 978 public static function get_unfiltered_display_value( $atts ) {
1388 979 $value = $atts['value'];
1389 980 $field = $atts['field'];
1390 - $atts = $atts['atts'] ?? $atts;
981 + $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
1391 982
1392 983 if ( is_array( $field ) ) {
1393 984 $field = $field['id'];
1394 985 }
@@ -1401,14 +992,8 @@
1401 992 /**
1402 993 * Get a value from the user profile from the user ID
1403 994 *
1404 995 * @since 3.0
1405 - *
1406 - * @param int|string $user_id
1407 - * @param string $user_info
1408 - * @param array $args
1409 - *
1410 - * @return string
1411 996 */
1412 997 public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
1413 998 $defaults = array(
1414 999 'blank' => false,
@@ -1416,52 +1001,51 @@
1416 1001 'size' => 96,
1417 1002 );
1418 1003
1419 1004 $args = wp_parse_args( $args, $defaults );
1005 +
1420 1006 $user = get_userdata( $user_id );
1421 1007 $info = '';
1422 1008
1423 1009 if ( $user ) {
1424 - if ( $user_info === 'avatar' ) {
1010 + if ( $user_info == 'avatar' ) {
1425 1011 $info = get_avatar( $user_id, $args['size'] );
1426 - } elseif ( $user_info === 'author_link' ) {
1012 + } elseif ( $user_info == 'author_link' ) {
1427 1013 $info = get_author_posts_url( $user_id );
1428 1014 } else {
1429 - $info = $user->$user_info ?? '';
1015 + $info = isset( $user->$user_info ) ? $user->$user_info : '';
1430 1016 }
1431 1017
1432 - if ( 'display_name' === $user_info && ! $info && ! $args['blank'] ) {
1018 + if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
1433 1019 $info = $user->user_login;
1434 1020 }
1435 1021 }
1436 1022
1437 1023 if ( $args['link'] ) {
1438 - return '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
1024 + $info = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
1439 1025 }
1440 1026
1441 1027 return $info;
1442 1028 }
1443 1029
1444 - /**
1445 - * @param string $type
1446 - *
1447 - * @return array
1448 - */
1449 1030 public static function get_field_types( $type ) {
1450 - $single_input = self::single_input_fields();
1451 - $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
1031 + $single_input = self::single_input_fields();
1032 + $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
1033 +
1452 1034 $field_selection = FrmField::all_field_selection();
1453 - $field_types = array();
1454 1035
1455 - if ( in_array( $type, $single_input, true ) ) {
1036 + $field_types = array();
1037 + if ( in_array( $type, $single_input ) ) {
1456 1038 self::field_types_for_input( $single_input, $field_selection, $field_types );
1457 - } elseif ( in_array( $type, $multiple_input, true ) ) {
1039 + } elseif ( in_array( $type, $multiple_input ) ) {
1458 1040 self::field_types_for_input( $multiple_input, $field_selection, $field_types );
1459 1041 } elseif ( isset( $field_selection[ $type ] ) ) {
1460 1042 $field_types[ $type ] = $field_selection[ $type ];
1461 1043 }
1462 1044
1463 - return apply_filters( 'frm_switch_field_types', $field_types, compact( 'type', 'field_selection' ) );
1045 + $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type', 'field_selection' ) );
1046 +
1047 + return $field_types;
1464 1048 }
1465 1049
1466 1050 /**
1467 1051 * Get a list of all fields that use a single value input.
@@ -1466,10 +1050,8 @@
1466 1050 /**
1467 1051 * Get a list of all fields that use a single value input.
1468 1052 *
1469 1053 * @since 4.0
1470 - *
1471 - * @return array
1472 1054 */
1473 1055 public static function single_input_fields() {
1474 1056 $fields = array(
1475 1057 'text',
@@ -1483,26 +1065,15 @@
1483 1065 'hidden',
1484 1066 'time',
1485 1067 'tag',
1486 1068 'password',
1487 - 'gdpr',
1488 1069 );
1489 1070 return apply_filters( 'frm_single_input_fields', $fields );
1490 1071 }
1491 1072
1492 - /**
1493 - * @param string[] $inputs
1494 - * @param array $fields
1495 - * @param array $field_types
1496 - *
1497 - * @return void
1498 - */
1499 1073 private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1500 1074 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 - }
1075 + $field_types[ $input ] = $fields[ $input ];
1505 1076 unset( $input );
1506 1077 }
1507 1078 }
1508 1079
@@ -1512,12 +1083,12 @@
1512 1083 * @since 2.0.6
1513 1084 *
1514 1085 * @param string $opt_key
1515 1086 *
1516 - * @return bool Returns true if current field option is an "Other" option
1087 + * @return boolean Returns true if current field option is an "Other" option
1517 1088 */
1518 1089 public static function is_other_opt( $opt_key ) {
1519 - return $opt_key && str_starts_with( $opt_key, 'other_' );
1090 + return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1520 1091 }
1521 1092
1522 1093 /**
1523 1094 * Get value that belongs in "Other" text box
@@ -1524,19 +1095,18 @@
1524 1095 *
1525 1096 * @since 2.0.6
1526 1097 *
1527 1098 * @param array $args
1528 - *
1529 - * @return string
1530 1099 */
1531 - public static function get_other_val( $args ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
1532 - $defaults = array(
1100 + public static function get_other_val( $args ) {
1101 + $defaults = array(
1533 1102 'opt_key' => 0,
1534 1103 'field' => array(),
1535 1104 'parent' => false,
1536 1105 'pointer' => false,
1537 1106 );
1538 - $args = wp_parse_args( $args, $defaults );
1107 + $args = wp_parse_args( $args, $defaults );
1108 +
1539 1109 $opt_key = $args['opt_key'];
1540 1110 $field = $args['field'];
1541 1111 $parent = $args['parent'];
1542 1112 $pointer = $args['pointer'];
@@ -1542,9 +1112,9 @@
1542 1112 $pointer = $args['pointer'];
1543 1113 $other_val = '';
1544 1114
1545 1115 // 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
1116 + // check if the value belongs in the current "Other" option text field
1547 1117 if ( ! self::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) {
1548 1118 return $other_val;
1549 1119 }
1550 1120
@@ -1551,22 +1121,21 @@
1551 1121 // Check posted vals before checking saved values
1552 1122 // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
1553 1123 if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1554 1124 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
1125 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
1126 + $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 1127 } else {
1557 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
1558 - $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) );
1128 + $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1559 1129 }
1560 1130
1561 1131 return $other_val;
1562 - }
1563 1132
1564 - if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1133 + } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1565 1134 // For normal fields
1566 1135
1567 1136 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1568 - // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
1137 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
1569 1138 $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 1139 } else {
1571 1140 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1572 1141 }
@@ -1571,15 +1140,14 @@
1571 1140 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1572 1141 }
1573 1142
1574 1143 return $other_val;
1575 - }//end if
1144 + }
1576 1145
1577 1146 // For checkboxes
1578 1147 if ( $field['type'] === 'checkbox' && is_array( $field['value'] ) ) {
1579 1148 // Check if there is an "other" val in saved value and make sure the
1580 1149 // "other" val is not equal to the Other checkbox option
1581 - // phpcs:ignore Universal.Operators.StrictComparisons
1582 1150 if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
1583 1151 $other_val = $field['value'][ $opt_key ];
1584 1152 }
1585 1153 } else {
@@ -1586,33 +1154,29 @@
1586 1154 /**
1587 1155 * For radio buttons and dropdowns
1588 1156 * Check if saved value equals any of the options. If not, set it as the other value.
1589 1157 */
1590 - foreach ( $field['options'] as $opt_val ) {
1158 + foreach ( $field['options'] as $opt_key => $opt_val ) {
1591 1159 $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1592 -
1593 1160 // Multi-select dropdowns - key is not preserved
1594 1161 if ( is_array( $field['value'] ) ) {
1595 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1596 1162 $o_key = array_search( $temp_val, $field['value'] );
1597 -
1598 1163 if ( isset( $field['value'][ $o_key ] ) ) {
1599 1164 unset( $field['value'][ $o_key ], $o_key );
1600 1165 }
1601 - } elseif ( $temp_val == $field['value'] ) { // phpcs:ignore Universal.Operators.StrictComparisons
1166 + } elseif ( $temp_val == $field['value'] ) {
1602 1167 // For radio and regular dropdowns
1603 1168 return '';
1604 1169 } else {
1605 1170 $other_val = $field['value'];
1606 1171 }
1607 - unset( $opt_val, $temp_val );
1172 + unset( $opt_key, $opt_val, $temp_val );
1608 1173 }
1609 -
1610 1174 // For multi-select dropdowns only
1611 - if ( is_array( $field['value'] ) && $field['value'] ) {
1175 + if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1612 1176 $other_val = reset( $field['value'] );
1613 1177 }
1614 - }//end if
1178 + }
1615 1179
1616 1180 return $other_val;
1617 1181 }
1618 1182
@@ -1621,13 +1185,13 @@
1621 1185 * Intended for front-end use
1622 1186 *
1623 1187 * @since 2.0.6
1624 1188 *
1625 - * @param array $args Should include field, opt_key and field name.
1626 - * @param bool $other_opt
1189 + * @param array $args should include field, opt_key and field name
1190 + * @param boolean $other_opt
1627 1191 * @param string $checked
1628 1192 *
1629 - * @return array Other args.
1193 + * @return array $other_args
1630 1194 */
1631 1195 public static function prepare_other_input( $args, &$other_opt, &$checked ) {
1632 1196 $other_args = array(
1633 1197 'name' => '',
@@ -1633,14 +1197,14 @@
1633 1197 'name' => '',
1634 1198 'value' => '',
1635 1199 );
1636 1200
1637 - // Check if this is an "Other" option.
1201 + //Check if this is an "Other" option
1638 1202 if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1639 1203 return $other_args;
1640 1204 }
1641 1205
1642 - $other_opt = true;
1206 + $other_opt = true;
1643 1207
1644 1208 self::set_other_name( $args, $other_args );
1645 1209 self::set_other_value( $args, $other_args );
1646 1210
@@ -1647,37 +1211,25 @@
1647 1211 if ( '' !== $other_args['value'] ) {
1648 1212 $checked = 'checked="checked" ';
1649 1213 }
1650 1214
1651 - // If 'other' is selected as one of the default values for a checkbox field, 'checked' attribute should be on.
1652 - if ( ! $checked &&
1653 - $args['field']['type'] === 'checkbox' &&
1654 - is_array( $args['field']['value'] ) &&
1655 - isset( $args['field_val'] ) &&
1656 - in_array( $args['field_val'], $args['field']['value'], true )
1657 - ) {
1658 - $checked = 'checked="checked" ';
1659 - }
1660 -
1661 1215 return $other_args;
1662 1216 }
1663 1217
1664 1218 /**
1665 - * @since 2.0.6
1666 - *
1667 1219 * @param array $args
1668 1220 * @param array $other_args
1669 1221 *
1670 - * @return void
1222 + * @since 2.0.6
1671 1223 */
1672 1224 private static function set_other_name( $args, &$other_args ) {
1673 - // Set up name for other field
1225 + //Set up name for other field
1674 1226 $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1675 1227 $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] );
1676 1228 $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']';
1677 1229
1678 - // Converts item_meta[field_id] => item_meta[other][field_id] and
1679 - // item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1230 + //Converts item_meta[field_id] => item_meta[other][field_id] and
1231 + //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1680 1232 if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1681 1233 $other_args['name'] .= '[' . $args['opt_key'] . ']';
1682 1234 }
1683 1235 }
@@ -1684,14 +1236,12 @@
1684 1236
1685 1237 /**
1686 1238 * Find the parent and pointer, and get text for "other" text field
1687 1239 *
1688 - * @since 2.0.6
1689 - *
1690 1240 * @param array $args
1691 1241 * @param array $other_args
1692 1242 *
1693 - * @return void
1243 + * @since 2.0.6
1694 1244 */
1695 1245 private static function set_other_value( $args, &$other_args ) {
1696 1246 $parent = '';
1697 1247 $pointer = '';
@@ -1718,13 +1268,11 @@
1718 1268
1719 1269 /**
1720 1270 * If this field includes an other option, show it
1721 1271 *
1272 + * @param $args array
1273 + *
1722 1274 * @since 2.0.6
1723 - *
1724 - * @param array $args
1725 - *
1726 - * @return void
1727 1275 */
1728 1276 public static function include_other_input( $args ) {
1729 1277 if ( ! $args['other_opt'] ) {
1730 1278 return;
@@ -1730,15 +1278,13 @@
1730 1278 return;
1731 1279 }
1732 1280
1733 1281 $classes = array( 'frm_other_input' );
1734 -
1735 - if ( ! $args['checked'] || trim( $args['checked'] ) === '' ) {
1736 - // Hide the field if the other option is not selected
1282 + if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1283 + // hide the field if the other option is not selected
1737 1284 $classes[] = 'frm_pos_none';
1738 1285 }
1739 -
1740 - if ( $args['field']['type'] === 'select' && ! empty( $args['field']['multiple'] ) ) {
1286 + if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1741 1287 $classes[] = 'frm_other_full';
1742 1288 }
1743 1289
1744 1290 // Set up HTML ID for Other field
@@ -1743,11 +1289,10 @@
1743 1289
1744 1290 // Set up HTML ID for Other field
1745 1291 $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1746 1292
1747 - $label = $args['opt_label'] ?? $args['field']['name'];
1293 + $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1748 1294
1749 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1750 1295 echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1751 1296 esc_html( $label ) .
1752 1297 '</label>' .
1753 1298 '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
@@ -1752,9 +1297,8 @@
1752 1297 '</label>' .
1753 1298 '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
1754 1299 ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) .
1755 1300 ' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />';
1756 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1757 1301 }
1758 1302
1759 1303 /**
1760 1304 * Get the HTML id for an "Other" text field
@@ -1761,19 +1305,19 @@
1761 1305 * Note: This does not affect fields in repeating sections
1762 1306 *
1763 1307 * @since 2.0.08
1764 1308 *
1765 - * @param string $type Field type.
1766 - * @param string $html_id
1767 - * @param bool|string $opt_key
1309 + * @param string $type - field type
1310 + * @param string $html_id
1311 + * @param string|boolean $opt_key
1768 1312 *
1769 - * @return string Other ID.
1313 + * @return string $other_id
1770 1314 */
1771 1315 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1772 1316 $other_id = $html_id;
1773 1317
1774 1318 // If hidden radio field, add an opt key of 0
1775 - if ( $type === 'radio' && $opt_key === false ) {
1319 + if ( $type == 'radio' && $opt_key === false ) {
1776 1320 $opt_key = 0;
1777 1321 }
1778 1322
1779 1323 if ( $opt_key !== false ) {
@@ -1779,21 +1323,17 @@
1779 1323 if ( $opt_key !== false ) {
1780 1324 $other_id .= '-' . $opt_key;
1781 1325 }
1782 1326
1783 - return $other_id . '-otext';
1327 + $other_id .= '-otext';
1328 +
1329 + return $other_id;
1784 1330 }
1785 1331
1786 - /**
1787 - * @param array|string $val
1788 - *
1789 - * @return array|string
1790 - */
1791 1332 public static function switch_field_ids( $val ) {
1792 1333 global $frm_duplicate_ids;
1793 1334 $replace = array();
1794 1335 $replace_with = array();
1795 -
1796 1336 foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1797 1337 $replace[] = '[if ' . $old . ']';
1798 1338 $replace_with[] = '[if ' . $new . ']';
1799 1339 $replace[] = '[if ' . $old . ' ';
@@ -1815,31 +1355,19 @@
1815 1355 $replace[] = 'field_id="' . $old . '"';
1816 1356 $replace_with[] = 'field_id="' . $new . '"';
1817 1357 $replace[] = 'field_id=\"' . $old . '\"';
1818 1358 $replace_with[] = 'field_id=\"' . $new . '\"';
1819 - // This covers conditional logic.
1820 - $replace[] = '_field":"' . $old . '","';
1821 - $replace_with[] = '_field":"' . $new . '","';
1822 1359 unset( $old, $new );
1823 - }//end foreach
1824 -
1825 - if ( ! is_array( $val ) ) {
1826 - return str_replace( $replace, $replace_with, $val );
1827 1360 }
1828 -
1829 - foreach ( $val as $k => $v ) {
1830 - if ( ! is_string( $v ) ) {
1831 - continue;
1361 + if ( is_array( $val ) ) {
1362 + foreach ( $val as $k => $v ) {
1363 + if ( is_string( $v ) ) {
1364 + $val[ $k ] = str_replace( $replace, $replace_with, $v );
1365 + unset( $k, $v );
1366 + }
1832 1367 }
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 );
1368 + } else {
1369 + $val = str_replace( $replace, $replace_with, $val );
1842 1370 }
1843 1371
1844 1372 return $val;
1845 1373 }
@@ -1844,48 +1372,17 @@
1844 1372 return $val;
1845 1373 }
1846 1374
1847 1375 /**
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 1376 * @since 4.0
1875 - *
1876 - * @return void
1877 1377 */
1878 1378 public static function bulk_options_overlay() {
1879 1379 $prepop = array();
1880 1380 self::get_bulk_prefilled_opts( $prepop, true );
1881 1381
1882 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php';
1382 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1883 1383 }
1884 1384
1885 - /**
1886 - * @return array
1887 - */
1888 1385 public static function get_us_states() {
1889 1386 $states = array(
1890 1387 'AL' => 'Alabama',
1891 1388 'AK' => 'Alaska',
@@ -1942,11 +1439,8 @@
1942 1439
1943 1440 return apply_filters( 'frm_us_states', $states );
1944 1441 }
1945 1442
1946 - /**
1947 - * @return array
1948 - */
1949 1443 public static function get_countries() {
1950 1444 $countries = array(
1951 1445 __( 'Afghanistan', 'formidable' ),
1952 1446 __( 'Aland Islands', 'formidable' ),
@@ -2211,15 +1705,12 @@
2211 1705 * @since 5.0.04 Add `$include_class` param.
2212 1706 *
2213 1707 * @param array $prepop Bulk options.
2214 1708 * @param array|false $include_class Include the class in the bulk options.
2215 - *
2216 - * @return void
2217 1709 */
2218 1710 public static function get_bulk_prefilled_opts( array &$prepop, $include_class = false ) {
2219 1711 // Countries.
2220 1712 $countries = self::get_countries();
2221 -
2222 1713 if ( $include_class ) {
2223 1714 $countries['class'] = 'frm-countries-opts';
2224 1715 }
2225 1716
@@ -2228,9 +1719,8 @@
2228 1719 // State abv.
2229 1720 $states = self::get_us_states();
2230 1721 $state_abv = array_keys( $states );
2231 1722 sort( $state_abv );
2232 -
2233 1723 if ( $include_class ) {
2234 1724 $state_abv['class'] = 'frm-state-abv-opts';
2235 1725 }
2236 1726
@@ -2238,9 +1728,8 @@
2238 1728
2239 1729 // States.
2240 1730 $states = array_values( $states );
2241 1731 sort( $states );
2242 -
2243 1732 if ( $include_class ) {
2244 1733 $states['class'] = 'frm-states-opts';
2245 1734 }
2246 1735
@@ -2257,9 +1746,8 @@
2257 1746 __( '55-64', 'formidable' ),
2258 1747 __( '65 or Above', 'formidable' ),
2259 1748 __( 'Prefer Not to Answer', 'formidable' ),
2260 1749 );
2261 -
2262 1750 if ( $include_class ) {
2263 1751 $ages['class'] = 'frm-age-opts';
2264 1752 }
2265 1753
@@ -2273,9 +1761,8 @@
2273 1761 __( 'Satisfied', 'formidable' ),
2274 1762 __( 'Very Satisfied', 'formidable' ),
2275 1763 __( 'N/A', 'formidable' ),
2276 1764 );
2277 -
2278 1765 if ( $include_class ) {
2279 1766 $satisfaction['class'] = 'frm-satisfaction-opts';
2280 1767 }
2281 1768
@@ -2289,9 +1776,8 @@
2289 1776 __( 'Important', 'formidable' ),
2290 1777 __( 'Very Important', 'formidable' ),
2291 1778 __( 'N/A', 'formidable' ),
2292 1779 );
2293 -
2294 1780 if ( $include_class ) {
2295 1781 $importance['class'] = 'frm-importance-opts';
2296 1782 }
2297 1783
@@ -2305,9 +1791,8 @@
2305 1791 __( 'Agree', 'formidable' ),
2306 1792 __( 'Strongly Agree', 'formidable' ),
2307 1793 __( 'N/A', 'formidable' ),
2308 1794 );
2309 -
2310 1795 if ( $include_class ) {
2311 1796 $agreement['class'] = 'frm-agreement-opts';
2312 1797 }
2313 1798
@@ -2321,9 +1806,8 @@
2321 1806 __( 'Likely', 'formidable' ),
2322 1807 __( 'Extremely Likely', 'formidable' ),
2323 1808 __( 'N/A', 'formidable' ),
2324 1809 );
2325 -
2326 1810 if ( $include_class ) {
2327 1811 $likely['class'] = 'frm-likely-opts';
2328 1812 }
2329 1813
@@ -2336,12 +1820,10 @@
2336 1820 * Display a field value selector
2337 1821 *
2338 1822 * @since 2.03.05
2339 1823 *
2340 - * @param int $selector_field_id
1824 + * @param int $selector_field_id
2341 1825 * @param array $selector_args
2342 - *
2343 - * @return void
2344 1826 */
2345 1827 public static function display_field_value_selector( $selector_field_id, $selector_args ) {
2346 1828 $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
2347 1829 $field_value_selector->display();
@@ -2356,9 +1838,9 @@
2356 1838 *
2357 1839 * @return array
2358 1840 */
2359 1841 public static function convert_field_object_to_flat_array( $field ) {
2360 - $field_options = is_array( $field->field_options ) ? $field->field_options : array();
1842 + $field_options = $field->field_options;
2361 1843 $field_array = get_object_vars( $field );
2362 1844 unset( $field_array['field_options'] );
2363 1845
2364 1846 return $field_array + $field_options;
@@ -2364,43 +1846,11 @@
2364 1846 return $field_array + $field_options;
2365 1847 }
2366 1848
2367 1849 /**
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 1850 * @since 4.04
2400 1851 *
2401 1852 * @param array $args
2402 - *
2403 1853 * @return void
2404 1854 */
2405 1855 public static function show_add_field_buttons( $args ) {
2406 1856 $field_key = $args['field_key'];
@@ -2408,32 +1858,34 @@
2408 1858 $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
2409 1859 $field_name = FrmFormsHelper::get_field_link_name( $field_type );
2410 1860 $field_label .= ' <span>' . $field_name . '</span>';
2411 1861
2412 - if ( ! empty( $field_type['is_new'] ) ) {
2413 - ob_start();
2414 - FrmAppHelper::show_pill_text();
2415 - $field_label .= ob_get_clean();
2416 - }
2417 -
2418 1862 // If the individual field isn't allowed, disable it.
2419 - $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1863 + $run_filter = true;
1864 + $single_no_allow = ' ';
1865 + $install_data = '';
1866 + $requires = '';
1867 + $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1868 + $has_show_upgrade_class = strpos( $field_type['icon'], ' frm_show_upgrade' );
1869 + $show_upgrade = $has_show_upgrade_class || false !== strpos( $args['no_allow_class'], 'frm_show_upgrade' );
2420 1870
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 );
1871 + if ( $has_show_upgrade_class ) {
1872 + $single_no_allow .= 'frm_show_upgrade';
1873 + $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
1874 + $run_filter = false;
1875 + if ( isset( $field_type['addon'] ) ) {
1876 + $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
1877 + if ( isset( $upgrading['url'] ) ) {
1878 + $install_data = json_encode( $upgrading );
1879 + }
1880 + $requires = FrmFormsHelper::get_plan_required( $upgrading );
1881 + } elseif ( isset( $field_type['require'] ) ) {
1882 + $requires = $field_type['require'];
1883 + }
1884 + }
2431 1885
2432 - $show_upgrade = $has_show_upgrade_class || $has_show_update_class || str_contains( $args['no_allow_class'], 'frm_show_upgrade' );
2433 1886 $upgrade_label = '';
2434 1887 $upgrade_message = '';
2435 -
2436 1888 if ( $show_upgrade ) {
2437 1889 /* translators: %s: Field name */
2438 1890 $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
2439 1891
@@ -2452,45 +1904,11 @@
2452 1904 'data-content' => $field_key,
2453 1905 'data-requires' => $requires,
2454 1906 );
2455 1907
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 ) {
1908 + if ( $upgrade_message ) {
2490 1909 $li_params['data-message'] = $upgrade_message;
2491 1910 }
2492 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
2493 1911 ?>
2494 1912 <li <?php FrmAppHelper::array_to_html_params( $li_params, true ); ?>>
2495 1913 <?php
2496 1914 if ( $run_filter ) {
@@ -2495,147 +1913,26 @@
2495 1913 <?php
2496 1914 if ( $run_filter ) {
2497 1915 $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
2498 1916 }
2499 -
2500 - FrmAppHelper::kses_echo( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) );
1917 + echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2501 1918 ?>
2502 1919 </li>
2503 1920 <?php
2504 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
2505 1921 }
2506 1922
2507 1923 /**
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 1924 * Shows Display format option.
2610 1925 *
2611 1926 * @since 5.0.04
2612 1927 *
2613 1928 * @param array $field Field data.
2614 - *
2615 - * @return void
2616 1929 */
2617 1930 public static function show_radio_display_format( $field ) {
2618 - $options = self::get_display_format_options( $field );
2619 - $args = self::get_display_format_args( $field, $options );
2620 -
2621 - include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php';
2622 - }
2623 -
2624 - /**
2625 - * Creates an array that contains variables used for display format options setting.
2626 - *
2627 - * @since 6.3.2
2628 - *
2629 - * @param array $field The field.
2630 - *
2631 - * @return array
2632 - */
2633 - public static function get_display_format_options( $field ) {
2634 1931 $options = array(
2635 1932 '0' => array(
2636 - 'text' => __( 'Simple', 'formidable' ),
2637 - 'svg' => 'frm_simple_radio',
1933 + 'text' => __( 'Simple', 'formidable' ),
1934 + 'svg' => 'frm_simple_radio',
2638 1935 ),
2639 1936 '1' => array(
2640 1937 'text' => __( 'Images', 'formidable' ),
2641 1938 'svg' => 'frm_image_as_option',
@@ -2640,9 +1937,9 @@
2640 1937 'text' => __( 'Images', 'formidable' ),
2641 1938 'svg' => 'frm_image_as_option',
2642 1939 'addon' => 'pro',
2643 1940 '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
1941 + '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 1942 'content' => 'image-options',
2646 1943 ),
2647 1944 'buttons' => array(
2648 1945 'text' => __( 'Buttons', 'formidable' ),
@@ -2653,12 +1950,8 @@
2653 1950 'content' => 'button-options',
2654 1951 ),
2655 1952 );
2656 1953
2657 - if ( 'product' === FrmField::get_field_type( $field ) ) {
2658 - unset( $options['buttons'] );
2659 - }
2660 -
2661 1954 /**
2662 1955 * Allows modifying the options of Display format setting of Radio field.
2663 1956 *
2664 1957 * @since 5.0.04
@@ -2663,11 +1956,14 @@
2663 1956 *
2664 1957 * @since 5.0.04
2665 1958 *
2666 1959 * @param array $options Options.
2667 - * @param array $field
2668 1960 */
2669 - return apply_filters( 'frm_' . $field['type'] . '_display_format_options', $options, $field );
1961 + $options = apply_filters( 'frm_radio_display_format_options', $options );
1962 +
1963 + $args = self::get_display_format_args( $field, $options );
1964 +
1965 + include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php';
2670 1966 }
2671 1967
2672 1968 /**
2673 1969 * Gets display format arguments to pass to the images_dropdown() method.
@@ -2675,12 +1971,11 @@
2675 1971 * @since 5.0.04
2676 1972 *
2677 1973 * @param array $field Field data.
2678 1974 * @param array $options Options array.
2679 - *
2680 1975 * @return array
2681 1976 */
2682 - public static function get_display_format_args( $field, $options ) {
1977 + private static function get_display_format_args( $field, $options ) {
2683 1978 $args = array(
2684 1979 'selected' => '0',
2685 1980 'options' => array(),
2686 1981 'name' => 'field_options[image_options_' . $field['id'] . ']',
@@ -2698,18 +1993,13 @@
2698 1993 *
2699 1994 * @param array $args Arguments.
2700 1995 * @param array $method_args The arguments from the method. Contains `field`, `options`.
2701 1996 */
2702 - return apply_filters( 'frm_' . $field['type'] . '_display_format_args', $args, compact( 'field', 'options' ) );
1997 + return apply_filters( 'frm_radio_display_format_args', $args, compact( 'field', 'options' ) );
2703 1998 }
2704 1999
2705 2000 /**
2706 2001 * @since 5.0.04
2707 - *
2708 - * @param array $options Options.
2709 - * @param array $args Arguments.
2710 - *
2711 - * @return void
2712 2002 */
2713 2003 private static function fill_image_setting_options( $options, &$args ) {
2714 2004 foreach ( $options as $key => $option ) {
2715 2005 $args['options'][ $key ] = $option;
@@ -2719,9 +2009,8 @@
2719 2009 }
2720 2010
2721 2011 unset( $args['options'][ $key ]['addon'] );
2722 2012 $fill = array( 'upgrade', 'message', 'content' );
2723 -
2724 2013 foreach ( $fill as $f ) {
2725 2014 unset( $args['options'][ $key ][ $f ], $f );
2726 2015 }
2727 2016 }
@@ -2729,10 +2018,8 @@
2729 2018
2730 2019 /**
2731 2020 * @since 5.0.04
2732 2021 *
2733 - * @param array $option Option.
2734 - *
2735 2022 * @return array
2736 2023 */
2737 2024 private static function fill_image_setting_addon_link( $option ) {
2738 2025 $custom_attrs = array(
@@ -2743,9 +2030,8 @@
2743 2030 // translators: Add-on name.
2744 2031 $custom_attrs['data-upgrade'] = sprintf( __( 'Formidable %s', 'formidable' ), ucwords( $option['addon'] ) );
2745 2032
2746 2033 $fill = array( 'upgrade', 'message', 'content' );
2747 -
2748 2034 foreach ( $fill as $f ) {
2749 2035 if ( isset( $option[ $f ] ) ) {
2750 2036 $custom_attrs[ 'data-' . $f ] = $option[ $f ];
2751 2037 }
@@ -2755,10 +2041,15 @@
2755 2041 return $custom_attrs;
2756 2042 }
2757 2043
2758 2044 $upgrading = FrmAddonsController::install_link( $option['addon'] );
2045 + if ( isset( $upgrading['url'] ) ) {
2046 + $install_data = wp_json_encode( $upgrading );
2047 + } else {
2048 + $install_data = '';
2049 + }
2759 2050
2760 - $custom_attrs['data-oneclick'] = isset( $upgrading['url'] ) ? wp_json_encode( $upgrading ) : '';
2051 + $custom_attrs['data-oneclick'] = $install_data;
2761 2052 $custom_attrs['data-requires'] = FrmFormsHelper::get_plan_required( $upgrading );
2762 2053
2763 2054 return $custom_attrs;
2764 2055 }
@@ -2764,16 +2055,14 @@
2764 2055 }
2765 2056
2766 2057 /**
2767 2058 * 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.
2059 + * Some types require unserializing an array (@see self::field_type_requires_unserialize).
2770 2060 *
2771 2061 * @since 6.2
2772 2062 *
2773 2063 * @param mixed $value
2774 2064 * @param string $field_type
2775 - *
2776 2065 * @return void
2777 2066 */
2778 2067 public static function prepare_field_value( &$value, $field_type ) {
2779 2068 $field_object = FrmFieldFactory::get_field_type( $field_type );
@@ -2780,221 +2069,95 @@
2780 2069 $value = $field_object->maybe_decode_value( $value );
2781 2070 }
2782 2071
2783 2072 /**
2784 - * @since 6.8
2785 - *
2786 - * @param int|string $form_id
2787 - * @param array $field_ids If this is not empty, the results will be filtered by field id.
2788 - *
2789 - * @return array
2073 + * @deprecated 4.0
2790 2074 */
2791 - public static function get_draft_field_results( $form_id, $field_ids = array() ) {
2792 - if ( FrmAppHelper::pro_is_installed() ) {
2793 - $child_form_ids = FrmDb::get_col( 'frm_forms', array( 'parent_form_id' => $form_id ) );
2794 - $form_ids = array_merge( array( $form_id ), $child_form_ids );
2795 - } else {
2796 - $form_ids = array( $form_id );
2075 + public static function show_icon_link_js( $atts ) {
2076 + _deprecated_function( __METHOD__, '4.0' );
2077 + $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
2078 + if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
2079 + $atts['icon'] .= 'frm_hidden ';
2797 2080 }
2081 + 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>';
2082 + }
2798 2083
2799 - $where = array(
2800 - 'form_id' => $form_ids,
2801 - // Do a soft check for fields that look like drafts only.
2802 - 'field_options LIKE' => 's:5:"draft";i:1;',
2803 - );
2084 + /**
2085 + * @deprecated 4.0
2086 + */
2087 + public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
2088 + _deprecated_function( __METHOD__, '4.0' );
2089 + }
2804 2090
2805 - if ( $field_ids ) {
2806 - $where['id'] = $field_ids;
2807 - }
2808 -
2809 - $rows = FrmDb::get_results( 'frm_fields', $where, 'id, field_options' );
2810 -
2811 - return array_filter(
2812 - $rows,
2813 - function ( $row ) {
2814 - FrmAppHelper::unserialize_or_decode( $row->field_options );
2815 - return is_array( $row->field_options ) && ! empty( $row->field_options['draft'] );
2816 - }
2817 - );
2091 + /**
2092 + * @deprecated 4.0
2093 + */
2094 + public static function clear_on_focus_html( $field, $display, $id = '' ) {
2095 + _deprecated_function( __METHOD__, '4.0' );
2818 2096 }
2819 2097
2820 2098 /**
2821 - * This is called when loading the form builder.
2822 - * Any unsaved draft fields get added to a hidden draft_fields input on load.
2823 - *
2824 - * @since 6.8
2825 - *
2826 - * @param int|string $form_id
2827 - *
2828 - * @return array
2099 + * @deprecated 4.0
2829 2100 */
2830 - public static function get_all_draft_field_ids( $form_id ) {
2831 - $draft_field_rows = self::get_draft_field_results( $form_id );
2832 - return wp_list_pluck( $draft_field_rows, 'id' );
2101 + public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
2102 + _deprecated_function( __METHOD__, '4.0' );
2833 2103 }
2834 2104
2835 2105 /**
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
2106 + * @deprecated 3.0
2107 + * @codeCoverageIgnore
2844 2108 */
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';
2854 - }
2855 -
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 - );
2866 -
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 - }
2879 -
2880 - if ( empty( $attributes['data-fid'] ) ) {
2881 - unset( $data['plugin-status'] );
2882 -
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';
2109 + public static function display_recaptcha() {
2110 + _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
2889 2111 }
2890 2112
2891 2113 /**
2892 - * Get AI generate options button class.
2893 - *
2894 - * @since 6.24
2895 - *
2896 - * @return string Button class.
2114 + * @deprecated 3.0
2115 + * @codeCoverageIgnore
2897 2116 */
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 - );
2117 + public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
2118 + FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
2918 2119 }
2919 2120
2920 2121 /**
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
2122 + * @deprecated 3.0
2123 + * @codeCoverageIgnore
2929 2124 */
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 );
2125 + public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
2126 + return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
2939 2127 }
2940 2128
2941 2129 /**
2942 - * @since 6.28
2130 + * @deprecated 3.0
2131 + * @codeCoverageIgnore
2943 2132 *
2944 - * @param array $field
2133 + * @param string $html
2134 + * @param array $field
2135 + * @param array $errors
2136 + * @param object|false $form
2137 + * @param array $args
2945 2138 *
2946 - * @return bool
2139 + * @return string
2947 2140 */
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 );
2141 + public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
2142 + return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args );
2956 2143 }
2957 2144
2958 2145 /**
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
2146 + * @deprecated 3.0
2147 + * @codeCoverageIgnore
2968 2148 */
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 );
2149 + public static function get_default_field_opts( $type, $field = null, $limit = false ) {
2150 + return FrmDeprecated::get_default_field_opts( $type, $field, $limit );
2979 2151 }
2980 2152
2981 2153 /**
2982 - * @since 6.28
2154 + * @deprecated 2.02.07 This is still referenced in the Highrise add on as of v1.06.
2155 + * @codeCoverageIgnore
2983 2156 *
2984 - * @param array $field
2985 - * @param string $choice_key
2986 - *
2987 - * @return void
2157 + * @param array $args
2158 + * @return string
2988 2159 */
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 );
2160 + public static function dropdown_categories( $args ) {
2161 + return FrmDeprecated::dropdown_categories( $args );
2999 2162 }
3000 2163 }