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 +257 -93 6.25.1 → trunk View file →
@@ -4,19 +4,23 @@
4 4 }
5 5
6 6 class FrmEntriesController {
7 7
8 + /**
9 + * @return void
10 + */
8 11 public static function menu() {
9 12 FrmAppHelper::force_capability( 'frm_view_entries' );
10 13
11 - 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
12 15
13 16 $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' );
17 +
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
16 22 self::maybe_redirect_to_views_upsell();
17 - } else {
18 - self::maybe_redirect_to_views_index();
19 23 }
20 24
21 25 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
22 26 self::load_manage_entries_hooks();
@@ -57,8 +61,9 @@
57 61 * @return void
58 62 */
59 63 private static function maybe_redirect_to_views_upsell() {
60 64 global $pagenow;
65 +
61 66 if ( 'edit.php' !== $pagenow || 'frm_display' !== FrmAppHelper::simple_get( 'post_type' ) ) {
62 67 return;
63 68 }
64 69
@@ -74,14 +79,15 @@
74 79 /**
75 80 * @since 6.14.1
76 81 *
77 82 * @param array $query_args
83 + *
78 84 * @return array
79 85 */
80 86 private static function add_url_params_to_views_redirect_query_args( $query_args ) {
81 87 $query_args['show_nav'] = FrmAppHelper::simple_get( 'show_nav', 'absint', 0 );
88 + $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
82 89
83 - $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
84 90 if ( $form_id ) {
85 91 $query_args['form'] = $form_id;
86 92 }
87 93
@@ -89,24 +95,29 @@
89 95 }
90 96
91 97 /**
92 98 * @since 2.05.07
99 + *
100 + * @return void
93 101 */
94 102 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 + if ( in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
103 104 add_filter( 'screen_options_show_screen', self::class . '::remove_screen_options', 10, 2 );
105 + return;
104 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' );
105 114 }
106 115
107 116 /**
108 117 * Display in Back End.
118 + *
119 + * @return mixed
109 120 */
110 121 public static function route() {
111 122 $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
112 123 FrmAppHelper::include_svg();
@@ -117,13 +128,15 @@
117 128 return self::$action();
118 129
119 130 default:
120 131 do_action( 'frm_entry_action_route', $action );
132 +
121 133 if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
122 - return;
134 + return null;
123 135 }
124 136
125 - return self::display_list();
137 + self::display_list();
138 + return null;
126 139 }
127 140 }
128 141
129 142 /**
@@ -130,8 +143,13 @@
130 143 * Prevent the "screen options" tab from showing when
131 144 * editing or creating an entry
132 145 *
133 146 * @since 3.0
147 + *
148 + * @param bool $show_screen Whether to show the screen options tab.
149 + * @param object $screen The current screen object.
150 + *
151 + * @return bool
134 152 */
135 153 public static function remove_screen_options( $show_screen, $screen ) {
136 154 $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
137 155 $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
@@ -136,14 +154,19 @@
136 154 $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
137 155 $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
138 156
139 157 if ( $screen->id === $menu_name . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries' ) {
140 - $show_screen = false;
158 + return false;
141 159 }
142 160
143 161 return $show_screen;
144 162 }
145 163
164 + /**
165 + * @param array $columns
166 + *
167 + * @return array
168 + */
146 169 public static function manage_columns( $columns ) {
147 170 global $frm_vars;
148 171 $form_id = FrmForm::get_current_form_id();
149 172
@@ -158,16 +181,16 @@
158 181 $columns[ $form_id . '_user_id' ] = esc_html__( 'Created By', 'formidable' );
159 182 }
160 183
161 184 $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' );
162 - $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
163 - $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' );
164 187 self::maybe_add_ip_col( $form_id, $columns );
165 188
166 189 $frm_vars['cols'] = $columns;
190 + $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
167 191
168 - $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
169 - 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 ) ) {
170 193 add_screen_option(
171 194 'per_page',
172 195 array(
173 196 'label' => esc_html__( 'Entries', 'formidable' ),
@@ -179,8 +202,14 @@
179 202
180 203 return $columns;
181 204 }
182 205
206 + /**
207 + * @param int|string $form_id
208 + * @param array $columns
209 + *
210 + * @return void
211 + */
183 212 private static function get_columns_for_form( $form_id, &$columns ) {
184 213 $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
185 214
186 215 /**
@@ -198,8 +227,9 @@
198 227 continue;
199 228 }
200 229
201 230 $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] );
231 +
202 232 if ( $has_child_fields ) {
203 233 self::add_subform_cols( $form_col, $form_id, $columns );
204 234 } else {
205 235 self::add_field_cols( $form_col, $form_id, $columns );
@@ -208,12 +238,19 @@
208 238 }
209 239
210 240 /**
211 241 * @since 3.01
242 + *
243 + * @param object $field The field object.
244 + * @param int|string $form_id The form ID.
245 + * @param array $columns The columns array.
246 + *
247 + * @return void
212 248 */
213 249 private static function add_subform_cols( $field, $form_id, &$columns ) {
214 250 $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] );
215 - if ( empty( $sub_form_cols ) ) {
251 +
252 + if ( ! $sub_form_cols ) {
216 253 return;
217 254 }
218 255
219 256 foreach ( $sub_form_cols as $k => $sub_form_col ) {
@@ -220,8 +257,9 @@
220 257 if ( FrmField::is_no_save_field( $sub_form_col->type ) ) {
221 258 unset( $sub_form_cols[ $k ] );
222 259 continue;
223 260 }
261 +
224 262 $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $field->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
225 263 unset( $sub_form_col );
226 264 }
227 265 }
@@ -227,12 +265,19 @@
227 265 }
228 266
229 267 /**
230 268 * @since 3.01
269 + *
270 + * @param object $field The field object.
271 + * @param int|string $form_id The form ID.
272 + * @param array $columns The columns array.
273 + *
274 + * @return void
231 275 */
232 276 private static function add_field_cols( $field, $form_id, &$columns ) {
233 277 $col_id = $field->field_key;
234 - if ( $field->form_id != $form_id ) {
278 +
279 + if ( (int) $field->form_id !== (int) $form_id ) {
235 280 $col_id .= '-_-form' . $field->form_id;
236 281 }
237 282
238 283 $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
@@ -237,8 +282,9 @@
237 282
238 283 $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
239 284 $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status';
240 285 $include_column_for_sep_val = $has_separate_value && ! $is_post_status;
286 +
241 287 if ( $include_column_for_sep_val ) {
242 288 $columns[ $form_id . '_frmsep_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val );
243 289 }
244 290
@@ -257,16 +303,24 @@
257 303 * @return string
258 304 */
259 305 private static function maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, $is_value = true ) {
260 306 $field_name = FrmAppHelper::truncate( $field->name, 35 );
261 - if ( ! $include_column_for_sep_val || ! in_array( $field->type, array( 'select', 'radio', 'checkbox' ), true ) ) {
307 +
308 + if ( ! $include_column_for_sep_val || ! in_array( $field->type, array( 'select', 'radio', 'checkbox', 'product', 'ranking' ), true ) ) {
262 309 return $field_name;
263 310 }
311 +
264 312 $append_text = $is_value ? esc_html__( 'value', 'formidable' ) : esc_html__( 'label', 'formidable' );
265 313
266 314 return sprintf( '%s (%s)', $field_name, $append_text );
267 315 }
268 316
317 + /**
318 + * @param int|string $form_id The form ID.
319 + * @param array $columns The columns array.
320 + *
321 + * @return void
322 + */
269 323 private static function maybe_add_ip_col( $form_id, &$columns ) {
270 324 if ( FrmAppHelper::ips_saved() ) {
271 325 $columns[ $form_id . '_ip' ] = 'IP';
272 326 }
@@ -271,15 +325,26 @@
271 325 $columns[ $form_id . '_ip' ] = 'IP';
272 326 }
273 327 }
274 328
329 + /**
330 + * @param bool $check The check value.
331 + * @param int $object_id The object ID.
332 + * @param string $meta_key The meta key.
333 + * @param mixed $meta_value The meta value.
334 + * @param mixed $prev_value The previous value.
335 + *
336 + * @return bool
337 + */
275 338 public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
276 339 $this_page_name = self::hidden_column_key();
340 +
341 + // phpcs:ignore Universal.Operators.StrictComparisons
277 342 if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
278 343 return $check;
279 344 }
280 345
281 - if ( empty( $prev_value ) ) {
346 + if ( ! $prev_value ) {
282 347 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
283 348 }
284 349
285 350 global $frm_vars;
@@ -290,17 +355,27 @@
290 355 }
291 356
292 357 /**
293 358 * Add hidden columns back from other forms
359 + *
360 + * @param int $meta_id The meta ID.
361 + * @param int $object_id The object ID.
362 + * @param string $meta_key The meta key.
363 + * @param array $meta_value The meta value.
364 + *
365 + * @return void
294 366 */
295 367 public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
296 368 $this_page_name = self::hidden_column_key();
369 +
370 + // phpcs:ignore Universal.Operators.StrictComparisons
297 371 if ( $meta_key != $this_page_name ) {
298 372 return;
299 373 }
300 374
301 375 global $frm_vars;
302 - if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
376 +
377 + if ( empty( $frm_vars['prev_hidden_cols'] ) ) {
303 378 // Don't continue if there's no previous value.
304 379 return;
305 380 }
306 381
@@ -305,9 +380,9 @@
305 380 }
306 381
307 382 foreach ( $meta_value as $mk => $mv ) {
308 383 // Remove blank values.
309 - if ( empty( $mv ) ) {
384 + if ( ! $mv ) {
310 385 unset( $meta_value[ $mk ] );
311 386 }
312 387 }
313 388
@@ -316,9 +391,10 @@
316 391 $cur_form_prefix = $cur_form_prefix[0];
317 392 $save = false;
318 393
319 394 foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
320 - 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 ) ) {
321 397 // Don't add blank cols or process included cols.
322 398 continue;
323 399 }
324 400
@@ -323,9 +399,10 @@
323 399 }
324 400
325 401 $form_prefix = explode( '_', $prev_hidden );
326 402 $form_prefix = $form_prefix[0];
327 - if ( $form_prefix == $cur_form_prefix ) {
403 +
404 + if ( $form_prefix === $cur_form_prefix ) {
328 405 // Don't add back columns that are meant to be hidden.
329 406 continue;
330 407 }
331 408
@@ -333,28 +410,36 @@
333 410 $save = true;
334 411 unset( $form_prefix );
335 412 }
336 413
337 - if ( $save ) {
338 - $user_id = get_current_user_id();
339 - update_user_option( $user_id, $this_page_name, $meta_value, true );
414 + if ( ! $save ) {
415 + return;
340 416 }
417 +
418 + update_user_option( get_current_user_id(), $this_page_name, $meta_value, true );
341 419 }
342 420
343 421 /**
344 422 * @since 2.05.07
423 + *
424 + * @param string $menu_name
425 + *
426 + * @return string
345 427 */
346 428 private static function hidden_column_key( $menu_name = '' ) {
347 429 $base = self::base_column_key( $menu_name );
348 -
349 430 return 'manage' . $base . 'columnshidden';
350 431 }
351 432
352 433 /**
353 434 * @since 2.05.07
435 + *
436 + * @param string $menu_name
437 + *
438 + * @return string
354 439 */
355 440 private static function base_column_key( $menu_name = '' ) {
356 - if ( empty( $menu_name ) ) {
441 + if ( ! $menu_name ) {
357 442 $menu_name = FrmAppHelper::get_menu_name();
358 443 }
359 444
360 445 $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
@@ -361,16 +446,26 @@
361 446
362 447 return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries';
363 448 }
364 449
450 + /**
451 + * @param int $save
452 + * @param string $option
453 + * @param string $value
454 + *
455 + * @return int
456 + */
365 457 public static function save_per_page( $save, $option, $value ) {
366 458 if ( $option === 'formidable_page_formidable_entries_per_page' ) {
367 - $save = (int) $value;
459 + return (int) $value;
368 460 }
369 461
370 462 return $save;
371 463 }
372 464
465 + /**
466 + * @return array
467 + */
373 468 public static function sortable_columns() {
374 469 $form_id = FrmForm::get_current_form_id();
375 470 $fields = FrmField::get_all_for_form( $form_id );
376 471
@@ -402,8 +497,9 @@
402 497 * Can't sort on checkboxes because they are sorted serialized.
403 498 * Some post content can be sorted but not everything.
404 499 *
405 500 * @param stdClass $field
501 + *
406 502 * @return bool
407 503 */
408 504 private static function field_supports_sorting( $field ) {
409 505 $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] );
@@ -411,8 +507,9 @@
411 507 }
412 508
413 509 /**
414 510 * @param mixed $result Option value from database for hidden columns in entries table.
511 + *
415 512 * @return array
416 513 */
417 514 public static function hidden_columns( $result ) {
418 515 global $frm_vars;
@@ -428,9 +525,9 @@
428 525 $hidden = self::user_hidden_columns_for_form( $form_id, $result );
429 526 $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
430 527 $max_columns = 11;
431 528
432 - if ( ! empty( $hidden ) ) {
529 + if ( $hidden ) {
433 530 $result = $hidden;
434 531 $i = $i - count( $result );
435 532 }
436 533
@@ -444,21 +541,29 @@
444 541 }
445 542
446 543 /**
447 544 * @since 2.05.07
545 + *
546 + * @param int|string $form_id
547 + * @param mixed $result
548 + *
549 + * @return array
448 550 */
449 551 private static function user_hidden_columns_for_form( $form_id, $result ) {
450 552 $hidden = array();
553 +
451 554 foreach ( (array) $result as $r ) {
452 - if ( ! empty( $r ) ) {
453 - list( $form_prefix, $field_key ) = explode( '_', $r );
555 + if ( ! $r ) {
556 + continue;
557 + }
454 558
455 - if ( (int) $form_prefix === (int) $form_id ) {
456 - $hidden[] = $r;
457 - }
559 + list( $form_prefix, $field_key ) = explode( '_', $r );
458 560
459 - unset( $form_prefix );
561 + if ( (int) $form_prefix === (int) $form_id ) {
562 + $hidden[] = $r;
460 563 }
564 +
565 + unset( $form_prefix );
461 566 }
462 567
463 568 return $hidden;
464 569 }
@@ -469,8 +574,9 @@
469 574 * @since 2.05.07
470 575 *
471 576 * @param array $atts
472 577 * @param array $result
578 + *
473 579 * @return void
474 580 */
475 581 private static function remove_excess_cols( $atts, &$result ) {
476 582 global $frm_vars;
@@ -479,17 +585,16 @@
479 585 $atts['form_id'] . '_item_key' => '',
480 586 $atts['form_id'] . '_id' => '',
481 587 );
482 588 $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
589 + $i = $atts['i'];
483 590
484 - $i = $atts['i'];
485 -
486 591 foreach ( $cols as $col_key => $col ) {
487 592 if ( $i <= $atts['max_columns'] ) {
488 593 break;
489 594 }
490 595
491 - if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
596 + if ( ! $result || ! in_array( $col_key, $result, true ) ) {
492 597 $result[] = $col_key;
493 598 --$i;
494 599 }
495 600
@@ -496,8 +601,14 @@
496 601 unset( $col_key, $col );
497 602 }
498 603 }
499 604
605 + /**
606 + * @param string $message
607 + * @param array $errors
608 + *
609 + * @return void
610 + */
500 611 public static function display_list( $message = '', $errors = array() ) {
501 612 global $wpdb, $frm_vars;
502 613
503 614 $form = FrmForm::maybe_get_current_form();
@@ -509,28 +620,29 @@
509 620
510 621 self::get_delete_form_time( $form, $errors );
511 622 }
512 623
513 - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
514 -
624 + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
515 625 $wp_list_table = new $table_class( array( 'params' => $params ) );
626 + $pagenum = $wp_list_table->get_pagenum();
516 627
517 - $pagenum = $wp_list_table->get_pagenum();
518 -
519 628 $wp_list_table->prepare_items();
520 629
521 630 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
631 +
522 632 if ( $pagenum > $total_pages && $total_pages > 0 ) {
523 633 $url = add_query_arg( 'paged', $total_pages );
634 +
524 635 if ( headers_sent() ) {
525 636 FrmAppHelper::js_redirect( $url, true );
526 637 } else {
527 - wp_redirect( esc_url_raw( $url ) );
638 + wp_safe_redirect( esc_url_raw( $url ) );
528 639 }
640 +
529 641 die();
530 642 }
531 643
532 - if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
644 + if ( ! $message && isset( $_GET['import-message'] ) ) {
533 645 $message = __( 'Your import is complete', 'formidable' );
534 646 }
535 647
536 648 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
@@ -535,20 +647,32 @@
535 647
536 648 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
537 649 }
538 650
651 + /**
652 + * @param object $form
653 + * @param array $errors
654 + *
655 + * @return void
656 + */
539 657 private static function get_delete_form_time( $form, &$errors ) {
540 - if ( 'trash' === $form->status ) {
541 - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
542 - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( $form->options['trash_time'] ?? time() ) );
658 + if ( 'trash' !== $form->status ) {
659 + return;
660 + }
543 661
544 - /* translators: %1$s: Time string */
545 - $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 );
546 - }
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 );
547 667 }
548 668
549 669 /**
550 670 * Back End CRUD.
671 + *
672 + * @param int $id
673 + *
674 + * @return void
551 675 */
552 676 public static function show( $id = 0 ) {
553 677 FrmAppHelper::permission_check( 'frm_view_entries' );
554 678
@@ -560,8 +684,9 @@
560 684 }
561 685 }
562 686
563 687 $entry = FrmEntry::getOne( $id, true );
688 +
564 689 if ( ! $entry ) {
565 690 FrmAppController::show_error_modal(
566 691 array(
567 692 'title' => __( 'You can\'t view the entry', 'formidable' ),
@@ -572,8 +697,9 @@
572 697 return;
573 698 }
574 699
575 700 $data = $entry->description;
701 +
576 702 if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
577 703 $data = array( 'referrer' => $data );
578 704 }
579 705
@@ -590,8 +716,9 @@
590 716 * @return void
591 717 */
592 718 public static function destroy() {
593 719 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
720 +
594 721 if ( false !== $permission_error ) {
595 722 $error_args = array(
596 723 'title' => __( 'Verification failed', 'formidable' ),
597 724 'body' => $permission_error,
@@ -602,13 +729,14 @@
602 729 }
603 730
604 731 $params = FrmForm::get_admin_params();
605 732
606 - if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
733 + if ( ! empty( $params['keep_post'] ) ) {
607 734 self::unlink_post( $params['id'] );
608 735 }
609 736
610 737 $message = '';
738 +
611 739 if ( FrmEntry::destroy( $params['id'] ) ) {
612 740 $message = __( 'Entry was successfully deleted', 'formidable' );
613 741 }
614 742
@@ -614,11 +742,18 @@
614 742
615 743 self::display_list( $message );
616 744 }
617 745
746 + /**
747 + * @param array|string $errors
748 + * @param bool $ajax
749 + *
750 + * @return void
751 + */
618 752 public static function process_entry( $errors = '', $ajax = false ) {
619 753 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
620 - if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
754 +
755 + if ( FrmAppHelper::is_admin() || empty( $_POST ) || ! $form_id || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
621 756 return;
622 757 }
623 758
624 759 global $frm_vars;
@@ -623,13 +758,15 @@
623 758
624 759 global $frm_vars;
625 760
626 761 $form = FrmForm::getOne( $form_id );
762 +
627 763 if ( ! $form ) {
628 764 return;
629 765 }
630 766
631 767 $is_preview = 'frm_forms_preview' === FrmAppHelper::simple_get( 'action' );
768 +
632 769 if ( $is_preview && FrmFormsHelper::should_block_preview( $form->form_key ) ) {
633 770 return;
634 771 }
635 772
@@ -643,8 +780,9 @@
643 780 if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
644 781 return;
645 782 }
646 783
784 + // phpcs:ignore Universal.Operators.StrictComparisons
647 785 if ( $errors == '' && ! $ajax ) {
648 786 $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
649 787 }
650 788
@@ -657,26 +795,28 @@
657 795 $errors = apply_filters( 'frm_entries_before_create', $errors, $form );
658 796
659 797 $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
660 798
661 - if ( empty( $errors ) ) {
662 - $_POST['frm_skip_cookie'] = 1;
663 - $do_success = false;
664 - if ( $params['action'] === 'create' ) {
665 - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
666 - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
799 + if ( $errors ) {
800 + return;
801 + }
667 802
668 - $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
669 - $do_success = true;
670 - }
671 - }
803 + $_POST['frm_skip_cookie'] = 1;
804 + $do_success = false;
672 805
673 - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
674 - if ( $do_success ) {
675 - FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
676 - }
677 - unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
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
808 +
809 + $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
810 + $do_success = true;
678 811 }
812 +
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 ) );
817 + }
818 + unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
679 819 }
680 820
681 821 /**
682 822 * Escape url entities before redirect
@@ -690,11 +830,19 @@
690 830 public static function prepare_redirect_url( $url ) {
691 831 return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
692 832 }
693 833
834 + /**
835 + * Delete entry if redirected.
836 + *
837 + * @param string $url
838 + * @param object $form
839 + * @param array $atts
840 + *
841 + * @return string
842 + */
694 843 public static function delete_entry_before_redirect( $url, $form, $atts ) {
695 844 self::_delete_entry( $atts['id'], $form );
696 -
697 845 return $url;
698 846 }
699 847
700 848 /**
@@ -700,13 +848,23 @@
700 848 /**
701 849 * Delete entry if not redirected.
702 850 *
703 851 * @param array $atts
852 + *
853 + * @return void
704 854 */
705 855 public static function delete_entry_after_save( $atts ) {
706 856 self::_delete_entry( $atts['entry_id'], $atts['form'] );
707 857 }
708 858
859 + /**
860 + * Delete entry if not redirected.
861 + *
862 + * @param int $entry_id
863 + * @param object $form
864 + *
865 + * @return void
866 + */
709 867 private static function _delete_entry( $entry_id, $form ) {
710 868 if ( ! $form ) {
711 869 return;
712 870 }
@@ -711,16 +869,23 @@
711 869 return;
712 870 }
713 871
714 872 FrmAppHelper::unserialize_or_decode( $form->options );
715 - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
716 - self::unlink_post( $entry_id );
717 - FrmEntry::destroy( $entry_id );
873 +
874 + if ( empty( $form->options['no_save'] ) ) {
875 + return;
718 876 }
877 +
878 + self::unlink_post( $entry_id );
879 + FrmEntry::destroy( $entry_id );
719 880 }
720 881
721 882 /**
722 883 * Unlink entry from post
884 + *
885 + * @param int $entry_id
886 + *
887 + * @return void
723 888 */
724 889 private static function unlink_post( $entry_id ) {
725 890 global $wpdb;
726 891 $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) );
@@ -763,34 +928,32 @@
763 928 'line_breaks' => true,
764 929 'array_separator' => ', ',
765 930 );
766 931 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
932 + $atts = shortcode_atts( $defaults, $atts );
767 933
768 - $atts = shortcode_atts( $defaults, $atts );
769 -
770 934 if ( $atts['default_email'] ) {
771 - $shortcode_atts = array(
935 + $shortcode_atts = array(
772 936 'format' => $atts['format'],
773 937 'plain_text' => $atts['plain_text'],
774 938 );
775 -
776 939 $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
777 - $formatted_entry = $entry_formatter->content();
940 + return $entry_formatter->content();
941 + }
778 942
779 - } else {
943 + $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
780 944
781 - $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
782 - $formatted_entry = $entry_formatter->get_formatted_entry_values();
783 -
784 - }
785 -
786 - return $formatted_entry;
945 + return $entry_formatter->get_formatted_entry_values();
787 946 }
788 947
948 + /**
949 + * @param false|object $entry
950 + *
951 + * @return void
952 + */
789 953 public static function entry_sidebar( $entry = false ) {
790 - $data = array();
791 - $id = 0;
792 -
954 + $data = array();
955 + $id = 0;
793 956 $date_format = get_option( 'date_format' );
794 957 $time_format = get_option( 'time_format' );
795 958
796 959 if ( $entry ) {
@@ -795,8 +958,9 @@
795 958
796 959 if ( $entry ) {
797 960 $id = $entry->id;
798 961 $data = $entry->description;
962 +
799 963 if ( isset( $data['browser'] ) ) {
800 964 $browser = FrmEntriesHelper::get_browser( $data['browser'] );
801 965 }
802 966 /**