PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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 +132 -113 6.27 → trunk View file →
@@ -118,9 +118,9 @@
118 118 * @param object $field - this is passed by reference since it is an object.
119 119 * @param bool $reset
120 120 * @param array $args
121 121 *
122 - * @return array|string $new_value
122 + * @return array|string New value.
123 123 */
124 124 private static function get_field_value_for_new_entry( $field, $reset, $args ) {
125 125 $new_value = $field->default_value;
126 126
@@ -128,9 +128,9 @@
128 128 self::get_posted_value( $field, $new_value, $args );
129 129 }
130 130
131 131 if ( ! is_array( $new_value ) ) {
132 - $new_value = str_replace( '"', '"', $new_value );
132 + return str_replace( '"', '"', $new_value );
133 133 }
134 134
135 135 return $new_value;
136 136 }
@@ -142,23 +142,25 @@
142 142 *
143 143 * @param object $field
144 144 * @param array $args
145 145 *
146 - * @return bool $value_is_posted
146 + * @return bool True if a value is posted.
147 147 */
148 148 public static function value_is_posted( $field, $args ) {
149 149 $value_is_posted = false;
150 150
151 - if ( $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
152 - $repeating = ! empty( $args['repeating'] );
151 + if ( ! $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
152 + return $value_is_posted;
153 + }
153 154
154 - if ( $repeating ) {
155 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
156 - $value_is_posted = true;
157 - }
158 - } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
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
159 159 $value_is_posted = true;
160 160 }
161 + } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
162 + $value_is_posted = true;
161 163 }
162 164
163 165 return $value_is_posted;
164 166 }
@@ -199,9 +201,9 @@
199 201 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
200 202
201 203 foreach ( $shortcodes[0] as $short_key => $tag ) {
202 204 $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
203 - $this_atts = ! empty( $add_atts ) ? array_merge( $atts, $add_atts ) : $atts;
205 + $this_atts = $add_atts ? array_merge( $atts, $add_atts ) : $atts;
204 206 $default = FrmEntriesController::show_entry_shortcode( $this_atts );
205 207
206 208 // Add the default message.
207 209 $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
@@ -220,12 +222,12 @@
220 222 public static function prepare_display_value( $entry, $field, $atts ) {
221 223 $field_value = $entry->metas[ $field->id ] ?? false;
222 224
223 225 if ( FrmAppHelper::pro_is_installed() ) {
224 - $empty = empty( $field_value );
226 + $empty = ! $field_value;
225 227 FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
226 228
227 - if ( $empty && ! empty( $field_value ) ) {
229 + if ( $empty && $field_value ) {
228 230 // We've got an entry id, so switch it to a value.
229 231 $atts['force_id'] = true;
230 232 }
231 233 }
@@ -255,14 +257,14 @@
255 257 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
256 258 }
257 259 }
258 260
259 - $field_value = array();
260 -
261 261 if ( empty( $child_entries ) ) {
262 262 return '';
263 263 }
264 264
265 + $field_value = array();
266 +
265 267 foreach ( $child_entries as $child_entry ) {
266 268 $atts['item_id'] = $child_entry->id;
267 269 $atts['post_id'] = $child_entry->post_id;
268 270
@@ -269,9 +271,9 @@
269 271 // Fet the value for this field -- check for post values as well.
270 272 $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field );
271 273
272 274 if ( $entry_val || '0' === $entry_val ) {
273 - // foreach entry get display_value.
275 + // For each entry get display_value.
274 276 $field_value[] = self::display_value( $entry_val, $field, $atts );
275 277 }
276 278
277 279 unset( $child_entry );
@@ -413,11 +415,11 @@
413 415 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; // phpcs:ignore WordPress.Security.NonceVerification.Missing
414 416 }
415 417
416 418 /**
417 - * @param array|int|object $field
418 - * @param mixed $value
419 - * @param array $args
419 + * @param array|int|object|string $field
420 + * @param mixed $value
421 + * @param array $args
420 422 *
421 423 * @return void
422 424 */
423 425 public static function get_posted_value( $field, &$value, $args ) {
@@ -447,8 +449,9 @@
447 449 }
448 450
449 451 /**
450 452 * @since 4.02.04
453 + * @since 6.29 This is public.
451 454 *
452 455 * @param int|string $field_id Field ID.
453 456 * @param array $args Additional arguments.
454 457 *
@@ -453,9 +456,9 @@
453 456 * @param array $args Additional arguments.
454 457 *
455 458 * @return mixed
456 459 */
457 - private static function get_posted_meta( $field_id, $args ) {
460 + public static function get_posted_meta( $field_id, $args ) {
458 461 if ( empty( $args['parent_field_id'] ) ) {
459 462 // Sanitizing is done next.
460 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
461 464 } else {
@@ -492,21 +495,22 @@
492 495 // Get other value for fields in repeating section.
493 496 self::set_other_repeating_vals( $field, $value, $args );
494 497
495 498 // Check if there are any posted "Other" values.
496 - if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
499 + if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
500 + return;
501 + }
497 502
498 - // Save original value.
499 - $args['temp_value'] = $value;
500 - $args['other'] = true;
503 + // Save original value.
504 + $args['temp_value'] = $value;
505 + $args['other'] = true;
501 506
502 - // Sanitizing is done next.
503 - $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
504 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
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 );
505 510
506 - // Set the validation value now
507 - self::set_other_validation_val( $value, $other_vals, $field, $args );
508 - }
511 + // Set the validation value now
512 + self::set_other_validation_val( $value, $other_vals, $field, $args );
509 513 }
510 514
511 515 /**
512 516 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
@@ -524,18 +528,20 @@
524 528 return;
525 529 }
526 530
527 531 // Check if there are any other posted "other" values for this field.
528 - 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
529 - // Save original value
530 - $args['temp_value'] = $value;
531 - $args['other'] = true;
532 - $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
533 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
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 + }
534 535
535 - // Set the validation value now.
536 - self::set_other_validation_val( $value, $other_vals, $field, $args );
537 - }
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 );
541 +
542 + // Set the validation value now.
543 + self::set_other_validation_val( $value, $other_vals, $field, $args );
538 544 }
539 545
540 546 /**
541 547 * Modify value used for validation
@@ -553,9 +559,9 @@
553 559 *
554 560 * @return void
555 561 */
556 562 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
557 - // Checkboxes and multi-select dropdowns.
563 + // Checkboxes.
558 564 if ( is_array( $value ) && $field->type === 'checkbox' ) {
559 565 // Combine "Other" values with checked values. "Other" values will override checked box values.
560 566 foreach ( $other_vals as $k => $v ) {
561 567 if ( isset( $value[ $k ] ) && trim( $v ) === '' ) {
@@ -567,38 +573,40 @@
567 573
568 574 if ( is_array( $value ) && $value ) {
569 575 $value = array_merge( $value, $other_vals );
570 576 }
571 - } else {
572 - // Radio and dropdowns.
573 - $other_key = array_filter( array_keys( $field->options ), 'is_string' );
574 - $other_key = reset( $other_key );
575 577
576 - // Multi-select dropdown.
577 - if ( is_array( $value ) ) {
578 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
579 - $o_key = array_search( $field->options[ $other_key ], $value );
578 + return;
579 + }
580 580
581 - if ( $o_key !== false ) {
582 - // Modify the original value so other key will be preserved.
583 - $value[ $other_key ] = $value[ $o_key ];
581 + // Radio and dropdowns.
582 + $other_key = array_filter( array_keys( $field->options ), 'is_string' );
583 + $other_key = reset( $other_key );
584 584
585 - // By default, the array keys will be numeric for multi-select dropdowns.
586 - // If going backwards and forwards between pages, the array key will match the other key.
587 - if ( $o_key !== $other_key ) {
588 - unset( $value[ $o_key ] );
589 - }
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 );
590 589
591 - $args['temp_value'] = $value;
592 - $value[ $other_key ] = reset( $other_vals );
590 + if ( $o_key !== false ) {
591 + // Modify the original value so other key will be preserved.
592 + $value[ $other_key ] = $value[ $o_key ];
593 593
594 - if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
595 - unset( $value[ $other_key ] );
596 - }
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 ] );
597 598 }
598 - } elseif ( $field->options[ $other_key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
599 - $value = $other_vals;
600 - }//end if
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;
601 609 }//end if
602 610 }
603 611
604 612 /**
@@ -673,20 +681,20 @@
673 681 }
674 682 }
675 683 }
676 684
677 - // finally get the correct version number
685 + // Finally get the correct version number
678 686 $known = array( 'Version', $ub, 'other' );
679 687 $pattern = '#(?<browser>' . implode( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
680 688 // Get the matching numbers.
681 689 preg_match_all( $pattern, $u_agent, $matches );
682 690
683 - // see how many we have
691 + // See how many we have
684 692 $i = count( $matches['browser'] );
685 693
686 694 if ( $i > 1 ) {
687 695 // We will have two since we are not using 'other' argument yet
688 - // see if version is before or after the name.
696 + // See if version is before or after the name.
689 697 $version = strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ? $matches['version'][0] : $matches['version'][1];
690 698 } elseif ( $i === 1 ) {
691 699 $version = $matches['version'][0];
692 700 } else {
@@ -692,9 +700,9 @@
692 700 } else {
693 701 $version = '';
694 702 }
695 703
696 - // check if we have a number
704 + // Check if we have a number
697 705 if ( $version === '' ) {
698 706 $version = '?';
699 707 }
700 708
@@ -712,8 +720,9 @@
712 720 $id = $atts['id'] ?? FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
713 721 $links = self::get_action_links( $id, $atts['entry'] );
714 722
715 723 foreach ( $links as $link ) {
724 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
716 725 ?>
717 726 <div class="misc-pub-section">
718 727 <a href="<?php echo esc_url( $link['url'] ); ?>"
719 728 <?php
@@ -736,8 +745,9 @@
736 745 <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
737 746 </a>
738 747 </div>
739 748 <?php
749 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
740 750 }//end foreach
741 751 }
742 752
743 753 /**
@@ -751,8 +761,20 @@
751 761 private static function get_action_links( $id, $entry ) {
752 762 $page = FrmAppHelper::get_param( 'frm_action' );
753 763 $actions = array();
754 764
765 + $actions['frm_edit'] = array(
766 + 'url' => '#',
767 + 'label' => __( 'Edit Entry', 'formidable' ),
768 + 'class' => 'frm_noallow',
769 + 'data' => array(
770 + 'upgrade' => __( 'Entry edits', 'formidable' ),
771 + 'medium' => 'edit-entries',
772 + 'content' => 'entry',
773 + ),
774 + 'icon' => 'frmfont frm_pencil_icon',
775 + );
776 +
755 777 if ( $page !== 'show' ) {
756 778 $actions['frm_view'] = array(
757 779 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
758 780 'label' => __( 'View Entry', 'formidable' ),
@@ -759,20 +781,8 @@
759 781 'icon' => 'frmfont frm_save_icon',
760 782 );
761 783 }
762 784
763 - if ( current_user_can( 'frm_delete_entries' ) ) {
764 - $actions['frm_delete'] = array(
765 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ) ),
766 - 'label' => __( 'Delete Entry', 'formidable' ),
767 - 'icon' => 'frmfont frm_delete_icon',
768 - 'data' => array(
769 - 'frmverify' => __( 'Permanently delete this entry?', 'formidable' ),
770 - 'frmverify-btn' => 'frm-button-red',
771 - ),
772 - );
773 - }
774 -
775 785 if ( $page === 'show' ) {
776 786 $actions['frm_print'] = array(
777 787 'url' => '#',
778 788 'label' => __( 'Print Entry', 'formidable' ),
@@ -782,20 +792,8 @@
782 792 'icon' => 'frmfont frm_printer_icon',
783 793 );
784 794 }
785 795
786 - $actions['frm_resend'] = array(
787 - 'url' => '#',
788 - 'label' => __( 'Resend Emails', 'formidable' ),
789 - 'class' => 'frm_noallow',
790 - 'data' => array(
791 - 'upgrade' => __( 'Resend Emails', 'formidable' ),
792 - 'medium' => 'resend-email',
793 - 'content' => 'entry',
794 - ),
795 - 'icon' => 'frmfont frm_email_icon',
796 - );
797 -
798 796 if ( ! function_exists( 'frm_pdfs_autoloader' ) ) {
799 797 $actions['frm_download_pdf'] = array(
800 798 'url' => '#',
801 799 'label' => __( 'Download as PDF', 'formidable' ),
@@ -804,21 +802,45 @@
804 802 'icon' => 'frmfont frm_download_icon',
805 803 );
806 804 }
807 805
808 - $actions['frm_edit'] = array(
806 + $actions['frm_resend'] = array(
809 807 'url' => '#',
810 - 'label' => __( 'Edit Entry', 'formidable' ),
808 + 'label' => __( 'Resend Emails', 'formidable' ),
811 809 'class' => 'frm_noallow',
812 810 'data' => array(
813 - 'upgrade' => __( 'Entry edits', 'formidable' ),
814 - 'medium' => 'edit-entries',
811 + 'upgrade' => __( 'Resend Emails', 'formidable' ),
812 + 'medium' => 'resend-email',
815 813 'content' => 'entry',
816 814 ),
817 - 'icon' => 'frmfont frm_pencil_icon',
815 + 'icon' => 'frmfont frm_email_icon',
818 816 );
819 817
820 - return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
818 + if ( current_user_can( 'frm_delete_entries' ) ) {
819 + $actions['frm_delete'] = array(
820 + 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ) ),
821 + 'label' => __( 'Delete Entry', 'formidable' ),
822 + 'class' => 'frm_delete_entry',
823 + 'icon' => 'frmfont frm_delete_icon',
824 + 'data' => array(
825 + 'frmverify' => __( 'Permanently delete this entry?', 'formidable' ),
826 + 'frmverify-btn' => 'frm-button-red',
827 + ),
828 + );
829 + }
830 +
831 + $actions = apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
832 +
833 + if ( ! isset( $actions['frm_delete'] ) ) {
834 + return $actions;
835 + }
836 +
837 + // Make delete the last link.
838 + $delete_action = $actions['frm_delete'];
839 + unset( $actions['frm_delete'] );
840 + $actions['frm_delete'] = $delete_action;
841 +
842 + return $actions;
821 843 }
822 844
823 845 /**
824 846 * Gets data attributes for PDFs addon upgrade link.
@@ -860,16 +882,18 @@
860 882 );
861 883 $metas_without_a_field = (array) FrmEntryMeta::getAll( $query, ' ORDER BY it.created_at DESC', '', true );
862 884
863 885 foreach ( $metas_without_a_field as $meta ) {
864 - if ( ! empty( $meta->meta_value['captcha_score'] ) ) {
865 - echo '<div class="misc-pub-section">';
866 - FrmAppHelper::icon_by_class( 'frmfont frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
867 - echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
868 - echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
869 - echo '</div>';
870 - return;
886 + if ( empty( $meta->meta_value['captcha_score'] ) ) {
887 + continue;
871 888 }
889 +
890 + echo '<div class="misc-pub-section">';
891 + FrmAppHelper::icon_by_class( 'frmfont frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
892 + echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
893 + echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
894 + echo '</div>';
895 + return;
872 896 }
873 897 }
874 898
875 899 /**
@@ -881,11 +905,9 @@
881 905 *
882 906 * @return int
883 907 */
884 908 public static function get_entry_status( $status ) {
885 - $statuses = self::get_entry_statuses();
886 -
887 - if ( array_key_exists( $status, $statuses ) ) {
909 + if ( array_key_exists( $status, self::get_entry_statuses() ) ) {
888 910 return $status;
889 911 }
890 912
891 913 if ( ! $status ) {
@@ -906,10 +928,9 @@
906 928 *
907 929 * @return string
908 930 */
909 931 public static function get_entry_status_label( $status ) {
910 - $statuses = self::get_entry_statuses();
911 - return $statuses[ self::get_entry_status( $status ) ];
932 + return self::get_entry_statuses()[ self::get_entry_status( $status ) ];
912 933 }
913 934
914 935 /**
915 936 * Get all entry statuses.
@@ -950,11 +971,9 @@
950 971 *
951 972 * @return int
952 973 */
953 974 public static function get_visible_unread_inbox_count() {
954 - $menu_name = FrmAppHelper::get_menu_name();
955 -
956 - if ( ! in_array( $menu_name, array( 'Formidable', 'Forms' ), true ) ) {
975 + if ( ! in_array( FrmAppHelper::get_menu_name(), array( 'Formidable', 'Forms' ), true ) ) {
957 976 return 0;
958 977 }
959 978
960 979 $inbox = new FrmInbox();