PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24.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/FrmEntriesHelper.php +137 -223 6.31 → 6.24.1 View file →
@@ -8,9 +8,8 @@
8 8 /**
9 9 * "Submitted" entry status.
10 10 *
11 11 * @since 6.4.2
12 - *
13 12 * @var int
14 13 */
15 14 const SUBMITTED_ENTRY_STATUS = 0;
16 15
@@ -17,21 +16,12 @@
17 16 /**
18 17 * "Draft" entry status.
19 18 *
20 19 * @since 6.4.2
21 - *
22 20 * @var int
23 21 */
24 22 const DRAFT_ENTRY_STATUS = 1;
25 23
26 - /**
27 - * @param mixed $fields
28 - * @param object|string $form
29 - * @param bool $reset
30 - * @param array $args
31 - *
32 - * @return array
33 - */
34 24 public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
35 25 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
36 26
37 27 $values = array(
@@ -40,10 +30,9 @@
40 30 'item_key' => '',
41 31 );
42 32
43 33 $values['fields'] = array();
44 -
45 - if ( ! $fields ) {
34 + if ( empty( $fields ) ) {
46 35 return apply_filters( 'frm_setup_new_entry', $values );
47 36 }
48 37
49 38 foreach ( (array) $fields as $field ) {
@@ -48,15 +37,16 @@
48 37
49 38 foreach ( (array) $fields as $field ) {
50 39 $original_default = $field->default_value;
51 40 self::prepare_field_default_value( $field );
52 - $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
41 + $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
42 +
53 43 $field_array = FrmAppHelper::start_field_array( $field );
54 44 $field_array['value'] = $new_value;
55 45 $field_array['type'] = apply_filters( 'frm_field_type', $field->type, $field, $new_value );
56 - $field_array['parent_form_id'] = $args['parent_form_id'] ?? $field->form_id;
46 + $field_array['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
57 47 $field_array['reset_value'] = $reset;
58 - $field_array['in_embed_form'] = $args['in_embed_form'] ?? '0';
48 + $field_array['in_embed_form'] = isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0';
59 49 $field_array['original_default'] = $original_default;
60 50
61 51 FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args );
62 52
@@ -73,9 +63,8 @@
73 63 }
74 64 }//end foreach
75 65
76 66 FrmAppHelper::unserialize_or_decode( $form->options );
77 -
78 67 if ( is_array( $form->options ) ) {
79 68 $values = array_merge( $values, $form->options );
80 69 }
81 70
@@ -90,10 +79,8 @@
90 79 /**
91 80 * @since 2.05
92 81 *
93 82 * @param object $field
94 - *
95 - * @return void
96 83 */
97 84 private static function prepare_field_default_value( &$field ) {
98 85 // If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array.
99 86 $return_array = FrmField::is_field_with_multiple_values( $field );
@@ -118,9 +105,9 @@
118 105 * @param object $field - this is passed by reference since it is an object.
119 106 * @param bool $reset
120 107 * @param array $args
121 108 *
122 - * @return array|string New value.
109 + * @return array|string $new_value
123 110 */
124 111 private static function get_field_value_for_new_entry( $field, $reset, $args ) {
125 112 $new_value = $field->default_value;
126 113
@@ -128,9 +115,9 @@
128 115 self::get_posted_value( $field, $new_value, $args );
129 116 }
130 117
131 118 if ( ! is_array( $new_value ) ) {
132 - return str_replace( '"', '"', $new_value );
119 + $new_value = str_replace( '"', '"', $new_value );
133 120 }
134 121
135 122 return $new_value;
136 123 }
@@ -142,36 +129,26 @@
142 129 *
143 130 * @param object $field
144 131 * @param array $args
145 132 *
146 - * @return bool True if a value is posted.
133 + * @return bool $value_is_posted
147 134 */
148 135 public static function value_is_posted( $field, $args ) {
149 136 $value_is_posted = false;
150 -
151 - if ( ! $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
152 - return $value_is_posted;
153 - }
154 -
155 - $repeating = ! empty( $args['repeating'] );
156 -
157 - if ( $repeating ) {
158 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
137 + if ( $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
138 + $repeating = isset( $args['repeating'] ) && $args['repeating'];
139 + if ( $repeating ) {
140 + if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
141 + $value_is_posted = true;
142 + }
143 + } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
159 144 $value_is_posted = true;
160 145 }
161 - } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
162 - $value_is_posted = true;
163 146 }
164 147
165 148 return $value_is_posted;
166 149 }
167 150
168 - /**
169 - * @param array $values
170 - * @param object $record
171 - *
172 - * @return array
173 - */
174 151 public static function setup_edit_vars( $values, $record ) {
175 152 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
176 153
177 154 $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
@@ -180,22 +157,16 @@
180 157
181 158 return apply_filters( 'frm_setup_edit_entry_vars', $values, $record );
182 159 }
183 160
184 - /**
185 - * @param string $message
186 - * @param array $atts
187 - *
188 - * @return string
189 - */
190 161 public static function replace_default_message( $message, $atts ) {
191 - if ( ! str_contains( $message, '[default-message' ) &&
192 - ! str_contains( $message, '[default_message' ) &&
193 - $message ) {
162 + if ( strpos( $message, '[default-message' ) === false &&
163 + strpos( $message, '[default_message' ) === false &&
164 + ! empty( $message ) ) {
194 165 return $message;
195 166 }
196 167
197 - if ( ! $message ) {
168 + if ( empty( $message ) ) {
198 169 $message = '[default-message]';
199 170 }
200 171
201 172 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
@@ -200,12 +171,17 @@
200 171
201 172 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
202 173
203 174 foreach ( $shortcodes[0] as $short_key => $tag ) {
204 - $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
205 - $this_atts = $add_atts ? array_merge( $atts, $add_atts ) : $atts;
206 - $default = FrmEntriesController::show_entry_shortcode( $this_atts );
175 + $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
176 + if ( ! empty( $add_atts ) ) {
177 + $this_atts = array_merge( $atts, $add_atts );
178 + } else {
179 + $this_atts = $atts;
180 + }
207 181
182 + $default = FrmEntriesController::show_entry_shortcode( $this_atts );
183 +
208 184 // Add the default message.
209 185 $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
210 186 }
211 187
@@ -215,25 +191,22 @@
215 191 /**
216 192 * @param stdClass $entry
217 193 * @param stdClass $field
218 194 * @param array $atts
219 - *
220 195 * @return string
221 196 */
222 197 public static function prepare_display_value( $entry, $field, $atts ) {
223 - $field_value = $entry->metas[ $field->id ] ?? false;
198 + $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
224 199
225 200 if ( FrmAppHelper::pro_is_installed() ) {
226 - $empty = ! $field_value;
201 + $empty = empty( $field_value );
227 202 FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
228 -
229 - if ( $empty && $field_value ) {
203 + if ( $empty && ! empty( $field_value ) ) {
230 204 // We've got an entry id, so switch it to a value.
231 205 $atts['force_id'] = true;
232 206 }
233 207 }
234 208
235 - // phpcs:ignore Universal.Operators.StrictComparisons
236 209 if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) {
237 210 return self::display_value( $field_value, $field, $atts );
238 211 }
239 212
@@ -239,20 +212,19 @@
239 212
240 213 if ( ! FrmAppHelper::pro_is_installed() ) {
241 214 return '';
242 215 }
243 -
244 216 if ( is_callable( 'FrmProEntriesHelper::prepare_child_display_value' ) ) {
245 217 return FrmProEntriesHelper::prepare_child_display_value( $entry, $field, $atts );
246 218 }
247 219
248 220 // This is an embedded form.
249 - if ( str_starts_with( $atts['embedded_field_id'], 'form' ) ) {
221 + if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) {
250 222 // This is a repeating section.
251 223 $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ), '', '', true );
252 224 } else {
253 225 // Get all values for this field.
254 - $child_values = $entry->metas[ $atts['embedded_field_id'] ] ?? false;
226 + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
255 227
256 228 if ( $child_values ) {
257 229 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
258 230 }
@@ -257,14 +229,14 @@
257 229 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
258 230 }
259 231 }
260 232
233 + $field_value = array();
234 +
261 235 if ( empty( $child_entries ) ) {
262 236 return '';
263 237 }
264 238
265 - $field_value = array();
266 -
267 239 foreach ( $child_entries as $child_entry ) {
268 240 $atts['item_id'] = $child_entry->id;
269 241 $atts['post_id'] = $child_entry->post_id;
270 242
@@ -271,9 +243,9 @@
271 243 // Fet the value for this field -- check for post values as well.
272 244 $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field );
273 245
274 246 if ( $entry_val || '0' === $entry_val ) {
275 - // For each entry get display_value.
247 + // foreach entry get display_value.
276 248 $field_value[] = self::display_value( $entry_val, $field, $atts );
277 249 }
278 250
279 251 unset( $child_entry );
@@ -279,13 +251,11 @@
279 251 unset( $child_entry );
280 252 }
281 253
282 254 $sep = ', ';
283 -
284 - if ( str_contains( implode( ' ', $field_value ), '<img' ) ) {
255 + if ( strpos( implode( ' ', $field_value ), '<img' ) !== false ) {
285 256 $sep = '<br/>';
286 257 }
287 -
288 258 $val = implode( $sep, $field_value );
289 259
290 260 return FrmAppHelper::kses( $val, 'all' );
291 261 }
@@ -299,8 +269,9 @@
299 269 *
300 270 * @return string
301 271 */
302 272 public static function display_value( $value, $field, $atts = array() ) {
273 +
303 274 $defaults = array(
304 275 'type' => '',
305 276 'html' => false,
306 277 'show_filename' => true,
@@ -336,15 +307,14 @@
336 307
337 308 if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] === 'tag' ) ) {
338 309 $atts['pre_truncate'] = $atts['truncate'];
339 310 $atts['truncate'] = true;
340 - $atts['exclude_cat'] = $field->field_options['exclude_cat'] ?? 0;
311 + $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
341 312
342 313 $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts );
343 314 $atts['truncate'] = $atts['pre_truncate'];
344 315 }
345 316
346 - // phpcs:ignore Universal.Operators.StrictComparisons
347 317 if ( $value == '' ) {
348 318 return $value;
349 319 }
350 320
@@ -353,9 +323,8 @@
353 323
354 324 $value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts );
355 325 $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) );
356 326
357 - // phpcs:ignore Universal.Operators.StrictComparisons
358 327 if ( $value == $unfiltered_value ) {
359 328 $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
360 329 }
361 330
@@ -369,21 +338,13 @@
369 338
370 339 return apply_filters( 'frm_display_value', $value, $field, $atts );
371 340 }
372 341
373 - /**
374 - * @param object $field
375 - * @param mixed $value
376 - * @param array $args
377 - *
378 - * @return void
379 - */
380 342 public static function set_posted_value( $field, $value, $args ) {
381 343 // If validating a field with "other" opt, set back to prev value now.
382 344 if ( ! empty( $args['other'] ) ) {
383 345 $value = $args['temp_value'];
384 346 }
385 -
386 347 if ( empty( $args['parent_field_id'] ) ) {
387 348 $_POST['item_meta'][ $field->id ] = $value;
388 349 } else {
389 350 self::set_parent_field_posted_value( $field, $value, $args );
@@ -393,18 +354,12 @@
393 354 /**
394 355 * Init arrays if necessary, else we get fatal error.
395 356 *
396 357 * @since 4.01
397 - *
398 - * @param object $field Field object.
399 - * @param mixed $value Value to set.
400 - * @param array $args Additional arguments.
401 - *
402 - * @return void
403 358 */
404 359 private static function set_parent_field_posted_value( $field, $value, $args ) {
405 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
406 - if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) || ! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
360 + if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
361 + if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) || ! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
407 362 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
408 363 }
409 364 } else {
410 365 // All of the section was probably removed.
@@ -414,27 +369,15 @@
414 369
415 370 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; // phpcs:ignore WordPress.Security.NonceVerification.Missing
416 371 }
417 372
418 - /**
419 - * @param array|int|object|string $field
420 - * @param mixed $value
421 - * @param array $args
422 - *
423 - * @return void
424 - */
425 373 public static function get_posted_value( $field, &$value, $args ) {
426 374 if ( is_array( $field ) ) {
427 375 $field_id = $field['id'];
428 376 $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
429 377 } elseif ( is_object( $field ) ) {
430 - $field_id = $field->id;
431 -
432 - if ( 'hidden' === $field->type && ! empty( $field->field_options['original_type'] ) ) {
433 - $field_obj = FrmFieldFactory::get_field_type( $field->field_options['original_type'], $field );
434 - } else {
435 - $field_obj = FrmFieldFactory::get_field_object( $field );
436 - }
378 + $field_id = $field->id;
379 + $field_obj = FrmFieldFactory::get_field_object( $field );
437 380 } elseif ( is_numeric( $field ) ) {
438 381 $field_id = $field;
439 382 $field_obj = FrmFieldFactory::get_field_object( $field );
440 383 } else {
@@ -449,21 +392,15 @@
449 392 }
450 393
451 394 /**
452 395 * @since 4.02.04
453 - * @since 6.29 This is public.
454 - *
455 - * @param int|string $field_id Field ID.
456 - * @param array $args Additional arguments.
457 - *
458 - * @return mixed
459 396 */
460 - public static function get_posted_meta( $field_id, $args ) {
397 + private static function get_posted_meta( $field_id, $args ) {
461 398 if ( empty( $args['parent_field_id'] ) ) {
462 399 // Sanitizing is done next.
463 - $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
400 + $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
464 401 } else {
465 - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
402 + $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
466 403 }
467 404 return $value;
468 405 }
469 406
@@ -471,17 +408,14 @@
471 408 * Check if field has an "Other" option and if any other values are posted
472 409 *
473 410 * @since 2.0
474 411 *
475 - * @param object $field Field object.
476 - * @param array|string $value Field value, passed by reference.
477 - * @param array $args Arguments array, passed by reference.
478 - *
479 - * @return void
412 + * @param object $field
413 + * @param array|string $value
414 + * @param array $args
480 415 */
481 416 public static function maybe_set_other_validation( $field, &$value, &$args ) {
482 417 $args['other'] = false;
483 -
484 418 if ( ! $value || ! FrmAppHelper::pro_is_installed() ) {
485 419 return;
486 420 }
487 421
@@ -495,22 +429,21 @@
495 429 // Get other value for fields in repeating section.
496 430 self::set_other_repeating_vals( $field, $value, $args );
497 431
498 432 // Check if there are any posted "Other" values.
499 - if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
500 - return;
501 - }
433 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
502 434
503 - // Save original value.
504 - $args['temp_value'] = $value;
505 - $args['other'] = true;
435 + // Save original value.
436 + $args['temp_value'] = $value;
437 + $args['other'] = true;
506 438
507 - // Sanitizing is done next.
508 - $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
509 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
439 + // Sanitizing is done next.
440 + $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
441 + FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
510 442
511 - // Set the validation value now
512 - self::set_other_validation_val( $value, $other_vals, $field, $args );
443 + // Set the validation value now
444 + self::set_other_validation_val( $value, $other_vals, $field, $args );
445 + }
513 446 }
514 447
515 448 /**
516 449 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
@@ -516,13 +449,11 @@
516 449 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
517 450 *
518 451 * @since 2.0
519 452 *
520 - * @param object $field Field object.
521 - * @param array|string $value Field value, passed by reference.
522 - * @param array $args Arguments array, passed by reference.
523 - *
524 - * @return void
453 + * @param object $field
454 + * @param array|string $value
455 + * @param array $args
525 456 */
526 457 public static function set_other_repeating_vals( $field, &$value, &$args ) {
527 458 if ( ! $args['parent_field_id'] ) {
528 459 return;
@@ -528,20 +459,19 @@
528 459 return;
529 460 }
530 461
531 462 // Check if there are any other posted "other" values for this field.
532 - if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
533 - return;
534 - }
463 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
464 + // Save original value
465 + $args['temp_value'] = $value;
466 + $args['other'] = true;
535 467
536 - // Save original value
537 - $args['temp_value'] = $value;
538 - $args['other'] = true;
539 - $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
540 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
468 + $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
469 + FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
541 470
542 - // Set the validation value now.
543 - self::set_other_validation_val( $value, $other_vals, $field, $args );
471 + // Set the validation value now.
472 + self::set_other_validation_val( $value, $other_vals, $field, $args );
473 + }
544 474 }
545 475
546 476 /**
547 477 * Modify value used for validation
@@ -555,13 +485,11 @@
555 485 * @param array|string $value
556 486 * @param array|string $other_vals (usually of posted values).
557 487 * @param object $field
558 488 * @param array $args
559 - *
560 - * @return void
561 489 */
562 490 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
563 - // Checkboxes.
491 + // Checkboxes and multi-select dropdowns.
564 492 if ( is_array( $value ) && $field->type === 'checkbox' ) {
565 493 // Combine "Other" values with checked values. "Other" values will override checked box values.
566 494 foreach ( $other_vals as $k => $v ) {
567 495 if ( isset( $value[ $k ] ) && trim( $v ) === '' ) {
@@ -570,43 +498,39 @@
570 498 break;
571 499 }
572 500 }
573 501
574 - if ( is_array( $value ) && $value ) {
502 + if ( is_array( $value ) && ! empty( $value ) ) {
575 503 $value = array_merge( $value, $other_vals );
576 504 }
505 + } else {
506 + // Radio and dropdowns.
507 + $other_key = array_filter( array_keys( $field->options ), 'is_string' );
508 + $other_key = reset( $other_key );
577 509
578 - return;
579 - }
510 + // Multi-select dropdown.
511 + if ( is_array( $value ) ) {
512 + $o_key = array_search( $field->options[ $other_key ], $value );
580 513
581 - // Radio and dropdowns.
582 - $other_key = array_filter( array_keys( $field->options ), 'is_string' );
583 - $other_key = reset( $other_key );
514 + if ( $o_key !== false ) {
515 + // Modify the original value so other key will be preserved.
516 + $value[ $other_key ] = $value[ $o_key ];
584 517
585 - // Multi-select dropdown.
586 - if ( is_array( $value ) ) {
587 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
588 - $o_key = array_search( $field->options[ $other_key ], $value );
518 + // By default, the array keys will be numeric for multi-select dropdowns.
519 + // If going backwards and forwards between pages, the array key will match the other key.
520 + if ( $o_key !== $other_key ) {
521 + unset( $value[ $o_key ] );
522 + }
589 523
590 - if ( $o_key !== false ) {
591 - // Modify the original value so other key will be preserved.
592 - $value[ $other_key ] = $value[ $o_key ];
593 -
594 - // By default, the array keys will be numeric for multi-select dropdowns.
595 - // If going backwards and forwards between pages, the array key will match the other key.
596 - if ( $o_key !== $other_key ) {
597 - unset( $value[ $o_key ] );
524 + $args['temp_value'] = $value;
525 + $value[ $other_key ] = reset( $other_vals );
526 + if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
527 + unset( $value[ $other_key ] );
528 + }
598 529 }
599 -
600 - $args['temp_value'] = $value;
601 - $value[ $other_key ] = reset( $other_vals );
602 -
603 - if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
604 - unset( $value[ $other_key ] );
605 - }
606 - }
607 - } elseif ( $field->options[ $other_key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
608 - $value = $other_vals;
530 + } elseif ( $field->options[ $other_key ] == $value ) {
531 + $value = $other_vals;
532 + }//end if
609 533 }//end if
610 534 }
611 535
612 536 /**
@@ -612,16 +536,14 @@
612 536 /**
613 537 * Add submitted values to a string for spam checking.
614 538 *
615 539 * @param array $values
616 - *
617 540 * @return string
618 541 */
619 542 public static function entry_array_to_string( $values ) {
620 543 $content = '';
621 -
622 544 foreach ( $values['item_meta'] as $val ) {
623 - if ( $content !== '' ) {
545 + if ( $content != '' ) {
624 546 $content .= "\n\n";
625 547 }
626 548
627 549 if ( is_array( $val ) ) {
@@ -668,14 +590,14 @@
668 590 'Firefox' => 'Mozilla Firefox',
669 591 );
670 592
671 593 // Next get the name of the useragent yes separately and for good reason.
672 - if ( str_contains( $u_agent, 'MSIE' ) && ! str_contains( $u_agent, 'Opera' ) ) {
594 + if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
673 595 $bname = 'Internet Explorer';
674 596 $ub = 'MSIE';
675 597 } else {
676 598 foreach ( $agent_options as $agent_key => $agent_name ) {
677 - if ( str_contains( $u_agent, $agent_key ) ) {
599 + if ( strpos( $u_agent, $agent_key ) !== false ) {
678 600 $bname = $agent_name;
679 601 $ub = $agent_key;
680 602 break;
681 603 }
@@ -681,21 +603,25 @@
681 603 }
682 604 }
683 605 }
684 606
685 - // Finally get the correct version number
607 + // finally get the correct version number
686 608 $known = array( 'Version', $ub, 'other' );
687 - $pattern = '#(?<browser>' . implode( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
609 + $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
688 610 // Get the matching numbers.
689 611 preg_match_all( $pattern, $u_agent, $matches );
690 612
691 - // See how many we have
613 + // see how many we have
692 614 $i = count( $matches['browser'] );
693 615
694 616 if ( $i > 1 ) {
695 617 // We will have two since we are not using 'other' argument yet
696 - // See if version is before or after the name.
697 - $version = strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ? $matches['version'][0] : $matches['version'][1];
618 + // see if version is before or after the name.
619 + if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
620 + $version = $matches['version'][0];
621 + } else {
622 + $version = $matches['version'][1];
623 + }
698 624 } elseif ( $i === 1 ) {
699 625 $version = $matches['version'][0];
700 626 } else {
701 627 $version = '';
@@ -700,10 +626,10 @@
700 626 } else {
701 627 $version = '';
702 628 }
703 629
704 - // Check if we have a number
705 - if ( $version === '' ) {
630 + // check if we have a number
631 + if ( $version == '' ) {
706 632 $version = '?';
707 633 }
708 634
709 635 return $bname . ' ' . $version . ' / ' . $platform;
@@ -710,19 +636,14 @@
710 636 }
711 637
712 638 /**
713 639 * @since 3.0
714 - *
715 - * @param array $atts Action dropdown attributes.
716 - *
717 - * @return void
718 640 */
719 641 public static function actions_dropdown( $atts ) {
720 - $id = $atts['id'] ?? FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
642 + $id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
721 643 $links = self::get_action_links( $id, $atts['entry'] );
722 644
723 645 foreach ( $links as $link ) {
724 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
725 646 ?>
726 647 <div class="misc-pub-section">
727 648 <a href="<?php echo esc_url( $link['url'] ); ?>"
728 649 <?php
@@ -730,13 +651,11 @@
730 651 foreach ( $link['data'] as $data => $value ) {
731 652 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
732 653 }
733 654 }
734 -
735 655 if ( isset( $link['class'] ) ) {
736 656 echo 'class="' . esc_attr( $link['class'] ) . '" ';
737 657 }
738 -
739 658 if ( isset( $link['id'] ) ) {
740 659 echo 'id="' . esc_attr( $link['id'] ) . '" ';
741 660 }
742 661 ?>
@@ -745,19 +664,13 @@
745 664 <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
746 665 </a>
747 666 </div>
748 667 <?php
749 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
750 668 }//end foreach
751 669 }
752 670
753 671 /**
754 672 * @since 3.0
755 - *
756 - * @param int $id Entry ID.
757 - * @param array|object $entry Entry object.
758 - *
759 - * @return array
760 673 */
761 674 private static function get_action_links( $id, $entry ) {
762 675 $page = FrmAppHelper::get_param( 'frm_action' );
763 676 $actions = array();
@@ -765,9 +678,9 @@
765 678 if ( $page !== 'show' ) {
766 679 $actions['frm_view'] = array(
767 680 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
768 681 'label' => __( 'View Entry', 'formidable' ),
769 - 'icon' => 'frmfont frm_save_icon',
682 + 'icon' => 'frm_icon_font frm_save_icon',
770 683 );
771 684 }
772 685
773 686 if ( current_user_can( 'frm_delete_entries' ) ) {
@@ -773,9 +686,9 @@
773 686 if ( current_user_can( 'frm_delete_entries' ) ) {
774 687 $actions['frm_delete'] = array(
775 688 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ) ),
776 689 'label' => __( 'Delete Entry', 'formidable' ),
777 - 'icon' => 'frmfont frm_delete_icon',
690 + 'icon' => 'frm_icon_font frm_delete_icon',
778 691 'data' => array(
779 692 'frmverify' => __( 'Permanently delete this entry?', 'formidable' ),
780 693 'frmverify-btn' => 'frm-button-red',
781 694 ),
@@ -788,9 +701,9 @@
788 701 'label' => __( 'Print Entry', 'formidable' ),
789 702 'data' => array(
790 703 'frmprint' => '1',
791 704 ),
792 - 'icon' => 'frmfont frm_printer_icon',
705 + 'icon' => 'frm_icon_font frm_printer_icon',
793 706 );
794 707 }
795 708
796 709 $actions['frm_resend'] = array(
@@ -801,18 +714,18 @@
801 714 'upgrade' => __( 'Resend Emails', 'formidable' ),
802 715 'medium' => 'resend-email',
803 716 'content' => 'entry',
804 717 ),
805 - 'icon' => 'frmfont frm_email_icon',
718 + 'icon' => 'frm_icon_font frm_email_icon',
806 719 );
807 720
808 - if ( ! function_exists( 'frm_pdfs_autoloader' ) ) {
721 + if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) {
809 722 $actions['frm_download_pdf'] = array(
810 723 'url' => '#',
811 724 'label' => __( 'Download as PDF', 'formidable' ),
812 725 'class' => 'frm_noallow',
813 726 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ),
814 - 'icon' => 'frmfont frm_download_icon',
727 + 'icon' => 'frm_icon_font frm_download_icon',
815 728 );
816 729 }
817 730
818 731 $actions['frm_edit'] = array(
@@ -823,9 +736,9 @@
823 736 'upgrade' => __( 'Entry edits', 'formidable' ),
824 737 'medium' => 'edit-entries',
825 738 'content' => 'entry',
826 739 ),
827 - 'icon' => 'frmfont frm_pencil_icon',
740 + 'icon' => 'frm_icon_font frm_pencil_icon',
828 741 );
829 742
830 743 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
831 744 }
@@ -833,9 +746,8 @@
833 746 /**
834 747 * Gets data attributes for PDFs addon upgrade link.
835 748 *
836 749 * @param string $medium The source of the upgrade link used for analytics data.
837 - *
838 750 * @return array
839 751 */
840 752 private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
841 753 $data = array(
@@ -845,9 +757,8 @@
845 757 'medium' => $medium,
846 758 );
847 759
848 760 $upgrading = FrmAddonsController::install_link( 'pdfs' );
849 -
850 761 if ( isset( $upgrading['url'] ) ) {
851 762 $data['oneclick'] = json_encode( $upgrading );
852 763 } else {
853 764 $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
@@ -859,9 +770,8 @@
859 770 /**
860 771 * @since 5.0.15
861 772 *
862 773 * @param int|string $entry_id
863 - *
864 774 * @return void
865 775 */
866 776 public static function maybe_render_captcha_score( $entry_id ) {
867 777 $query = array(
@@ -868,20 +778,17 @@
868 778 'item_id' => (int) $entry_id,
869 779 'field_id' => 0,
870 780 );
871 781 $metas_without_a_field = (array) FrmEntryMeta::getAll( $query, ' ORDER BY it.created_at DESC', '', true );
872 -
873 782 foreach ( $metas_without_a_field as $meta ) {
874 - if ( empty( $meta->meta_value['captcha_score'] ) ) {
875 - continue;
783 + if ( ! empty( $meta->meta_value['captcha_score'] ) ) {
784 + echo '<div class="misc-pub-section">';
785 + FrmAppHelper::icon_by_class( 'frm_icon_font frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
786 + echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
787 + echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
788 + echo '</div>';
789 + return;
876 790 }
877 -
878 - echo '<div class="misc-pub-section">';
879 - FrmAppHelper::icon_by_class( 'frmfont frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
880 - echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
881 - echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
882 - echo '</div>';
883 - return;
884 791 }
885 792 }
886 793
887 794 /**
@@ -893,13 +800,15 @@
893 800 *
894 801 * @return int
895 802 */
896 803 public static function get_entry_status( $status ) {
897 - if ( array_key_exists( $status, self::get_entry_statuses() ) ) {
804 + $statuses = self::get_entry_statuses();
805 +
806 + if ( array_key_exists( $status, $statuses ) ) {
898 807 return $status;
899 808 }
900 809
901 - if ( ! $status ) {
810 + if ( empty( $status ) ) {
902 811 // If the status is empty, let's default to 0.
903 812 return self::SUBMITTED_ENTRY_STATUS;
904 813 }
905 814
@@ -916,9 +825,11 @@
916 825 *
917 826 * @return string
918 827 */
919 828 public static function get_entry_status_label( $status ) {
920 - return self::get_entry_statuses()[ self::get_entry_status( $status ) ];
829 + $statuses = self::get_entry_statuses();
830 +
831 + return $statuses[ self::get_entry_status( $status ) ];
921 832 }
922 833
923 834 /**
924 835 * Get all entry statuses.
@@ -928,8 +839,9 @@
928 839 *
929 840 * @return array<string>
930 841 */
931 842 public static function get_entry_statuses() {
843 +
932 844 $default_entry_statuses = array(
933 845 self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ),
934 846 self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ),
935 847 );
@@ -950,9 +862,11 @@
950 862 _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' );
951 863 $extended_entry_status = array();
952 864 }
953 865
954 - return array_replace( $default_entry_statuses, $extended_entry_status );
866 + $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status );
867 +
868 + return $existing_entry_statuses;
955 869 }
956 870
957 871 /**
958 872 * @since 6.17
@@ -959,9 +873,10 @@
959 873 *
960 874 * @return int
961 875 */
962 876 public static function get_visible_unread_inbox_count() {
963 - if ( ! in_array( FrmAppHelper::get_menu_name(), array( 'Formidable', 'Forms' ), true ) ) {
877 + $menu_name = FrmAppHelper::get_menu_name();
878 + if ( ! in_array( $menu_name, array( 'Formidable', 'Forms' ), true ) ) {
964 879 return 0;
965 880 }
966 881
967 882 $inbox = new FrmInbox();
@@ -972,9 +887,8 @@
972 887 }
973 888
974 889 if ( is_callable( 'FrmProSettingsController::inbox_badge' ) ) {
975 890 $inbox_count = FrmProSettingsController::inbox_badge( $inbox_count );
976 -
977 891 if ( ! $inbox_count ) {
978 892 return 0;
979 893 }
980 894 }