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