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