PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +18 -143 6.26.1 → 6.13 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,9 +30,8 @@
40 30 'item_key' => '',
41 31 );
42 32
43 33 $values['fields'] = array();
44 -
45 34 if ( empty( $fields ) ) {
46 35 return apply_filters( 'frm_setup_new_entry', $values );
47 36 }
48 37
@@ -53,11 +42,11 @@
53 42
54 43 $field_array = FrmAppHelper::start_field_array( $field );
55 44 $field_array['value'] = $new_value;
56 45 $field_array['type'] = apply_filters( 'frm_field_type', $field->type, $field, $new_value );
57 - $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;
58 47 $field_array['reset_value'] = $reset;
59 - $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';
60 49 $field_array['original_default'] = $original_default;
61 50
62 51 FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args );
63 52
@@ -74,9 +63,8 @@
74 63 }
75 64 }//end foreach
76 65
77 66 FrmAppHelper::unserialize_or_decode( $form->options );
78 -
79 67 if ( is_array( $form->options ) ) {
80 68 $values = array_merge( $values, $form->options );
81 69 }
82 70
@@ -91,10 +79,8 @@
91 79 /**
92 80 * @since 2.05
93 81 *
94 82 * @param object $field
95 - *
96 - * @return void
97 83 */
98 84 private static function prepare_field_default_value( &$field ) {
99 85 // If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array.
100 86 $return_array = FrmField::is_field_with_multiple_values( $field );
@@ -147,12 +133,10 @@
147 133 * @return bool $value_is_posted
148 134 */
149 135 public static function value_is_posted( $field, $args ) {
150 136 $value_is_posted = false;
151 -
152 137 if ( $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
153 138 $repeating = isset( $args['repeating'] ) && $args['repeating'];
154 -
155 139 if ( $repeating ) {
156 140 if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
157 141 $value_is_posted = true;
158 142 }
@@ -163,14 +147,8 @@
163 147
164 148 return $value_is_posted;
165 149 }
166 150
167 - /**
168 - * @param array $values
169 - * @param object $record
170 - *
171 - * @return array
172 - */
173 151 public static function setup_edit_vars( $values, $record ) {
174 152 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
175 153
176 154 $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
@@ -179,14 +157,8 @@
179 157
180 158 return apply_filters( 'frm_setup_edit_entry_vars', $values, $record );
181 159 }
182 160
183 - /**
184 - * @param string $message
185 - * @param array $atts
186 - *
187 - * @return string
188 - */
189 161 public static function replace_default_message( $message, $atts ) {
190 162 if ( strpos( $message, '[default-message' ) === false &&
191 163 strpos( $message, '[default_message' ) === false &&
192 164 ! empty( $message ) ) {
@@ -200,9 +172,8 @@
200 172 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
201 173
202 174 foreach ( $shortcodes[0] as $short_key => $tag ) {
203 175 $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
204 -
205 176 if ( ! empty( $add_atts ) ) {
206 177 $this_atts = array_merge( $atts, $add_atts );
207 178 } else {
208 179 $this_atts = $atts;
@@ -220,18 +191,16 @@
220 191 /**
221 192 * @param stdClass $entry
222 193 * @param stdClass $field
223 194 * @param array $atts
224 - *
225 195 * @return string
226 196 */
227 197 public static function prepare_display_value( $entry, $field, $atts ) {
228 - $field_value = $entry->metas[ $field->id ] ?? false;
198 + $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
229 199
230 200 if ( FrmAppHelper::pro_is_installed() ) {
231 201 $empty = empty( $field_value );
232 202 FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
233 -
234 203 if ( $empty && ! empty( $field_value ) ) {
235 204 // We've got an entry id, so switch it to a value.
236 205 $atts['force_id'] = true;
237 206 }
@@ -243,9 +212,8 @@
243 212
244 213 if ( ! FrmAppHelper::pro_is_installed() ) {
245 214 return '';
246 215 }
247 -
248 216 if ( is_callable( 'FrmProEntriesHelper::prepare_child_display_value' ) ) {
249 217 return FrmProEntriesHelper::prepare_child_display_value( $entry, $field, $atts );
250 218 }
251 219
@@ -254,9 +222,9 @@
254 222 // This is a repeating section.
255 223 $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ), '', '', true );
256 224 } else {
257 225 // Get all values for this field.
258 - $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;
259 227
260 228 if ( $child_values ) {
261 229 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
262 230 }
@@ -283,13 +251,11 @@
283 251 unset( $child_entry );
284 252 }
285 253
286 254 $sep = ', ';
287 -
288 255 if ( strpos( implode( ' ', $field_value ), '<img' ) !== false ) {
289 256 $sep = '<br/>';
290 257 }
291 -
292 258 $val = implode( $sep, $field_value );
293 259
294 260 return FrmAppHelper::kses( $val, 'all' );
295 261 }
@@ -326,12 +292,8 @@
326 292 }
327 293
328 294 $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value );
329 295
330 - if ( is_string( $field->field_options ) ) {
331 - $field->field_options = array();
332 - }
333 -
334 296 if ( ! isset( $field->field_options['post_field'] ) ) {
335 297 $field->field_options['post_field'] = '';
336 298 }
337 299
@@ -341,9 +303,9 @@
341 303
342 304 if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] === 'tag' ) ) {
343 305 $atts['pre_truncate'] = $atts['truncate'];
344 306 $atts['truncate'] = true;
345 - $atts['exclude_cat'] = $field->field_options['exclude_cat'] ?? 0;
307 + $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
346 308
347 309 $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts );
348 310 $atts['truncate'] = $atts['pre_truncate'];
349 311 }
@@ -372,21 +334,13 @@
372 334
373 335 return apply_filters( 'frm_display_value', $value, $field, $atts );
374 336 }
375 337
376 - /**
377 - * @param object $field
378 - * @param mixed $value
379 - * @param array $args
380 - *
381 - * @return void
382 - */
383 338 public static function set_posted_value( $field, $value, $args ) {
384 339 // If validating a field with "other" opt, set back to prev value now.
385 340 if ( ! empty( $args['other'] ) ) {
386 341 $value = $args['temp_value'];
387 342 }
388 -
389 343 if ( empty( $args['parent_field_id'] ) ) {
390 344 $_POST['item_meta'][ $field->id ] = $value;
391 345 } else {
392 346 self::set_parent_field_posted_value( $field, $value, $args );
@@ -396,14 +350,8 @@
396 350 /**
397 351 * Init arrays if necessary, else we get fatal error.
398 352 *
399 353 * @since 4.01
400 - *
401 - * @param object $field Field object.
402 - * @param mixed $value Value to set.
403 - * @param array $args Additional arguments.
404 - *
405 - * @return void
406 354 */
407 355 private static function set_parent_field_posted_value( $field, $value, $args ) {
408 356 if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
409 357 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
@@ -417,15 +365,8 @@
417 365
418 366 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; // phpcs:ignore WordPress.Security.NonceVerification.Missing
419 367 }
420 368
421 - /**
422 - * @param array|int|object $field
423 - * @param mixed $value
424 - * @param array $args
425 - *
426 - * @return void
427 - */
428 369 public static function get_posted_value( $field, &$value, $args ) {
429 370 if ( is_array( $field ) ) {
430 371 $field_id = $field['id'];
431 372 $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
@@ -430,14 +371,9 @@
430 371 $field_id = $field['id'];
431 372 $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
432 373 } elseif ( is_object( $field ) ) {
433 374 $field_id = $field->id;
434 -
435 - if ( 'hidden' === $field->type && ! empty( $field->field_options['original_type'] ) ) {
436 - $field_obj = FrmFieldFactory::get_field_type( $field->field_options['original_type'], $field );
437 - } else {
438 - $field_obj = FrmFieldFactory::get_field_object( $field );
439 - }
375 + $field_obj = FrmFieldFactory::get_field_object( $field );
440 376 } elseif ( is_numeric( $field ) ) {
441 377 $field_id = $field;
442 378 $field_obj = FrmFieldFactory::get_field_object( $field );
443 379 } else {
@@ -452,13 +388,8 @@
452 388 }
453 389
454 390 /**
455 391 * @since 4.02.04
456 - *
457 - * @param int|string $field_id Field ID.
458 - * @param array $args Additional arguments.
459 - *
460 - * @return mixed
461 392 */
462 393 private static function get_posted_meta( $field_id, $args ) {
463 394 if ( empty( $args['parent_field_id'] ) ) {
464 395 // Sanitizing is done next.
@@ -473,17 +404,14 @@
473 404 * Check if field has an "Other" option and if any other values are posted
474 405 *
475 406 * @since 2.0
476 407 *
477 - * @param object $field Field object.
478 - * @param array|string $value Field value, passed by reference.
479 - * @param array $args Arguments array, passed by reference.
480 - *
481 - * @return void
408 + * @param object $field
409 + * @param array|string $value
410 + * @param array $args
482 411 */
483 412 public static function maybe_set_other_validation( $field, &$value, &$args ) {
484 413 $args['other'] = false;
485 -
486 414 if ( ! $value || ! FrmAppHelper::pro_is_installed() ) {
487 415 return;
488 416 }
489 417
@@ -517,13 +445,11 @@
517 445 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
518 446 *
519 447 * @since 2.0
520 448 *
521 - * @param object $field Field object.
522 - * @param array|string $value Field value, passed by reference.
523 - * @param array $args Arguments array, passed by reference.
524 - *
525 - * @return void
449 + * @param object $field
450 + * @param array|string $value
451 + * @param array $args
526 452 */
527 453 public static function set_other_repeating_vals( $field, &$value, &$args ) {
528 454 if ( ! $args['parent_field_id'] ) {
529 455 return;
@@ -555,10 +481,8 @@
555 481 * @param array|string $value
556 482 * @param array|string $other_vals (usually of posted values).
557 483 * @param object $field
558 484 * @param array $args
559 - *
560 - * @return void
561 485 */
562 486 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
563 487 // Checkboxes and multi-select dropdowns.
564 488 if ( is_array( $value ) && $field->type === 'checkbox' ) {
@@ -594,9 +518,8 @@
594 518 }
595 519
596 520 $args['temp_value'] = $value;
597 521 $value[ $other_key ] = reset( $other_vals );
598 -
599 522 if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
600 523 unset( $value[ $other_key ] );
601 524 }
602 525 }
@@ -609,16 +532,14 @@
609 532 /**
610 533 * Add submitted values to a string for spam checking.
611 534 *
612 535 * @param array $values
613 - *
614 536 * @return string
615 537 */
616 538 public static function entry_array_to_string( $values ) {
617 539 $content = '';
618 -
619 540 foreach ( $values['item_meta'] as $val ) {
620 - if ( $content !== '' ) {
541 + if ( $content != '' ) {
621 542 $content .= "\n\n";
622 543 }
623 544
624 545 if ( is_array( $val ) ) {
@@ -680,9 +601,9 @@
680 601 }
681 602
682 603 // finally get the correct version number
683 604 $known = array( 'Version', $ub, 'other' );
684 - $pattern = '#(?<browser>' . implode( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
605 + $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
685 606 // Get the matching numbers.
686 607 preg_match_all( $pattern, $u_agent, $matches );
687 608
688 609 // see how many we have
@@ -702,9 +623,9 @@
702 623 $version = '';
703 624 }
704 625
705 626 // check if we have a number
706 - if ( $version === '' ) {
627 + if ( $version == '' ) {
707 628 $version = '?';
708 629 }
709 630
710 631 return $bname . ' ' . $version . ' / ' . $platform;
@@ -711,15 +632,11 @@
711 632 }
712 633
713 634 /**
714 635 * @since 3.0
715 - *
716 - * @param array $atts Action dropdown attributes.
717 - *
718 - * @return void
719 636 */
720 637 public static function actions_dropdown( $atts ) {
721 - $id = $atts['id'] ?? FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
638 + $id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
722 639 $links = self::get_action_links( $id, $atts['entry'] );
723 640
724 641 foreach ( $links as $link ) {
725 642 ?>
@@ -730,13 +647,11 @@
730 647 foreach ( $link['data'] as $data => $value ) {
731 648 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
732 649 }
733 650 }
734 -
735 651 if ( isset( $link['class'] ) ) {
736 652 echo 'class="' . esc_attr( $link['class'] ) . '" ';
737 653 }
738 -
739 654 if ( isset( $link['id'] ) ) {
740 655 echo 'id="' . esc_attr( $link['id'] ) . '" ';
741 656 }
742 657 ?>
@@ -750,13 +665,8 @@
750 665 }
751 666
752 667 /**
753 668 * @since 3.0
754 - *
755 - * @param int $id Entry ID.
756 - * @param array|object $entry Entry object.
757 - *
758 - * @return array
759 669 */
760 670 private static function get_action_links( $id, $entry ) {
761 671 $page = FrmAppHelper::get_param( 'frm_action' );
762 672 $actions = array();
@@ -774,10 +684,9 @@
774 684 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ) ),
775 685 'label' => __( 'Delete Entry', 'formidable' ),
776 686 'icon' => 'frm_icon_font frm_delete_icon',
777 687 'data' => array(
778 - 'frmverify' => __( 'Permanently delete this entry?', 'formidable' ),
779 - 'frmverify-btn' => 'frm-button-red',
688 + 'frmverify' => __( 'Delete this form entry?', 'formidable' ),
780 689 ),
781 690 );
782 691 }
783 692
@@ -803,9 +712,9 @@
803 712 ),
804 713 'icon' => 'frm_icon_font frm_email_icon',
805 714 );
806 715
807 - if ( ! function_exists( 'frm_pdfs_autoloader' ) ) {
716 + if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) {
808 717 $actions['frm_download_pdf'] = array(
809 718 'url' => '#',
810 719 'label' => __( 'Download as PDF', 'formidable' ),
811 720 'class' => 'frm_noallow',
@@ -832,9 +741,8 @@
832 741 /**
833 742 * Gets data attributes for PDFs addon upgrade link.
834 743 *
835 744 * @param string $medium The source of the upgrade link used for analytics data.
836 - *
837 745 * @return array
838 746 */
839 747 private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
840 748 $data = array(
@@ -844,9 +752,8 @@
844 752 'medium' => $medium,
845 753 );
846 754
847 755 $upgrading = FrmAddonsController::install_link( 'pdfs' );
848 -
849 756 if ( isset( $upgrading['url'] ) ) {
850 757 $data['oneclick'] = json_encode( $upgrading );
851 758 } else {
852 759 $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
@@ -858,9 +765,8 @@
858 765 /**
859 766 * @since 5.0.15
860 767 *
861 768 * @param int|string $entry_id
862 - *
863 769 * @return void
864 770 */
865 771 public static function maybe_render_captcha_score( $entry_id ) {
866 772 $query = array(
@@ -867,9 +773,8 @@
867 773 'item_id' => (int) $entry_id,
868 774 'field_id' => 0,
869 775 );
870 776 $metas_without_a_field = (array) FrmEntryMeta::getAll( $query, ' ORDER BY it.created_at DESC', '', true );
871 -
872 777 foreach ( $metas_without_a_field as $meta ) {
873 778 if ( ! empty( $meta->meta_value['captcha_score'] ) ) {
874 779 echo '<div class="misc-pub-section">';
875 780 FrmAppHelper::icon_by_class( 'frm_icon_font frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
@@ -955,36 +860,6 @@
955 860
956 861 $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status );
957 862
958 863 return $existing_entry_statuses;
959 - }
960 -
961 - /**
962 - * @since 6.17
963 - *
964 - * @return int
965 - */
966 - public static function get_visible_unread_inbox_count() {
967 - $menu_name = FrmAppHelper::get_menu_name();
968 -
969 - if ( ! in_array( $menu_name, array( 'Formidable', 'Forms' ), true ) ) {
970 - return 0;
971 - }
972 -
973 - $inbox = new FrmInbox();
974 - $inbox_count = count( $inbox->unread() );
975 -
976 - if ( ! $inbox_count ) {
977 - return 0;
978 - }
979 -
980 - if ( is_callable( 'FrmProSettingsController::inbox_badge' ) ) {
981 - $inbox_count = FrmProSettingsController::inbox_badge( $inbox_count );
982 -
983 - if ( ! $inbox_count ) {
984 - return 0;
985 - }
986 - }
987 -
988 - return $inbox_count;
989 864 }
990 865 }