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