PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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 +114 -41 6.56.16 View file →
@@ -9,11 +9,14 @@
9 9 FrmAppHelper::force_capability( 'frm_view_entries' );
10 10
11 11 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
12 12
13 - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed();
13 + $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed();
14 14 if ( ! $views_installed ) {
15 15 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' );
16 + self::maybe_redirect_to_views_upsell();
17 + } else {
18 + self::maybe_redirect_to_views_index();
16 19 }
17 20
18 21 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
19 22 self::load_manage_entries_hooks();
@@ -20,8 +23,73 @@
20 23 }
21 24 }
22 25
23 26 /**
27 + * This function is called when views is installed.
28 + * The Views add-on uses a different URL for the Views tab than the upsell page.
29 + * If the user is on the upsell page, instead of showing a permission error on reload,
30 + * redirect to the views index page.
31 + *
32 + * @since 6.14.1
33 + *
34 + * @return void
35 + */
36 + private static function maybe_redirect_to_views_index() {
37 + if ( ! FrmAppHelper::is_admin_page( 'formidable-views' ) ) {
38 + return;
39 + }
40 +
41 + $query_args = array(
42 + 'post_type' => 'frm_display',
43 + );
44 + $query_args = self::add_url_params_to_views_redirect_query_args( $query_args );
45 +
46 + wp_safe_redirect( add_query_arg( $query_args, admin_url( 'edit.php' ) ) );
47 + die();
48 + }
49 +
50 + /**
51 + * This function is called when views is inactive.
52 + * A user may deactivate views but then try to reload the views index.
53 + * Instead of showing a permission error, redirect to the views upsell page.
54 + *
55 + * @since 6.14.1
56 + *
57 + * @return void
58 + */
59 + private static function maybe_redirect_to_views_upsell() {
60 + global $pagenow;
61 + if ( 'edit.php' !== $pagenow || 'frm_display' !== FrmAppHelper::simple_get( 'post_type' ) ) {
62 + return;
63 + }
64 +
65 + $query_args = array(
66 + 'page' => 'formidable-views',
67 + );
68 + $query_args = self::add_url_params_to_views_redirect_query_args( $query_args );
69 +
70 + wp_safe_redirect( add_query_arg( $query_args, admin_url( 'admin.php' ) ) );
71 + die();
72 + }
73 +
74 + /**
75 + * @since 6.14.1
76 + *
77 + * @param array $query_args
78 + * @return array
79 + */
80 + private static function add_url_params_to_views_redirect_query_args( $query_args ) {
81 + $query_args['show_nav'] = FrmAppHelper::simple_get( 'show_nav', 'absint', 0 );
82 +
83 + $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
84 + if ( $form_id ) {
85 + $query_args['form'] = $form_id;
86 + }
87 +
88 + return $query_args;
89 + }
90 +
91 + /**
24 92 * @since 2.05.07
25 93 */
26 94 private static function load_manage_entries_hooks() {
27 95 if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
@@ -35,9 +103,11 @@
35 103 add_filter( 'screen_options_show_screen', __CLASS__ . '::remove_screen_options', 10, 2 );
36 104 }
37 105 }
38 106
39 - /* Display in Back End */
107 + /**
108 + * Display in Back End.
109 + */
40 110 public static function route() {
41 111 $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
42 112 FrmAppHelper::include_svg();
43 113
@@ -125,9 +195,9 @@
125 195 if ( FrmField::is_no_save_field( $form_col->type ) ) {
126 196 continue;
127 197 }
128 198
129 - $has_child_fields = $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] );
199 + $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] );
130 200 if ( $has_child_fields ) {
131 201 self::add_subform_cols( $form_col, $form_id, $columns );
132 202 } else {
133 203 self::add_field_cols( $form_col, $form_id, $columns );
@@ -163,9 +233,9 @@
163 233 $col_id .= '-_-form' . $field->form_id;
164 234 }
165 235
166 236 $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
167 - $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] == 'post_status';
237 + $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status';
168 238 if ( $has_separate_value && ! $is_post_status ) {
169 239 $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
170 240 }
171 241
@@ -188,10 +258,10 @@
188 258 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
189 259 }
190 260
191 261 global $frm_vars;
192 - //add a check so we don't create a loop
193 - $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
262 + // Add a check so we don't create a loop.
263 + $frm_vars['prev_hidden_cols'] = ! empty( $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
194 264
195 265 return $check;
196 266 }
197 267
@@ -205,9 +275,10 @@
205 275 }
206 276
207 277 global $frm_vars;
208 278 if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
209 - return; // Don't continue if there's no previous value.
279 + // Don't continue if there's no previous value.
280 + return;
210 281 }
211 282
212 283 foreach ( $meta_value as $mk => $mv ) {
213 284 // Remove blank values.
@@ -265,9 +336,9 @@
265 336 return sanitize_title( $menu_name ) . '_page_formidable-entries';
266 337 }
267 338
268 339 public static function save_per_page( $save, $option, $value ) {
269 - if ( $option == 'formidable_page_formidable_entries_per_page' ) {
340 + if ( $option === 'formidable_page_formidable_entries_per_page' ) {
270 341 $save = (int) $value;
271 342 }
272 343
273 344 return $save;
@@ -285,8 +356,14 @@
285 356 $form_id . '_item_key' => 'item_key',
286 357 $form_id . '_is_draft' => 'is_draft',
287 358 );
288 359
360 + if ( ! $form_id ) {
361 + $columns[ $form_id . '_user_id' ] = 'user_id';
362 + $columns[ $form_id . '_name' ] = 'name';
363 + $columns[ $form_id . '_form_id' ] = 'form_id';
364 + }
365 +
289 366 foreach ( $fields as $field ) {
290 367 if ( self::field_supports_sorting( $field ) ) {
291 368 $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
292 369 }
@@ -351,9 +428,9 @@
351 428 foreach ( (array) $result as $r ) {
352 429 if ( ! empty( $r ) ) {
353 430 list( $form_prefix, $field_key ) = explode( '_', $r );
354 431
355 - if ( (int) $form_prefix == (int) $form_id ) {
432 + if ( (int) $form_prefix === (int) $form_id ) {
356 433 $hidden[] = $r;
357 434 }
358 435
359 436 unset( $form_prefix );
@@ -385,9 +462,9 @@
385 462 }
386 463
387 464 if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
388 465 $result[] = $col_key;
389 - $i--;
466 + --$i;
390 467 }
391 468
392 469 unset( $col_key, $col );
393 470 }
@@ -432,18 +509,20 @@
432 509 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
433 510 }
434 511
435 512 private static function get_delete_form_time( $form, &$errors ) {
436 - if ( 'trash' == $form->status ) {
513 + if ( 'trash' === $form->status ) {
437 514 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
438 - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
515 + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? $form->options['trash_time'] : time() ) );
439 516
440 517 /* translators: %1$s: Time string */
441 - $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 );
518 + $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 );
442 519 }
443 520 }
444 521
445 - /* Back End CRUD */
522 + /**
523 + * Back End CRUD.
524 + */
446 525 public static function show( $id = 0 ) {
447 526 FrmAppHelper::permission_check( 'frm_view_entries' );
448 527
449 528 if ( ! $id ) {
@@ -455,12 +534,15 @@
455 534 }
456 535
457 536 $entry = FrmEntry::getOne( $id, true );
458 537 if ( ! $entry ) {
459 - echo '<div id="form_show_entry_page" class="wrap">' .
460 - esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) .
461 - '</div>';
462 -
538 + FrmAppController::show_error_modal(
539 + array(
540 + 'title' => __( 'You can\'t view the entry', 'formidable' ),
541 + 'body' => __( 'You are trying to view an entry that does not exist', 'formidable' ),
542 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
543 + )
544 + );
463 545 return;
464 546 }
465 547
466 548 $data = $entry->description;
@@ -470,9 +552,9 @@
470 552
471 553 $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
472 554 $form = FrmForm::getOne( $entry->form_id );
473 555
474 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
556 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php';
475 557 }
476 558
477 559 /**
478 560 * Destroy an entry from the admin page.
@@ -482,9 +564,15 @@
482 564 */
483 565 public static function destroy() {
484 566 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
485 567 if ( false !== $permission_error ) {
486 - wp_die( esc_html( $permission_error ) );
568 + $error_args = array(
569 + 'title' => __( 'Verification failed', 'formidable' ),
570 + 'body' => $permission_error,
571 + 'cancel_url' => admin_url( 'admin.php?page=formidable-entries' ),
572 + );
573 + FrmAppController::show_error_modal( $error_args );
574 + return;
487 575 }
488 576
489 577 $params = FrmForm::get_admin_params();
490 578
@@ -499,18 +587,8 @@
499 587
500 588 self::display_list( $message );
501 589 }
502 590
503 - /**
504 - * @deprecated 4.02.04 - Moved to Pro since it was unused in Lite.
505 - */
506 - public static function destroy_all() {
507 - _deprecated_function( __METHOD__, '4.02.04', 'FrmProEntriesController::destroy_all' );
508 - if ( is_callable( 'FrmProEntriesController::destroy_all' ) ) {
509 - FrmProEntriesController::destroy_all();
510 - }
511 - }
512 -
513 591 public static function process_entry( $errors = '', $ajax = false ) {
514 592 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
515 593 if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
516 594 return;
@@ -617,9 +695,9 @@
617 695 FrmEntry::clear_cache();
618 696 }
619 697
620 698 /**
621 - * @param $atts
699 + * @param array $atts
622 700 *
623 701 * @return array|string
624 702 */
625 703 public static function show_entry_shortcode( $atts ) {
@@ -646,9 +724,10 @@
646 724 'exclude_fields' => '',
647 725 'include_fields' => '',
648 726 'include_extras' => '',
649 727 'inline_style' => 1,
650 - 'child_array' => false, // return embedded fields as nested array
728 + // Return embedded fields as nested array.
729 + 'child_array' => false,
651 730 'line_breaks' => true,
652 731 'array_separator' => ', ',
653 732 );
654 733 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
@@ -690,20 +769,14 @@
690 769 /**
691 770 * Add or remove information in the entry sidebar.
692 771 *
693 772 * @since 5.5.2
773 + *
694 774 * @param array $data
775 + * @param array{entry:\stdClass} $entry
695 776 */
696 777 $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) );
697 778 }
698 779
699 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' );
700 - }
701 -
702 - /**
703 - * @deprecated 4.0
704 - */
705 - public static function contextual_help( $help, $screen_id, $screen ) {
706 - _deprecated_function( __METHOD__, '4.0' );
707 - return $help;
780 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php';
708 781 }
709 782 }