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