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