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 +283 -97 6.25 → 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,24 +265,62 @@
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 - $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
239 - $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status';
240 - if ( $has_separate_value && ! $is_post_status ) {
241 - $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
283 + $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
284 + $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status';
285 + $include_column_for_sep_val = $has_separate_value && ! $is_post_status;
286 +
287 + if ( $include_column_for_sep_val ) {
288 + $columns[ $form_id . '_frmsep_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val );
242 289 }
243 290
244 - $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 );
291 + $columns[ $form_id . '_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, false );
245 292 }
246 293
294 + /**
295 + * Appends "(Value)" or "(Label)" to the field name if it's an option field that has a separate value/label.
296 + *
297 + * @since 6.25.1
298 + *
299 + * @param object $field
300 + * @param bool $include_column_for_sep_val
301 + * @param bool $is_value
302 + *
303 + * @return string
304 + */
305 + private static function maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, $is_value = true ) {
306 + $field_name = FrmAppHelper::truncate( $field->name, 35 );
307 +
308 + if ( ! $include_column_for_sep_val || ! in_array( $field->type, array( 'select', 'radio', 'checkbox', 'product', 'ranking' ), true ) ) {
309 + return $field_name;
310 + }
311 +
312 + $append_text = $is_value ? esc_html__( 'value', 'formidable' ) : esc_html__( 'label', 'formidable' );
313 +
314 + return sprintf( '%s (%s)', $field_name, $append_text );
315 + }
316 +
317 + /**
318 + * @param int|string $form_id The form ID.
319 + * @param array $columns The columns array.
320 + *
321 + * @return void
322 + */
247 323 private static function maybe_add_ip_col( $form_id, &$columns ) {
248 324 if ( FrmAppHelper::ips_saved() ) {
249 325 $columns[ $form_id . '_ip' ] = 'IP';
250 326 }
@@ -249,15 +325,26 @@
249 325 $columns[ $form_id . '_ip' ] = 'IP';
250 326 }
251 327 }
252 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 + */
253 338 public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
254 339 $this_page_name = self::hidden_column_key();
340 +
341 + // phpcs:ignore Universal.Operators.StrictComparisons
255 342 if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
256 343 return $check;
257 344 }
258 345
259 - if ( empty( $prev_value ) ) {
346 + if ( ! $prev_value ) {
260 347 $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
261 348 }
262 349
263 350 global $frm_vars;
@@ -268,17 +355,27 @@
268 355 }
269 356
270 357 /**
271 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
272 366 */
273 367 public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
274 368 $this_page_name = self::hidden_column_key();
369 +
370 + // phpcs:ignore Universal.Operators.StrictComparisons
275 371 if ( $meta_key != $this_page_name ) {
276 372 return;
277 373 }
278 374
279 375 global $frm_vars;
280 - if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
376 +
377 + if ( empty( $frm_vars['prev_hidden_cols'] ) ) {
281 378 // Don't continue if there's no previous value.
282 379 return;
283 380 }
284 381
@@ -283,9 +380,9 @@
283 380 }
284 381
285 382 foreach ( $meta_value as $mk => $mv ) {
286 383 // Remove blank values.
287 - if ( empty( $mv ) ) {
384 + if ( ! $mv ) {
288 385 unset( $meta_value[ $mk ] );
289 386 }
290 387 }
291 388
@@ -294,9 +391,10 @@
294 391 $cur_form_prefix = $cur_form_prefix[0];
295 392 $save = false;
296 393
297 394 foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
298 - 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 ) ) {
299 397 // Don't add blank cols or process included cols.
300 398 continue;
301 399 }
302 400
@@ -301,9 +399,10 @@
301 399 }
302 400
303 401 $form_prefix = explode( '_', $prev_hidden );
304 402 $form_prefix = $form_prefix[0];
305 - if ( $form_prefix == $cur_form_prefix ) {
403 +
404 + if ( $form_prefix === $cur_form_prefix ) {
306 405 // Don't add back columns that are meant to be hidden.
307 406 continue;
308 407 }
309 408
@@ -311,28 +410,36 @@
311 410 $save = true;
312 411 unset( $form_prefix );
313 412 }
314 413
315 - if ( $save ) {
316 - $user_id = get_current_user_id();
317 - update_user_option( $user_id, $this_page_name, $meta_value, true );
414 + if ( ! $save ) {
415 + return;
318 416 }
417 +
418 + update_user_option( get_current_user_id(), $this_page_name, $meta_value, true );
319 419 }
320 420
321 421 /**
322 422 * @since 2.05.07
423 + *
424 + * @param string $menu_name
425 + *
426 + * @return string
323 427 */
324 428 private static function hidden_column_key( $menu_name = '' ) {
325 429 $base = self::base_column_key( $menu_name );
326 -
327 430 return 'manage' . $base . 'columnshidden';
328 431 }
329 432
330 433 /**
331 434 * @since 2.05.07
435 + *
436 + * @param string $menu_name
437 + *
438 + * @return string
332 439 */
333 440 private static function base_column_key( $menu_name = '' ) {
334 - if ( empty( $menu_name ) ) {
441 + if ( ! $menu_name ) {
335 442 $menu_name = FrmAppHelper::get_menu_name();
336 443 }
337 444
338 445 $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
@@ -339,16 +446,26 @@
339 446
340 447 return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries';
341 448 }
342 449
450 + /**
451 + * @param int $save
452 + * @param string $option
453 + * @param string $value
454 + *
455 + * @return int
456 + */
343 457 public static function save_per_page( $save, $option, $value ) {
344 458 if ( $option === 'formidable_page_formidable_entries_per_page' ) {
345 - $save = (int) $value;
459 + return (int) $value;
346 460 }
347 461
348 462 return $save;
349 463 }
350 464
465 + /**
466 + * @return array
467 + */
351 468 public static function sortable_columns() {
352 469 $form_id = FrmForm::get_current_form_id();
353 470 $fields = FrmField::get_all_for_form( $form_id );
354 471
@@ -380,8 +497,9 @@
380 497 * Can't sort on checkboxes because they are sorted serialized.
381 498 * Some post content can be sorted but not everything.
382 499 *
383 500 * @param stdClass $field
501 + *
384 502 * @return bool
385 503 */
386 504 private static function field_supports_sorting( $field ) {
387 505 $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] );
@@ -389,8 +507,9 @@
389 507 }
390 508
391 509 /**
392 510 * @param mixed $result Option value from database for hidden columns in entries table.
511 + *
393 512 * @return array
394 513 */
395 514 public static function hidden_columns( $result ) {
396 515 global $frm_vars;
@@ -406,9 +525,9 @@
406 525 $hidden = self::user_hidden_columns_for_form( $form_id, $result );
407 526 $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
408 527 $max_columns = 11;
409 528
410 - if ( ! empty( $hidden ) ) {
529 + if ( $hidden ) {
411 530 $result = $hidden;
412 531 $i = $i - count( $result );
413 532 }
414 533
@@ -422,21 +541,29 @@
422 541 }
423 542
424 543 /**
425 544 * @since 2.05.07
545 + *
546 + * @param int|string $form_id
547 + * @param mixed $result
548 + *
549 + * @return array
426 550 */
427 551 private static function user_hidden_columns_for_form( $form_id, $result ) {
428 552 $hidden = array();
553 +
429 554 foreach ( (array) $result as $r ) {
430 - if ( ! empty( $r ) ) {
431 - list( $form_prefix, $field_key ) = explode( '_', $r );
555 + if ( ! $r ) {
556 + continue;
557 + }
432 558
433 - if ( (int) $form_prefix === (int) $form_id ) {
434 - $hidden[] = $r;
435 - }
559 + list( $form_prefix, $field_key ) = explode( '_', $r );
436 560
437 - unset( $form_prefix );
561 + if ( (int) $form_prefix === (int) $form_id ) {
562 + $hidden[] = $r;
438 563 }
564 +
565 + unset( $form_prefix );
439 566 }
440 567
441 568 return $hidden;
442 569 }
@@ -447,8 +574,9 @@
447 574 * @since 2.05.07
448 575 *
449 576 * @param array $atts
450 577 * @param array $result
578 + *
451 579 * @return void
452 580 */
453 581 private static function remove_excess_cols( $atts, &$result ) {
454 582 global $frm_vars;
@@ -457,17 +585,16 @@
457 585 $atts['form_id'] . '_item_key' => '',
458 586 $atts['form_id'] . '_id' => '',
459 587 );
460 588 $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
589 + $i = $atts['i'];
461 590
462 - $i = $atts['i'];
463 -
464 591 foreach ( $cols as $col_key => $col ) {
465 592 if ( $i <= $atts['max_columns'] ) {
466 593 break;
467 594 }
468 595
469 - if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
596 + if ( ! $result || ! in_array( $col_key, $result, true ) ) {
470 597 $result[] = $col_key;
471 598 --$i;
472 599 }
473 600
@@ -474,8 +601,14 @@
474 601 unset( $col_key, $col );
475 602 }
476 603 }
477 604
605 + /**
606 + * @param string $message
607 + * @param array $errors
608 + *
609 + * @return void
610 + */
478 611 public static function display_list( $message = '', $errors = array() ) {
479 612 global $wpdb, $frm_vars;
480 613
481 614 $form = FrmForm::maybe_get_current_form();
@@ -487,28 +620,29 @@
487 620
488 621 self::get_delete_form_time( $form, $errors );
489 622 }
490 623
491 - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
492 -
624 + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
493 625 $wp_list_table = new $table_class( array( 'params' => $params ) );
626 + $pagenum = $wp_list_table->get_pagenum();
494 627
495 - $pagenum = $wp_list_table->get_pagenum();
496 -
497 628 $wp_list_table->prepare_items();
498 629
499 630 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
631 +
500 632 if ( $pagenum > $total_pages && $total_pages > 0 ) {
501 633 $url = add_query_arg( 'paged', $total_pages );
634 +
502 635 if ( headers_sent() ) {
503 636 FrmAppHelper::js_redirect( $url, true );
504 637 } else {
505 - wp_redirect( esc_url_raw( $url ) );
638 + wp_safe_redirect( esc_url_raw( $url ) );
506 639 }
640 +
507 641 die();
508 642 }
509 643
510 - if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
644 + if ( ! $message && isset( $_GET['import-message'] ) ) {
511 645 $message = __( 'Your import is complete', 'formidable' );
512 646 }
513 647
514 648 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
@@ -513,20 +647,32 @@
513 647
514 648 require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
515 649 }
516 650
651 + /**
652 + * @param object $form
653 + * @param array $errors
654 + *
655 + * @return void
656 + */
517 657 private static function get_delete_form_time( $form, &$errors ) {
518 - if ( 'trash' === $form->status ) {
519 - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
520 - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( $form->options['trash_time'] ?? time() ) );
658 + if ( 'trash' !== $form->status ) {
659 + return;
660 + }
521 661
522 - /* translators: %1$s: Time string */
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 );
524 - }
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 );
525 667 }
526 668
527 669 /**
528 670 * Back End CRUD.
671 + *
672 + * @param int $id
673 + *
674 + * @return void
529 675 */
530 676 public static function show( $id = 0 ) {
531 677 FrmAppHelper::permission_check( 'frm_view_entries' );
532 678
@@ -538,8 +684,9 @@
538 684 }
539 685 }
540 686
541 687 $entry = FrmEntry::getOne( $id, true );
688 +
542 689 if ( ! $entry ) {
543 690 FrmAppController::show_error_modal(
544 691 array(
545 692 'title' => __( 'You can\'t view the entry', 'formidable' ),
@@ -550,8 +697,9 @@
550 697 return;
551 698 }
552 699
553 700 $data = $entry->description;
701 +
554 702 if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
555 703 $data = array( 'referrer' => $data );
556 704 }
557 705
@@ -568,8 +716,9 @@
568 716 * @return void
569 717 */
570 718 public static function destroy() {
571 719 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
720 +
572 721 if ( false !== $permission_error ) {
573 722 $error_args = array(
574 723 'title' => __( 'Verification failed', 'formidable' ),
575 724 'body' => $permission_error,
@@ -580,13 +729,14 @@
580 729 }
581 730
582 731 $params = FrmForm::get_admin_params();
583 732
584 - if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
733 + if ( ! empty( $params['keep_post'] ) ) {
585 734 self::unlink_post( $params['id'] );
586 735 }
587 736
588 737 $message = '';
738 +
589 739 if ( FrmEntry::destroy( $params['id'] ) ) {
590 740 $message = __( 'Entry was successfully deleted', 'formidable' );
591 741 }
592 742
@@ -592,11 +742,18 @@
592 742
593 743 self::display_list( $message );
594 744 }
595 745
746 + /**
747 + * @param array|string $errors
748 + * @param bool $ajax
749 + *
750 + * @return void
751 + */
596 752 public static function process_entry( $errors = '', $ajax = false ) {
597 753 $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
598 - 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
599 756 return;
600 757 }
601 758
602 759 global $frm_vars;
@@ -601,13 +758,15 @@
601 758
602 759 global $frm_vars;
603 760
604 761 $form = FrmForm::getOne( $form_id );
762 +
605 763 if ( ! $form ) {
606 764 return;
607 765 }
608 766
609 767 $is_preview = 'frm_forms_preview' === FrmAppHelper::simple_get( 'action' );
768 +
610 769 if ( $is_preview && FrmFormsHelper::should_block_preview( $form->form_key ) ) {
611 770 return;
612 771 }
613 772
@@ -621,8 +780,9 @@
621 780 if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
622 781 return;
623 782 }
624 783
784 + // phpcs:ignore Universal.Operators.StrictComparisons
625 785 if ( $errors == '' && ! $ajax ) {
626 786 $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
627 787 }
628 788
@@ -635,26 +795,28 @@
635 795 $errors = apply_filters( 'frm_entries_before_create', $errors, $form );
636 796
637 797 $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
638 798
639 - if ( empty( $errors ) ) {
640 - $_POST['frm_skip_cookie'] = 1;
641 - $do_success = false;
642 - if ( $params['action'] === 'create' ) {
643 - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
644 - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
799 + if ( $errors ) {
800 + return;
801 + }
645 802
646 - $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
647 - $do_success = true;
648 - }
649 - }
803 + $_POST['frm_skip_cookie'] = 1;
804 + $do_success = false;
650 805
651 - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
652 - if ( $do_success ) {
653 - FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
654 - }
655 - 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;
656 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
657 819 }
658 820
659 821 /**
660 822 * Escape url entities before redirect
@@ -668,11 +830,19 @@
668 830 public static function prepare_redirect_url( $url ) {
669 831 return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
670 832 }
671 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 + */
672 843 public static function delete_entry_before_redirect( $url, $form, $atts ) {
673 844 self::_delete_entry( $atts['id'], $form );
674 -
675 845 return $url;
676 846 }
677 847
678 848 /**
@@ -678,13 +848,23 @@
678 848 /**
679 849 * Delete entry if not redirected.
680 850 *
681 851 * @param array $atts
852 + *
853 + * @return void
682 854 */
683 855 public static function delete_entry_after_save( $atts ) {
684 856 self::_delete_entry( $atts['entry_id'], $atts['form'] );
685 857 }
686 858
859 + /**
860 + * Delete entry if not redirected.
861 + *
862 + * @param int $entry_id
863 + * @param object $form
864 + *
865 + * @return void
866 + */
687 867 private static function _delete_entry( $entry_id, $form ) {
688 868 if ( ! $form ) {
689 869 return;
690 870 }
@@ -689,16 +869,23 @@
689 869 return;
690 870 }
691 871
692 872 FrmAppHelper::unserialize_or_decode( $form->options );
693 - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
694 - self::unlink_post( $entry_id );
695 - FrmEntry::destroy( $entry_id );
873 +
874 + if ( empty( $form->options['no_save'] ) ) {
875 + return;
696 876 }
877 +
878 + self::unlink_post( $entry_id );
879 + FrmEntry::destroy( $entry_id );
697 880 }
698 881
699 882 /**
700 883 * Unlink entry from post
884 + *
885 + * @param int $entry_id
886 + *
887 + * @return void
701 888 */
702 889 private static function unlink_post( $entry_id ) {
703 890 global $wpdb;
704 891 $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) );
@@ -741,34 +928,32 @@
741 928 'line_breaks' => true,
742 929 'array_separator' => ', ',
743 930 );
744 931 $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
932 + $atts = shortcode_atts( $defaults, $atts );
745 933
746 - $atts = shortcode_atts( $defaults, $atts );
747 -
748 934 if ( $atts['default_email'] ) {
749 - $shortcode_atts = array(
935 + $shortcode_atts = array(
750 936 'format' => $atts['format'],
751 937 'plain_text' => $atts['plain_text'],
752 938 );
753 -
754 939 $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
755 - $formatted_entry = $entry_formatter->content();
940 + return $entry_formatter->content();
941 + }
756 942
757 - } else {
943 + $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
758 944
759 - $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
760 - $formatted_entry = $entry_formatter->get_formatted_entry_values();
761 -
762 - }
763 -
764 - return $formatted_entry;
945 + return $entry_formatter->get_formatted_entry_values();
765 946 }
766 947
948 + /**
949 + * @param false|object $entry
950 + *
951 + * @return void
952 + */
767 953 public static function entry_sidebar( $entry = false ) {
768 - $data = array();
769 - $id = 0;
770 -
954 + $data = array();
955 + $id = 0;
771 956 $date_format = get_option( 'date_format' );
772 957 $time_format = get_option( 'time_format' );
773 958
774 959 if ( $entry ) {
@@ -773,8 +958,9 @@
773 958
774 959 if ( $entry ) {
775 960 $id = $entry->id;
776 961 $data = $entry->description;
962 +
777 963 if ( isset( $data['browser'] ) ) {
778 964 $browser = FrmEntriesHelper::get_browser( $data['browser'] );
779 965 }
780 966 /**