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