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