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