PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.17
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.17
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 +122 -46 6.36.17 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
@@ -80,13 +150,14 @@
80 150
81 151 if ( $form_id ) {
82 152 self::get_columns_for_form( $form_id, $columns );
83 153 } else {
84 - $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' );
85 - $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' );
86 - $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' );
154 + $columns[ $form_id . '_form_id' ] = esc_html__( 'Form', 'formidable' );
155 + $columns[ $form_id . '_name' ] = esc_html__( 'Entry Name', 'formidable' );
156 + $columns[ $form_id . '_user_id' ] = esc_html__( 'Created By', 'formidable' );
87 157 }
88 158
159 + $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' );
89 160 $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
90 161 $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
91 162 self::maybe_add_ip_col( $form_id, $columns );
92 163
@@ -96,9 +167,9 @@
96 167 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
97 168 add_screen_option(
98 169 'per_page',
99 170 array(
100 - 'label' => __( 'Entries', 'formidable' ),
171 + 'label' => esc_html__( 'Entries', 'formidable' ),
101 172 'default' => 20,
102 173 'option' => 'formidable_page_formidable_entries_per_page',
103 174 )
104 175 );
@@ -124,9 +195,9 @@
124 195 if ( FrmField::is_no_save_field( $form_col->type ) ) {
125 196 continue;
126 197 }
127 198
128 - $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'] );
129 200 if ( $has_child_fields ) {
130 201 self::add_subform_cols( $form_col, $form_id, $columns );
131 202 } else {
132 203 self::add_field_cols( $form_col, $form_id, $columns );
@@ -162,9 +233,9 @@
162 233 $col_id .= '-_-form' . $field->form_id;
163 234 }
164 235
165 236 $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
166 - $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';
167 238 if ( $has_separate_value && ! $is_post_status ) {
168 239 $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
169 240 }
170 241
@@ -187,10 +258,10 @@
187 258 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
188 259 }
189 260
190 261 global $frm_vars;
191 - //add a check so we don't create a loop
192 - $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;
193 264
194 265 return $check;
195 266 }
196 267
@@ -204,9 +275,10 @@
204 275 }
205 276
206 277 global $frm_vars;
207 278 if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
208 - return; // Don't continue if there's no previous value.
279 + // Don't continue if there's no previous value.
280 + return;
209 281 }
210 282
211 283 foreach ( $meta_value as $mk => $mv ) {
212 284 // Remove blank values.
@@ -260,13 +332,15 @@
260 332 if ( empty( $menu_name ) ) {
261 333 $menu_name = FrmAppHelper::get_menu_name();
262 334 }
263 335
264 - return sanitize_title( $menu_name ) . '_page_formidable-entries';
336 + $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
337 +
338 + return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries';
265 339 }
266 340
267 341 public static function save_per_page( $save, $option, $value ) {
268 - if ( $option == 'formidable_page_formidable_entries_per_page' ) {
342 + if ( $option === 'formidable_page_formidable_entries_per_page' ) {
269 343 $save = (int) $value;
270 344 }
271 345
272 346 return $save;
@@ -284,8 +358,14 @@
284 358 $form_id . '_item_key' => 'item_key',
285 359 $form_id . '_is_draft' => 'is_draft',
286 360 );
287 361
362 + if ( ! $form_id ) {
363 + $columns[ $form_id . '_user_id' ] = 'user_id';
364 + $columns[ $form_id . '_name' ] = 'name';
365 + $columns[ $form_id . '_form_id' ] = 'form_id';
366 + }
367 +
288 368 foreach ( $fields as $field ) {
289 369 if ( self::field_supports_sorting( $field ) ) {
290 370 $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
291 371 }
@@ -350,9 +430,9 @@
350 430 foreach ( (array) $result as $r ) {
351 431 if ( ! empty( $r ) ) {
352 432 list( $form_prefix, $field_key ) = explode( '_', $r );
353 433
354 - if ( (int) $form_prefix == (int) $form_id ) {
434 + if ( (int) $form_prefix === (int) $form_id ) {
355 435 $hidden[] = $r;
356 436 }
357 437
358 438 unset( $form_prefix );
@@ -384,9 +464,9 @@
384 464 }
385 465
386 466 if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
387 467 $result[] = $col_key;
388 - $i--;
468 + --$i;
389 469 }
390 470
391 471 unset( $col_key, $col );
392 472 }
@@ -431,18 +511,20 @@
431 511 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
432 512 }
433 513
434 514 private static function get_delete_form_time( $form, &$errors ) {
435 - if ( 'trash' == $form->status ) {
515 + if ( 'trash' === $form->status ) {
436 516 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
437 - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
517 + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? $form->options['trash_time'] : time() ) );
438 518
439 519 /* translators: %1$s: Time string */
440 - $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 );
520 + $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 );
441 521 }
442 522 }
443 523
444 - /* Back End CRUD */
524 + /**
525 + * Back End CRUD.
526 + */
445 527 public static function show( $id = 0 ) {
446 528 FrmAppHelper::permission_check( 'frm_view_entries' );
447 529
448 530 if ( ! $id ) {
@@ -454,12 +536,15 @@
454 536 }
455 537
456 538 $entry = FrmEntry::getOne( $id, true );
457 539 if ( ! $entry ) {
458 - echo '<div id="form_show_entry_page" class="wrap">' .
459 - esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) .
460 - '</div>';
461 -
540 + FrmAppController::show_error_modal(
541 + array(
542 + 'title' => __( 'You can\'t view the entry', 'formidable' ),
543 + 'body' => __( 'You are trying to view an entry that does not exist', 'formidable' ),
544 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
545 + )
546 + );
462 547 return;
463 548 }
464 549
465 550 $data = $entry->description;
@@ -469,9 +554,9 @@
469 554
470 555 $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
471 556 $form = FrmForm::getOne( $entry->form_id );
472 557
473 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
558 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php';
474 559 }
475 560
476 561 /**
477 562 * Destroy an entry from the admin page.
@@ -481,9 +566,15 @@
481 566 */
482 567 public static function destroy() {
483 568 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
484 569 if ( false !== $permission_error ) {
485 - wp_die( esc_html( $permission_error ) );
570 + $error_args = array(
571 + 'title' => __( 'Verification failed', 'formidable' ),
572 + 'body' => $permission_error,
573 + 'cancel_url' => admin_url( 'admin.php?page=formidable-entries' ),
574 + );
575 + FrmAppController::show_error_modal( $error_args );
576 + return;
486 577 }
487 578
488 579 $params = FrmForm::get_admin_params();
489 580
@@ -498,18 +589,8 @@
498 589
499 590 self::display_list( $message );
500 591 }
501 592
502 - /**
503 - * @deprecated 4.02.04 - Moved to Pro since it was unused in Lite.
504 - */
505 - public static function destroy_all() {
506 - _deprecated_function( __METHOD__, '4.02.04', 'FrmProEntriesController::destroy_all' );
507 - if ( is_callable( 'FrmProEntriesController::destroy_all' ) ) {
508 - FrmProEntriesController::destroy_all();
509 - }
510 - }
511 -
512 593 public static function process_entry( $errors = '', $ajax = false ) {
513 594 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
514 595 if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
515 596 return;
@@ -616,9 +697,9 @@
616 697 FrmEntry::clear_cache();
617 698 }
618 699
619 700 /**
620 - * @param $atts
701 + * @param array $atts
621 702 *
622 703 * @return array|string
623 704 */
624 705 public static function show_entry_shortcode( $atts ) {
@@ -645,9 +726,10 @@
645 726 'exclude_fields' => '',
646 727 'include_fields' => '',
647 728 'include_extras' => '',
648 729 'inline_style' => 1,
649 - 'child_array' => false, // return embedded fields as nested array
730 + // Return embedded fields as nested array.
731 + 'child_array' => false,
650 732 'line_breaks' => true,
651 733 'array_separator' => ', ',
652 734 );
653 735 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
@@ -689,20 +771,14 @@
689 771 /**
690 772 * Add or remove information in the entry sidebar.
691 773 *
692 774 * @since 5.5.2
775 + *
693 776 * @param array $data
777 + * @param array{entry:\stdClass} $entry
694 778 */
695 779 $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) );
696 780 }
697 781
698 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' );
699 - }
700 -
701 - /**
702 - * @deprecated 4.0
703 - */
704 - public static function contextual_help( $help, $screen_id, $screen ) {
705 - _deprecated_function( __METHOD__, '4.0' );
706 - return $help;
782 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php';
707 783 }
708 784 }