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