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