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
formidable / classes / controllers / FrmEntriesController.php

FrmEntriesController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.17, at classes/controllers/FrmEntriesController.php

785 lines 22.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmEntriesController {
7
8 public static function menu() {
9 FrmAppHelper::force_capability( 'frm_view_entries' );
10
11 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
12
13 $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed();
14 if ( ! $views_installed ) {
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();
19 }
20
21 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
22 self::load_manage_entries_hooks();
23 }
24 }
25
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 /**
92 * @since 2.05.07
93 */
94 private static function load_manage_entries_hooks() {
95 if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
96 $menu_name = FrmAppHelper::get_menu_name();
97 $base = self::base_column_key( $menu_name );
98
99 add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
100 add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
101 add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' );
102 } else {
103 add_filter( 'screen_options_show_screen', __CLASS__ . '::remove_screen_options', 10, 2 );
104 }
105 }
106
107 /**
108 * Display in Back End.
109 */
110 public static function route() {
111 $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
112 FrmAppHelper::include_svg();
113
114 switch ( $action ) {
115 case 'show':
116 case 'destroy':
117 return self::$action();
118
119 default:
120 do_action( 'frm_entry_action_route', $action );
121 if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
122 return;
123 }
124
125 return self::display_list();
126 }
127 }
128
129 /**
130 * Prevent the "screen options" tab from showing when
131 * editing or creating an entry
132 *
133 * @since 3.0
134 */
135 public static function remove_screen_options( $show_screen, $screen ) {
136 $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
137 if ( $screen->id == $menu_name . '_page_formidable-entries' ) {
138 $show_screen = false;
139 }
140
141 return $show_screen;
142 }
143
144 public static function manage_columns( $columns ) {
145 global $frm_vars;
146 $form_id = FrmForm::get_current_form_id();
147
148 $columns[ $form_id . '_id' ] = 'ID';
149 $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
150
151 if ( $form_id ) {
152 self::get_columns_for_form( $form_id, $columns );
153 } else {
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' );
157 }
158
159 $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' );
160 $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
161 $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
162 self::maybe_add_ip_col( $form_id, $columns );
163
164 $frm_vars['cols'] = $columns;
165
166 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
167 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
168 add_screen_option(
169 'per_page',
170 array(
171 'label' => esc_html__( 'Entries', 'formidable' ),
172 'default' => 20,
173 'option' => 'formidable_page_formidable_entries_per_page',
174 )
175 );
176 }
177
178 return $columns;
179 }
180
181 private static function get_columns_for_form( $form_id, &$columns ) {
182 $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
183
184 /**
185 * Allows changing fields in the Entries list table heading.
186 *
187 * @since 5.0.04
188 *
189 * @param array $fields Array of fields.
190 * @param array $args The arguments. Contains `form_id`.
191 */
192 $form_cols = apply_filters( 'frm_fields_in_entries_list_table', $form_cols, compact( 'form_id' ) );
193
194 foreach ( $form_cols as $form_col ) {
195 if ( FrmField::is_no_save_field( $form_col->type ) ) {
196 continue;
197 }
198
199 $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] );
200 if ( $has_child_fields ) {
201 self::add_subform_cols( $form_col, $form_id, $columns );
202 } else {
203 self::add_field_cols( $form_col, $form_id, $columns );
204 }
205 }
206 }
207
208 /**
209 * @since 3.01
210 */
211 private static function add_subform_cols( $field, $form_id, &$columns ) {
212 $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] );
213 if ( empty( $sub_form_cols ) ) {
214 return;
215 }
216
217 foreach ( $sub_form_cols as $k => $sub_form_col ) {
218 if ( FrmField::is_no_save_field( $sub_form_col->type ) ) {
219 unset( $sub_form_cols[ $k ] );
220 continue;
221 }
222 $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $field->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
223 unset( $sub_form_col );
224 }
225 }
226
227 /**
228 * @since 3.01
229 */
230 private static function add_field_cols( $field, $form_id, &$columns ) {
231 $col_id = $field->field_key;
232 if ( $field->form_id != $form_id ) {
233 $col_id .= '-_-form' . $field->form_id;
234 }
235
236 $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
237 $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status';
238 if ( $has_separate_value && ! $is_post_status ) {
239 $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
240 }
241
242 $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
243 }
244
245 private static function maybe_add_ip_col( $form_id, &$columns ) {
246 if ( FrmAppHelper::ips_saved() ) {
247 $columns[ $form_id . '_ip' ] = 'IP';
248 }
249 }
250
251 public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
252 $this_page_name = self::hidden_column_key();
253 if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
254 return $check;
255 }
256
257 if ( empty( $prev_value ) ) {
258 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
259 }
260
261 global $frm_vars;
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;
264
265 return $check;
266 }
267
268 /**
269 * Add hidden columns back from other forms
270 */
271 public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
272 $this_page_name = self::hidden_column_key();
273 if ( $meta_key != $this_page_name ) {
274 return;
275 }
276
277 global $frm_vars;
278 if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
279 // Don't continue if there's no previous value.
280 return;
281 }
282
283 foreach ( $meta_value as $mk => $mv ) {
284 // Remove blank values.
285 if ( empty( $mv ) ) {
286 unset( $meta_value[ $mk ] );
287 }
288 }
289
290 $cur_form_prefix = reset( $meta_value );
291 $cur_form_prefix = explode( '_', $cur_form_prefix );
292 $cur_form_prefix = $cur_form_prefix[0];
293 $save = false;
294
295 foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
296 if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
297 // Don't add blank cols or process included cols.
298 continue;
299 }
300
301 $form_prefix = explode( '_', $prev_hidden );
302 $form_prefix = $form_prefix[0];
303 if ( $form_prefix == $cur_form_prefix ) {
304 // Don't add back columns that are meant to be hidden.
305 continue;
306 }
307
308 $meta_value[] = $prev_hidden;
309 $save = true;
310 unset( $form_prefix );
311 }
312
313 if ( $save ) {
314 $user_id = get_current_user_id();
315 update_user_option( $user_id, $this_page_name, $meta_value, true );
316 }
317 }
318
319 /**
320 * @since 2.05.07
321 */
322 private static function hidden_column_key( $menu_name = '' ) {
323 $base = self::base_column_key( $menu_name );
324
325 return 'manage' . $base . 'columnshidden';
326 }
327
328 /**
329 * @since 2.05.07
330 */
331 private static function base_column_key( $menu_name = '' ) {
332 if ( empty( $menu_name ) ) {
333 $menu_name = FrmAppHelper::get_menu_name();
334 }
335
336 $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
337
338 return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries';
339 }
340
341 public static function save_per_page( $save, $option, $value ) {
342 if ( $option === 'formidable_page_formidable_entries_per_page' ) {
343 $save = (int) $value;
344 }
345
346 return $save;
347 }
348
349 public static function sortable_columns() {
350 $form_id = FrmForm::get_current_form_id();
351 $fields = FrmField::get_all_for_form( $form_id );
352
353 $columns = array(
354 $form_id . '_id' => 'id',
355 $form_id . '_created_at' => 'created_at',
356 $form_id . '_updated_at' => 'updated_at',
357 $form_id . '_ip' => 'ip',
358 $form_id . '_item_key' => 'item_key',
359 $form_id . '_is_draft' => 'is_draft',
360 );
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
368 foreach ( $fields as $field ) {
369 if ( self::field_supports_sorting( $field ) ) {
370 $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
371 }
372 }
373
374 return $columns;
375 }
376
377 /**
378 * Can't sort on checkboxes because they are sorted serialized.
379 * Some post content can be sorted but not everything.
380 *
381 * @param stdClass $field
382 * @return bool
383 */
384 private static function field_supports_sorting( $field ) {
385 $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] );
386 return apply_filters( 'frm_field_column_is_sortable', $is_sortable, $field );
387 }
388
389 /**
390 * @param mixed $result Option value from database for hidden columns in entries table.
391 * @return array
392 */
393 public static function hidden_columns( $result ) {
394 if ( ! is_array( $result ) ) {
395 // Force an unexpected value to be an array.
396 // Since $result is a filtered option and gets saved to the database, it's possible it could be a string.
397 // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error.
398 $result = array();
399 }
400
401 $form_id = FrmForm::get_current_form_id();
402
403 $hidden = self::user_hidden_columns_for_form( $form_id, $result );
404
405 global $frm_vars;
406 $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
407
408 if ( ! empty( $hidden ) ) {
409 $result = $hidden;
410 $i = $i - count( $result );
411 $max_columns = 11;
412 } else {
413 $max_columns = 8;
414 }
415
416 if ( $i <= $max_columns ) {
417 return $result;
418 }
419
420 self::remove_excess_cols( compact( 'i', 'max_columns', 'form_id' ), $result );
421
422 return $result;
423 }
424
425 /**
426 * @since 2.05.07
427 */
428 private static function user_hidden_columns_for_form( $form_id, $result ) {
429 $hidden = array();
430 foreach ( (array) $result as $r ) {
431 if ( ! empty( $r ) ) {
432 list( $form_prefix, $field_key ) = explode( '_', $r );
433
434 if ( (int) $form_prefix === (int) $form_id ) {
435 $hidden[] = $r;
436 }
437
438 unset( $form_prefix );
439 }
440 }
441
442 return $hidden;
443 }
444
445 /**
446 * Remove some columns by default when there are too many
447 *
448 * @since 2.05.07
449 */
450 private static function remove_excess_cols( $atts, &$result ) {
451 global $frm_vars;
452
453 $remove_first = array(
454 $atts['form_id'] . '_item_key' => '',
455 $atts['form_id'] . '_id' => '',
456 );
457 $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
458
459 $i = $atts['i'];
460
461 foreach ( $cols as $col_key => $col ) {
462 if ( $i <= $atts['max_columns'] ) {
463 break;
464 }
465
466 if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
467 $result[] = $col_key;
468 --$i;
469 }
470
471 unset( $col_key, $col );
472 }
473 }
474
475 public static function display_list( $message = '', $errors = array() ) {
476 global $wpdb, $frm_vars;
477
478 $form = FrmForm::maybe_get_current_form();
479 $params = FrmForm::get_admin_params( $form );
480
481 if ( $form ) {
482 $params['form'] = $form->id;
483 $frm_vars['current_form'] = $form;
484
485 self::get_delete_form_time( $form, $errors );
486 }
487
488 $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
489
490 $wp_list_table = new $table_class( array( 'params' => $params ) );
491
492 $pagenum = $wp_list_table->get_pagenum();
493
494 $wp_list_table->prepare_items();
495
496 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
497 if ( $pagenum > $total_pages && $total_pages > 0 ) {
498 $url = add_query_arg( 'paged', $total_pages );
499 if ( headers_sent() ) {
500 FrmAppHelper::js_redirect( $url, true );
501 } else {
502 wp_redirect( esc_url_raw( $url ) );
503 }
504 die();
505 }
506
507 if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
508 $message = __( 'Your import is complete', 'formidable' );
509 }
510
511 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
512 }
513
514 private static function get_delete_form_time( $form, &$errors ) {
515 if ( 'trash' === $form->status ) {
516 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
517 $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? $form->options['trash_time'] : time() ) );
518
519 /* translators: %1$s: Time string */
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 );
521 }
522 }
523
524 /**
525 * Back End CRUD.
526 */
527 public static function show( $id = 0 ) {
528 FrmAppHelper::permission_check( 'frm_view_entries' );
529
530 if ( ! $id ) {
531 $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
532
533 if ( ! $id ) {
534 $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' );
535 }
536 }
537
538 $entry = FrmEntry::getOne( $id, true );
539 if ( ! $entry ) {
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 );
547 return;
548 }
549
550 $data = $entry->description;
551 if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
552 $data = array( 'referrer' => $data );
553 }
554
555 $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
556 $form = FrmForm::getOne( $entry->form_id );
557
558 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php';
559 }
560
561 /**
562 * Destroy an entry from the admin page.
563 * This is triggered from the entries list from the "Delete" row action, and also from the "Delete Entry" trigger in the view/edit entry sidebar.
564 *
565 * @return void
566 */
567 public static function destroy() {
568 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
569 if ( false !== $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;
577 }
578
579 $params = FrmForm::get_admin_params();
580
581 if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
582 self::unlink_post( $params['id'] );
583 }
584
585 $message = '';
586 if ( FrmEntry::destroy( $params['id'] ) ) {
587 $message = __( 'Entry was successfully deleted', 'formidable' );
588 }
589
590 self::display_list( $message );
591 }
592
593 public static function process_entry( $errors = '', $ajax = false ) {
594 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
595 if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
596 return;
597 }
598
599 global $frm_vars;
600
601 $form = FrmForm::getOne( $form_id );
602 if ( ! $form ) {
603 return;
604 }
605
606 $params = FrmForm::get_params( $form );
607
608 if ( ! isset( $frm_vars['form_params'] ) ) {
609 $frm_vars['form_params'] = array();
610 }
611 $frm_vars['form_params'][ $form->id ] = $params;
612
613 if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
614 return;
615 }
616
617 if ( $errors == '' && ! $ajax ) {
618 $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
619 }
620
621 /**
622 * Use this filter to add trigger actions and add errors after
623 * all other errors have been processed
624 *
625 * @since 2.0.6
626 */
627 $errors = apply_filters( 'frm_entries_before_create', $errors, $form );
628
629 $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
630
631 if ( empty( $errors ) ) {
632 $_POST['frm_skip_cookie'] = 1;
633 $do_success = false;
634 if ( $params['action'] === 'create' ) {
635 if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
636 $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
637
638 $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
639 $do_success = true;
640 }
641 }
642
643 do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
644 if ( $do_success ) {
645 FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
646 }
647 unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
648 }
649 }
650
651 /**
652 * Escape url entities before redirect
653 *
654 * @since 3.0
655 *
656 * @param string $url
657 *
658 * @return string
659 */
660 public static function prepare_redirect_url( $url ) {
661 return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
662 }
663
664 public static function delete_entry_before_redirect( $url, $form, $atts ) {
665 self::_delete_entry( $atts['id'], $form );
666
667 return $url;
668 }
669
670 /**
671 * Delete entry if not redirected.
672 *
673 * @param array $atts
674 */
675 public static function delete_entry_after_save( $atts ) {
676 self::_delete_entry( $atts['entry_id'], $atts['form'] );
677 }
678
679 private static function _delete_entry( $entry_id, $form ) {
680 if ( ! $form ) {
681 return;
682 }
683
684 FrmAppHelper::unserialize_or_decode( $form->options );
685 if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
686 self::unlink_post( $entry_id );
687 FrmEntry::destroy( $entry_id );
688 }
689 }
690
691 /**
692 * Unlink entry from post
693 */
694 private static function unlink_post( $entry_id ) {
695 global $wpdb;
696 $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) );
697 FrmEntry::clear_cache();
698 }
699
700 /**
701 * @param array $atts
702 *
703 * @return array|string
704 */
705 public static function show_entry_shortcode( $atts ) {
706 $defaults = array(
707 'id' => false,
708 'entry' => false,
709 'fields' => false,
710 'plain_text' => false,
711 'user_info' => false,
712 'include_blank' => false,
713 'default_email' => false,
714 'form_id' => false,
715 'format' => 'text',
716 'array_key' => 'key',
717 'direction' => 'ltr',
718 'font_size' => '',
719 'text_color' => '',
720 'border_width' => '',
721 'border_color' => '',
722 'bg_color' => '',
723 'alt_bg_color' => '',
724 'class' => '',
725 'clickable' => false,
726 'exclude_fields' => '',
727 'include_fields' => '',
728 'include_extras' => '',
729 'inline_style' => 1,
730 // Return embedded fields as nested array.
731 'child_array' => false,
732 'line_breaks' => true,
733 'array_separator' => ', ',
734 );
735 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
736
737 $atts = shortcode_atts( $defaults, $atts );
738
739 if ( $atts['default_email'] ) {
740 $shortcode_atts = array(
741 'format' => $atts['format'],
742 'plain_text' => $atts['plain_text'],
743 );
744
745 $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
746 $formatted_entry = $entry_formatter->content();
747
748 } else {
749
750 $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
751 $formatted_entry = $entry_formatter->get_formatted_entry_values();
752
753 }
754
755 return $formatted_entry;
756 }
757
758 public static function entry_sidebar( $entry = false ) {
759 $data = array();
760 $id = 0;
761
762 $date_format = get_option( 'date_format' );
763 $time_format = get_option( 'time_format' );
764
765 if ( $entry ) {
766 $id = $entry->id;
767 $data = $entry->description;
768 if ( isset( $data['browser'] ) ) {
769 $browser = FrmEntriesHelper::get_browser( $data['browser'] );
770 }
771 /**
772 * Add or remove information in the entry sidebar.
773 *
774 * @since 5.5.2
775 *
776 * @param array $data
777 * @param array{entry:\stdClass} $entry
778 */
779 $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) );
780 }
781
782 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php';
783 }
784 }
785