PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.24
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.24
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 +138 -55 6.5.26.24 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
@@ -62,10 +132,12 @@
62 132 *
63 133 * @since 3.0
64 134 */
65 135 public static function remove_screen_options( $show_screen, $screen ) {
66 - $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
67 - if ( $screen->id == $menu_name . '_page_formidable-entries' ) {
136 + $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
137 + $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
138 +
139 + if ( $screen->id === $menu_name . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries' ) {
68 140 $show_screen = false;
69 141 }
70 142
71 143 return $show_screen;
@@ -125,9 +197,9 @@
125 197 if ( FrmField::is_no_save_field( $form_col->type ) ) {
126 198 continue;
127 199 }
128 200
129 - $has_child_fields = $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] );
201 + $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] );
130 202 if ( $has_child_fields ) {
131 203 self::add_subform_cols( $form_col, $form_id, $columns );
132 204 } else {
133 205 self::add_field_cols( $form_col, $form_id, $columns );
@@ -163,9 +235,9 @@
163 235 $col_id .= '-_-form' . $field->form_id;
164 236 }
165 237
166 238 $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';
239 + $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status';
168 240 if ( $has_separate_value && ! $is_post_status ) {
169 241 $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
170 242 }
171 243
@@ -188,10 +260,10 @@
188 260 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
189 261 }
190 262
191 263 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;
264 + // Add a check so we don't create a loop.
265 + $frm_vars['prev_hidden_cols'] = ! empty( $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
194 266
195 267 return $check;
196 268 }
197 269
@@ -205,9 +277,10 @@
205 277 }
206 278
207 279 global $frm_vars;
208 280 if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
209 - return; // Don't continue if there's no previous value.
281 + // Don't continue if there's no previous value.
282 + return;
210 283 }
211 284
212 285 foreach ( $meta_value as $mk => $mv ) {
213 286 // Remove blank values.
@@ -261,13 +334,15 @@
261 334 if ( empty( $menu_name ) ) {
262 335 $menu_name = FrmAppHelper::get_menu_name();
263 336 }
264 337
265 - return sanitize_title( $menu_name ) . '_page_formidable-entries';
338 + $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
339 +
340 + return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries';
266 341 }
267 342
268 343 public static function save_per_page( $save, $option, $value ) {
269 - if ( $option == 'formidable_page_formidable_entries_per_page' ) {
344 + if ( $option === 'formidable_page_formidable_entries_per_page' ) {
270 345 $save = (int) $value;
271 346 }
272 347
273 348 return $save;
@@ -285,8 +360,14 @@
285 360 $form_id . '_item_key' => 'item_key',
286 361 $form_id . '_is_draft' => 'is_draft',
287 362 );
288 363
364 + if ( ! $form_id ) {
365 + $columns[ $form_id . '_user_id' ] = 'user_id';
366 + $columns[ $form_id . '_name' ] = 'name';
367 + $columns[ $form_id . '_form_id' ] = 'form_id';
368 + }
369 +
289 370 foreach ( $fields as $field ) {
290 371 if ( self::field_supports_sorting( $field ) ) {
291 372 $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
292 373 }
@@ -311,8 +392,10 @@
311 392 * @param mixed $result Option value from database for hidden columns in entries table.
312 393 * @return array
313 394 */
314 395 public static function hidden_columns( $result ) {
396 + global $frm_vars;
397 +
315 398 if ( ! is_array( $result ) ) {
316 399 // Force an unexpected value to be an array.
317 400 // Since $result is a filtered option and gets saved to the database, it's possible it could be a string.
318 401 // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error.
@@ -318,21 +401,16 @@
318 401 // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error.
319 402 $result = array();
320 403 }
321 404
322 - $form_id = FrmForm::get_current_form_id();
405 + $form_id = FrmForm::get_current_form_id();
406 + $hidden = self::user_hidden_columns_for_form( $form_id, $result );
407 + $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
408 + $max_columns = 11;
323 409
324 - $hidden = self::user_hidden_columns_for_form( $form_id, $result );
325 -
326 - global $frm_vars;
327 - $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
328 -
329 410 if ( ! empty( $hidden ) ) {
330 - $result = $hidden;
331 - $i = $i - count( $result );
332 - $max_columns = 11;
333 - } else {
334 - $max_columns = 8;
411 + $result = $hidden;
412 + $i = $i - count( $result );
335 413 }
336 414
337 415 if ( $i <= $max_columns ) {
338 416 return $result;
@@ -351,9 +429,9 @@
351 429 foreach ( (array) $result as $r ) {
352 430 if ( ! empty( $r ) ) {
353 431 list( $form_prefix, $field_key ) = explode( '_', $r );
354 432
355 - if ( (int) $form_prefix == (int) $form_id ) {
433 + if ( (int) $form_prefix === (int) $form_id ) {
356 434 $hidden[] = $r;
357 435 }
358 436
359 437 unset( $form_prefix );
@@ -366,8 +444,12 @@
366 444 /**
367 445 * Remove some columns by default when there are too many
368 446 *
369 447 * @since 2.05.07
448 + *
449 + * @param array $atts
450 + * @param array $result
451 + * @return void
370 452 */
371 453 private static function remove_excess_cols( $atts, &$result ) {
372 454 global $frm_vars;
373 455
@@ -385,9 +467,9 @@
385 467 }
386 468
387 469 if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
388 470 $result[] = $col_key;
389 - $i--;
471 + --$i;
390 472 }
391 473
392 474 unset( $col_key, $col );
393 475 }
@@ -432,18 +514,20 @@
432 514 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
433 515 }
434 516
435 517 private static function get_delete_form_time( $form, &$errors ) {
436 - if ( 'trash' == $form->status ) {
518 + if ( 'trash' === $form->status ) {
437 519 $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() ) );
520 + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? $form->options['trash_time'] : time() ) );
439 521
440 522 /* 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 );
523 + $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 524 }
443 525 }
444 526
445 - /* Back End CRUD */
527 + /**
528 + * Back End CRUD.
529 + */
446 530 public static function show( $id = 0 ) {
447 531 FrmAppHelper::permission_check( 'frm_view_entries' );
448 532
449 533 if ( ! $id ) {
@@ -455,12 +539,15 @@
455 539 }
456 540
457 541 $entry = FrmEntry::getOne( $id, true );
458 542 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 -
543 + FrmAppController::show_error_modal(
544 + array(
545 + 'title' => __( 'You can\'t view the entry', 'formidable' ),
546 + 'body' => __( 'You are trying to view an entry that does not exist', 'formidable' ),
547 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
548 + )
549 + );
463 550 return;
464 551 }
465 552
466 553 $data = $entry->description;
@@ -470,9 +557,9 @@
470 557
471 558 $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
472 559 $form = FrmForm::getOne( $entry->form_id );
473 560
474 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
561 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php';
475 562 }
476 563
477 564 /**
478 565 * Destroy an entry from the admin page.
@@ -482,9 +569,15 @@
482 569 */
483 570 public static function destroy() {
484 571 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
485 572 if ( false !== $permission_error ) {
486 - wp_die( esc_html( $permission_error ) );
573 + $error_args = array(
574 + 'title' => __( 'Verification failed', 'formidable' ),
575 + 'body' => $permission_error,
576 + 'cancel_url' => admin_url( 'admin.php?page=formidable-entries' ),
577 + );
578 + FrmAppController::show_error_modal( $error_args );
579 + return;
487 580 }
488 581
489 582 $params = FrmForm::get_admin_params();
490 583
@@ -499,18 +592,8 @@
499 592
500 593 self::display_list( $message );
501 594 }
502 595
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 596 public static function process_entry( $errors = '', $ajax = false ) {
514 597 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
515 598 if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
516 599 return;
@@ -522,8 +605,13 @@
522 605 if ( ! $form ) {
523 606 return;
524 607 }
525 608
609 + $is_preview = 'frm_forms_preview' === FrmAppHelper::simple_get( 'action' );
610 + if ( $is_preview && FrmFormsHelper::should_block_preview( $form->form_key ) ) {
611 + return;
612 + }
613 +
526 614 $params = FrmForm::get_params( $form );
527 615
528 616 if ( ! isset( $frm_vars['form_params'] ) ) {
529 617 $frm_vars['form_params'] = array();
@@ -617,9 +705,9 @@
617 705 FrmEntry::clear_cache();
618 706 }
619 707
620 708 /**
621 - * @param $atts
709 + * @param array $atts
622 710 *
623 711 * @return array|string
624 712 */
625 713 public static function show_entry_shortcode( $atts ) {
@@ -646,9 +734,10 @@
646 734 'exclude_fields' => '',
647 735 'include_fields' => '',
648 736 'include_extras' => '',
649 737 'inline_style' => 1,
650 - 'child_array' => false, // return embedded fields as nested array
738 + // Return embedded fields as nested array.
739 + 'child_array' => false,
651 740 'line_breaks' => true,
652 741 'array_separator' => ', ',
653 742 );
654 743 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
@@ -690,20 +779,14 @@
690 779 /**
691 780 * Add or remove information in the entry sidebar.
692 781 *
693 782 * @since 5.5.2
783 + *
694 784 * @param array $data
785 + * @param array{entry:\stdClass} $entry
695 786 */
696 787 $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) );
697 788 }
698 789
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;
790 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php';
708 791 }
709 792 }