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/controllers/FrmEntriesController.php +94 -94 6.26 → trunk View file →
@@ -10,17 +10,17 @@
10 10 */
11 11 public static function menu() {
12 12 FrmAppHelper::force_capability( 'frm_view_entries' );
13 13
14 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
14 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
15 15
16 16 $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed();
17 17
18 - if ( ! $views_installed ) {
19 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' );
18 + if ( $views_installed ) {
19 + self::maybe_redirect_to_views_index();
20 + } else {
21 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
20 22 self::maybe_redirect_to_views_upsell();
21 - } else {
22 - self::maybe_redirect_to_views_index();
23 23 }
24 24
25 25 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
26 26 self::load_manage_entries_hooks();
@@ -84,11 +84,10 @@
84 84 * @return array
85 85 */
86 86 private static function add_url_params_to_views_redirect_query_args( $query_args ) {
87 87 $query_args['show_nav'] = FrmAppHelper::simple_get( 'show_nav', 'absint', 0 );
88 + $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
88 89
89 - $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
90 -
91 90 if ( $form_id ) {
92 91 $query_args['form'] = $form_id;
93 92 }
94 93
@@ -100,18 +99,19 @@
100 99 *
101 100 * @return void
102 101 */
103 102 private static function load_manage_entries_hooks() {
104 - if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
105 - $menu_name = FrmAppHelper::get_menu_name();
106 - $base = self::base_column_key( $menu_name );
107 -
108 - add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
109 - add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
110 - add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' );
111 - } else {
103 + if ( in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
112 104 add_filter( 'screen_options_show_screen', self::class . '::remove_screen_options', 10, 2 );
105 + return;
113 106 }
107 +
108 + $menu_name = FrmAppHelper::get_menu_name();
109 + $base = self::base_column_key( $menu_name );
110 +
111 + add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
112 + add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
113 + add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' );
114 114 }
115 115
116 116 /**
117 117 * Display in Back End.
@@ -130,13 +130,13 @@
130 130 default:
131 131 do_action( 'frm_entry_action_route', $action );
132 132
133 133 if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
134 - return;
134 + return null;
135 135 }
136 136
137 137 self::display_list();
138 - return;
138 + return null;
139 139 }
140 140 }
141 141
142 142 /**
@@ -154,9 +154,9 @@
154 154 $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
155 155 $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
156 156
157 157 if ( $screen->id === $menu_name . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries' ) {
158 - $show_screen = false;
158 + return false;
159 159 }
160 160
161 161 return $show_screen;
162 162 }
@@ -181,17 +181,16 @@
181 181 $columns[ $form_id . '_user_id' ] = esc_html__( 'Created By', 'formidable' );
182 182 }
183 183
184 184 $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' );
185 - $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
186 - $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
185 + $columns[ $form_id . '_created_at' ] = esc_html__( 'Entry creation date', 'formidable' );
186 + $columns[ $form_id . '_updated_at' ] = esc_html__( 'Entry update date', 'formidable' );
187 187 self::maybe_add_ip_col( $form_id, $columns );
188 188
189 189 $frm_vars['cols'] = $columns;
190 + $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
190 191
191 - $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
192 -
193 - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
192 + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ), true ) ) {
194 193 add_screen_option(
195 194 'per_page',
196 195 array(
197 196 'label' => esc_html__( 'Entries', 'formidable' ),
@@ -249,9 +248,9 @@
249 248 */
250 249 private static function add_subform_cols( $field, $form_id, &$columns ) {
251 250 $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] );
252 251
253 - if ( empty( $sub_form_cols ) ) {
252 + if ( ! $sub_form_cols ) {
254 253 return;
255 254 }
256 255
257 256 foreach ( $sub_form_cols as $k => $sub_form_col ) {
@@ -258,8 +257,9 @@
258 257 if ( FrmField::is_no_save_field( $sub_form_col->type ) ) {
259 258 unset( $sub_form_cols[ $k ] );
260 259 continue;
261 260 }
261 +
262 262 $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $field->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
263 263 unset( $sub_form_col );
264 264 }
265 265 }
@@ -275,9 +275,9 @@
275 275 */
276 276 private static function add_field_cols( $field, $form_id, &$columns ) {
277 277 $col_id = $field->field_key;
278 278
279 - if ( $field->form_id != $form_id ) {
279 + if ( (int) $field->form_id !== (int) $form_id ) {
280 280 $col_id .= '-_-form' . $field->form_id;
281 281 }
282 282
283 283 $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
@@ -304,9 +304,9 @@
304 304 */
305 305 private static function maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, $is_value = true ) {
306 306 $field_name = FrmAppHelper::truncate( $field->name, 35 );
307 307
308 - if ( ! $include_column_for_sep_val || ! in_array( $field->type, array( 'select', 'radio', 'checkbox' ), true ) ) {
308 + if ( ! $include_column_for_sep_val || ! in_array( $field->type, array( 'select', 'radio', 'checkbox', 'product', 'ranking' ), true ) ) {
309 309 return $field_name;
310 310 }
311 311
312 312 $append_text = $is_value ? esc_html__( 'value', 'formidable' ) : esc_html__( 'label', 'formidable' );
@@ -337,13 +337,14 @@
337 337 */
338 338 public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
339 339 $this_page_name = self::hidden_column_key();
340 340
341 + // phpcs:ignore Universal.Operators.StrictComparisons
341 342 if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
342 343 return $check;
343 344 }
344 345
345 - if ( empty( $prev_value ) ) {
346 + if ( ! $prev_value ) {
346 347 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
347 348 }
348 349
349 350 global $frm_vars;
@@ -365,8 +366,9 @@
365 366 */
366 367 public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
367 368 $this_page_name = self::hidden_column_key();
368 369
370 + // phpcs:ignore Universal.Operators.StrictComparisons
369 371 if ( $meta_key != $this_page_name ) {
370 372 return;
371 373 }
372 374
@@ -371,9 +373,9 @@
371 373 }
372 374
373 375 global $frm_vars;
374 376
375 - if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
377 + if ( empty( $frm_vars['prev_hidden_cols'] ) ) {
376 378 // Don't continue if there's no previous value.
377 379 return;
378 380 }
379 381
@@ -378,9 +380,9 @@
378 380 }
379 381
380 382 foreach ( $meta_value as $mk => $mv ) {
381 383 // Remove blank values.
382 - if ( empty( $mv ) ) {
384 + if ( ! $mv ) {
383 385 unset( $meta_value[ $mk ] );
384 386 }
385 387 }
386 388
@@ -389,9 +391,10 @@
389 391 $cur_form_prefix = $cur_form_prefix[0];
390 392 $save = false;
391 393
392 394 foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
393 - if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
395 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
396 + if ( ! $prev_hidden || in_array( $prev_hidden, $meta_value ) ) {
394 397 // Don't add blank cols or process included cols.
395 398 continue;
396 399 }
397 400
@@ -407,12 +410,13 @@
407 410 $save = true;
408 411 unset( $form_prefix );
409 412 }
410 413
411 - if ( $save ) {
412 - $user_id = get_current_user_id();
413 - update_user_option( $user_id, $this_page_name, $meta_value, true );
414 + if ( ! $save ) {
415 + return;
414 416 }
417 +
418 + update_user_option( get_current_user_id(), $this_page_name, $meta_value, true );
415 419 }
416 420
417 421 /**
418 422 * @since 2.05.07
@@ -422,9 +426,8 @@
422 426 * @return string
423 427 */
424 428 private static function hidden_column_key( $menu_name = '' ) {
425 429 $base = self::base_column_key( $menu_name );
426 -
427 430 return 'manage' . $base . 'columnshidden';
428 431 }
429 432
430 433 /**
@@ -434,9 +437,9 @@
434 437 *
435 438 * @return string
436 439 */
437 440 private static function base_column_key( $menu_name = '' ) {
438 - if ( empty( $menu_name ) ) {
441 + if ( ! $menu_name ) {
439 442 $menu_name = FrmAppHelper::get_menu_name();
440 443 }
441 444
442 445 $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
@@ -452,9 +455,9 @@
452 455 * @return int
453 456 */
454 457 public static function save_per_page( $save, $option, $value ) {
455 458 if ( $option === 'formidable_page_formidable_entries_per_page' ) {
456 - $save = (int) $value;
459 + return (int) $value;
457 460 }
458 461
459 462 return $save;
460 463 }
@@ -522,9 +525,9 @@
522 525 $hidden = self::user_hidden_columns_for_form( $form_id, $result );
523 526 $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
524 527 $max_columns = 11;
525 528
526 - if ( ! empty( $hidden ) ) {
529 + if ( $hidden ) {
527 530 $result = $hidden;
528 531 $i = $i - count( $result );
529 532 }
530 533
@@ -548,17 +551,19 @@
548 551 private static function user_hidden_columns_for_form( $form_id, $result ) {
549 552 $hidden = array();
550 553
551 554 foreach ( (array) $result as $r ) {
552 - if ( ! empty( $r ) ) {
553 - list( $form_prefix, $field_key ) = explode( '_', $r );
555 + if ( ! $r ) {
556 + continue;
557 + }
554 558
555 - if ( (int) $form_prefix === (int) $form_id ) {
556 - $hidden[] = $r;
557 - }
559 + list( $form_prefix, $field_key ) = explode( '_', $r );
558 560
559 - unset( $form_prefix );
561 + if ( (int) $form_prefix === (int) $form_id ) {
562 + $hidden[] = $r;
560 563 }
564 +
565 + unset( $form_prefix );
561 566 }
562 567
563 568 return $hidden;
564 569 }
@@ -580,17 +585,16 @@
580 585 $atts['form_id'] . '_item_key' => '',
581 586 $atts['form_id'] . '_id' => '',
582 587 );
583 588 $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
589 + $i = $atts['i'];
584 590
585 - $i = $atts['i'];
586 -
587 591 foreach ( $cols as $col_key => $col ) {
588 592 if ( $i <= $atts['max_columns'] ) {
589 593 break;
590 594 }
591 595
592 - if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
596 + if ( ! $result || ! in_array( $col_key, $result, true ) ) {
593 597 $result[] = $col_key;
594 598 --$i;
595 599 }
596 600
@@ -616,14 +620,12 @@
616 620
617 621 self::get_delete_form_time( $form, $errors );
618 622 }
619 623
620 - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
621 -
624 + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
622 625 $wp_list_table = new $table_class( array( 'params' => $params ) );
626 + $pagenum = $wp_list_table->get_pagenum();
623 627
624 - $pagenum = $wp_list_table->get_pagenum();
625 -
626 628 $wp_list_table->prepare_items();
627 629
628 630 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
629 631
@@ -632,14 +634,15 @@
632 634
633 635 if ( headers_sent() ) {
634 636 FrmAppHelper::js_redirect( $url, true );
635 637 } else {
636 - wp_redirect( esc_url_raw( $url ) );
638 + wp_safe_redirect( esc_url_raw( $url ) );
637 639 }
640 +
638 641 die();
639 642 }
640 643
641 - if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
644 + if ( ! $message && isset( $_GET['import-message'] ) ) {
642 645 $message = __( 'Your import is complete', 'formidable' );
643 646 }
644 647
645 648 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
@@ -651,15 +654,17 @@
651 654 *
652 655 * @return void
653 656 */
654 657 private static function get_delete_form_time( $form, &$errors ) {
655 - if ( 'trash' === $form->status ) {
656 - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
657 - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( $form->options['trash_time'] ?? time() ) );
658 + if ( 'trash' !== $form->status ) {
659 + return;
660 + }
658 661
659 - /* translators: %1$s: Time string */
660 - $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete );
661 - }
662 + $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
663 + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, $form->options['trash_time'] ?? time() );
664 +
665 + /* translators: %1$s: Time string */
666 + $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete );
662 667 }
663 668
664 669 /**
665 670 * Back End CRUD.
@@ -724,9 +729,9 @@
724 729 }
725 730
726 731 $params = FrmForm::get_admin_params();
727 732
728 - if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
733 + if ( ! empty( $params['keep_post'] ) ) {
729 734 self::unlink_post( $params['id'] );
730 735 }
731 736
732 737 $message = '';
@@ -746,9 +751,9 @@
746 751 */
747 752 public static function process_entry( $errors = '', $ajax = false ) {
748 753 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
749 754
750 - if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
755 + if ( FrmAppHelper::is_admin() || empty( $_POST ) || ! $form_id || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
751 756 return;
752 757 }
753 758
754 759 global $frm_vars;
@@ -775,8 +780,9 @@
775 780 if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
776 781 return;
777 782 }
778 783
784 + // phpcs:ignore Universal.Operators.StrictComparisons
779 785 if ( $errors == '' && ! $ajax ) {
780 786 $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
781 787 }
782 788
@@ -789,28 +795,28 @@
789 795 $errors = apply_filters( 'frm_entries_before_create', $errors, $form );
790 796
791 797 $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
792 798
793 - if ( empty( $errors ) ) {
794 - $_POST['frm_skip_cookie'] = 1;
795 - $do_success = false;
799 + if ( $errors ) {
800 + return;
801 + }
796 802
797 - if ( $params['action'] === 'create' ) {
798 - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
799 - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
803 + $_POST['frm_skip_cookie'] = 1;
804 + $do_success = false;
800 805
801 - $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
802 - $do_success = true;
803 - }
804 - }
806 + if ( $params['action'] === 'create' && apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
807 + $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
805 808
806 - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
809 + $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
810 + $do_success = true;
811 + }
807 812
808 - if ( $do_success ) {
809 - FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
810 - }
811 - unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
813 + do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
814 +
815 + if ( $do_success ) {
816 + FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
812 817 }
818 + unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
813 819 }
814 820
815 821 /**
816 822 * Escape url entities before redirect
@@ -835,9 +841,8 @@
835 841 * @return string
836 842 */
837 843 public static function delete_entry_before_redirect( $url, $form, $atts ) {
838 844 self::_delete_entry( $atts['id'], $form );
839 -
840 845 return $url;
841 846 }
842 847
843 848 /**
@@ -865,12 +870,14 @@
865 870 }
866 871
867 872 FrmAppHelper::unserialize_or_decode( $form->options );
868 873
869 - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
870 - self::unlink_post( $entry_id );
871 - FrmEntry::destroy( $entry_id );
874 + if ( empty( $form->options['no_save'] ) ) {
875 + return;
872 876 }
877 +
878 + self::unlink_post( $entry_id );
879 + FrmEntry::destroy( $entry_id );
873 880 }
874 881
875 882 /**
876 883 * Unlink entry from post
@@ -921,28 +928,22 @@
921 928 'line_breaks' => true,
922 929 'array_separator' => ', ',
923 930 );
924 931 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
932 + $atts = shortcode_atts( $defaults, $atts );
925 933
926 - $atts = shortcode_atts( $defaults, $atts );
927 -
928 934 if ( $atts['default_email'] ) {
929 - $shortcode_atts = array(
935 + $shortcode_atts = array(
930 936 'format' => $atts['format'],
931 937 'plain_text' => $atts['plain_text'],
932 938 );
933 -
934 939 $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
935 - $formatted_entry = $entry_formatter->content();
940 + return $entry_formatter->content();
941 + }
936 942
937 - } else {
943 + $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
938 944
939 - $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
940 - $formatted_entry = $entry_formatter->get_formatted_entry_values();
941 -
942 - }
943 -
944 - return $formatted_entry;
945 + return $entry_formatter->get_formatted_entry_values();
945 946 }
946 947
947 948 /**
948 949 * @param false|object $entry
@@ -949,11 +950,10 @@
949 950 *
950 951 * @return void
951 952 */
952 953 public static function entry_sidebar( $entry = false ) {
953 - $data = array();
954 - $id = 0;
955 -
954 + $data = array();
955 + $id = 0;
956 956 $date_format = get_option( 'date_format' );
957 957 $time_format = get_option( 'time_format' );
958 958
959 959 if ( $entry ) {