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