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