PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.6.1
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.6.1
3.6.1 3.6.0 3.5.3 3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / admin / class-evf-admin-entries-table-list.php
everest-forms / includes / admin Last commit date
builder 3 weeks ago form-migrator 2 months ago plugin-updates 8 years ago settings 1 month ago views 3 weeks ago class-evf-admin-addons.php 6 months ago class-evf-admin-assets.php 3 weeks ago class-evf-admin-builder.php 4 months ago class-evf-admin-dashboard.php 2 months ago class-evf-admin-editor.php 4 years ago class-evf-admin-embed-wizard.php 2 years ago class-evf-admin-entries-table-list.php 1 day ago class-evf-admin-entries.php 1 month ago class-evf-admin-form-templates.php 3 weeks ago class-evf-admin-forms-table-list.php 6 months ago class-evf-admin-forms.php 6 months ago class-evf-admin-import-export.php 2 months ago class-evf-admin-menus.php 1 month ago class-evf-admin-notices.php 6 months ago class-evf-admin-preview-confirmation.php 1 year ago class-evf-admin-settings.php 2 months ago class-evf-admin-tools.php 4 months ago class-evf-admin-welcome.php 3 years ago class-evf-admin.php 4 months ago class-evf-base-list-table.php 6 months ago evf-admin-functions.php 1 day ago
class-evf-admin-entries-table-list.php
1281 lines
1 <?php
2 /**
3 * EverestForms Entries Table List
4 *
5 * @package EverestForms\Admin
6 * @since 1.1.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 if ( ! class_exists( 'EVF_Base_List_Table' ) ) {
12 require_once __DIR__ . '/class-evf-base-list-table.php';
13 }
14
15 /**
16 * Entries table list class.
17 */
18 class EVF_Admin_Entries_Table_List extends EVF_Base_List_Table {
19
20 /**
21 * Form ID.
22 *
23 * @var int
24 */
25 public $form_id;
26
27 /**
28 * Forms object.
29 *
30 * @var EVF_Form_Handler
31 */
32 public $form;
33
34 /**
35 * Forms object.
36 *
37 * @var EVF_Form_Handler[]
38 */
39 public $forms;
40
41 /**
42 * Form data as an array.
43 *
44 * @var array
45 */
46 public $form_data;
47
48 /**
49 * Initialize the log table list.
50 */
51 public function __construct() {
52 $this->forms = evf_get_all_forms( true );
53 if ( ! empty( $this->forms ) ) {
54 $this->form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
55
56 $default_form_id = apply_filters( 'everest_forms_entry_list_default_form_id', key( $this->forms ) );
57 $active_form_id = ( $this->form_id > 0 ) ? $this->form_id : $default_form_id;
58
59 $this->form = evf()->form->get( $active_form_id );
60 $this->form_data = ! empty( $this->form->post_content ) ? evf_decode( $this->form->post_content ) : '';
61 }
62
63 parent::__construct(
64 array(
65 'singular' => 'entry',
66 'plural' => 'entries',
67 'ajax' => false,
68 )
69 );
70 }
71
72 /**
73 * Get the current action selected from the bulk actions dropdown.
74 *
75 * @since 1.5.3
76 *
77 * @return string|false The action name or False if no action was selected.
78 */
79 public function current_action() {
80 if ( isset( $_REQUEST['export_action'] ) && ! empty( $_REQUEST['export_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
81 return false;
82 }
83
84 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
85 return 'delete_all';
86 }
87
88 return parent::current_action();
89 }
90
91 /**
92 * No items found text.
93 */
94 public function no_items() {
95 esc_html_e( 'Whoops, it appears you do not have any form entries yet.', 'everest-forms' );
96 }
97
98 /**
99 * Get list columns.
100 *
101 * @return array
102 */
103 public function get_columns() {
104 $columns = array();
105 $columns['cb'] = '<input type="checkbox" />';
106 $columns = apply_filters( 'everest_forms_add_extra_columns', $columns );
107
108 if ( 0 === $this->form_id ) {
109 $columns['entry'] = esc_html__( 'Entry', 'everest-forms' );
110 $columns['form'] = esc_html__( 'Form', 'everest-forms' );
111 $columns['date'] = esc_html__( 'Date Created', 'everest-forms' );
112 } else {
113 $columns = apply_filters( 'everest_forms_entries_table_form_fields_columns', $this->get_columns_form_fields( $columns ), $this->form_id, $this->form_data );
114 $columns['date'] = esc_html__( 'Date Created', 'everest-forms' );
115 }
116
117 return apply_filters( 'everest_forms_entries_table_columns', $columns, $this->form_data );
118 }
119
120 /**
121 * Get a list of sortable columns.
122 *
123 * @return array
124 */
125 protected function get_sortable_columns() {
126 $sortable_columns = array();
127
128 if ( isset( $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
129 $sortable_columns = array(
130 'date' => array( 'date_created', false ),
131 );
132 }
133
134 return $sortable_columns;
135 }
136
137 /**
138 * Generates content for a single row of the table.
139 *
140 * @since 1.6.0
141 *
142 * @param object $entry Entry data.
143 */
144 public function single_row( $entry ) {
145 if ( empty( $_GET['status'] ) || ( isset( $_GET['status'] ) && 'trash' !== $_GET['status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
146 echo '<tr class="' . ( $entry->viewed ? 'read' : 'unread' ) . '">';
147 $this->single_row_columns( $entry );
148 echo '</tr>';
149 } else {
150 parent::single_row( $entry );
151 }
152 }
153
154 /**
155 * Get the list of fields, that are disallowed to be displayed as column in a table.
156 *
157 * @return array
158 */
159 public static function get_columns_form_disallowed_fields() {
160 return (array) apply_filters( 'everest_forms_entries_table_fields_disallow', array( 'html', 'title', 'captcha', 'repeater-fields', 'authorize-net', 'private-note' ) );
161 }
162
163 /**
164 * Logic to determine which fields are displayed in the table columns.
165 *
166 * @param array $columns List of colums.
167 * @param int $display Numbers of columns to display.
168 *
169 * @return array
170 */
171 public function get_columns_form_fields( $columns = array(), $display = 3 ) {
172 $entry_columns = evf()->form->get_meta( $this->form_id, 'entry_columns' );
173
174 if ( ! $entry_columns && ! empty( $this->form_data['form_fields'] ) ) {
175 $x = 0;
176 foreach ( $this->form_data['form_fields'] as $id => $field ) {
177 if ( ! in_array( $field['type'], self::get_columns_form_disallowed_fields(), true ) && $x < $display ) {
178 $columns[ 'evf_field_' . $id ] = ! empty( $field['label'] ) ? wp_strip_all_tags( $field['label'] ) : esc_html__( 'Field', 'everest-forms' );
179 ++$x;
180 }
181 }
182 } elseif ( ! empty( $entry_columns ) ) {
183 foreach ( $entry_columns as $id ) {
184 // Check to make sure the field as not been removed.
185 $status = defined( 'EFP_VERSION' ) ? true : false;
186 $status = apply_filters( 'everest_forms_plugin_active_status', $status );
187 if ( empty( $this->form_data['form_fields'][ $id ] ) ) {
188 if ( $status ) {
189 if ( 'sn' === $id ) {
190 $extra_column = apply_filters( 'everest_forms_entries_table_extra_columns', array(), 0, array() );
191 $columns = array_merge( $columns, $extra_column );
192 }
193 if ( 'id' === $id ) {
194 $extra_column = apply_filters( 'everest_forms_entries_table_extra_columns_id', array(), 0, array() );
195 $columns = array_merge( $columns, $extra_column );
196 }
197 }
198 continue;
199 }
200
201 $columns[ 'evf_field_' . $id ] = ! empty( $this->form_data['form_fields'][ $id ]['label'] ) ? wp_strip_all_tags( $this->form_data['form_fields'][ $id ]['label'] ) : esc_html__( 'Field', 'everest-forms' );
202 }
203 }
204
205 return apply_filters( 'everest_forms_entries_table_form_field_columns', $columns, $this->form_id, $this->form_data );
206 }
207
208 /**
209 * Column cb.
210 *
211 * @param object $entry Entry object.
212 * @return string
213 */
214 public function column_cb( $entry ) {
215 return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $entry->entry_id );
216 }
217
218 /**
219 * Column for simplified "Entry" view (All Forms only)
220 *
221 * @param object $entry Entry object.
222 * @return string
223 */
224 public function column_entry( $entry ) {
225 if ( empty( $entry->meta ) ) {
226 return '<span class="na">&mdash;</span>';
227 }
228
229 // Skip system fields
230 $skip_fields = array( 'entry_id', 'form_id', 'user_id', 'user_device', 'user_ip_address', 'viewed', 'starred', 'status' );
231
232 // Upload fields store only the hashed file URL in entry meta, so map each
233 // upload field's meta key to its original file name(s) from the full
234 // entry fields. This keeps the preview readable (e.g. "photo.png") instead
235 // of the full URL / hashed file name. See EVF-2095.
236 $upload_names = $this->get_upload_field_names( $entry );
237
238 // Find first non-empty field value
239 foreach ( $entry->meta as $key => $value ) {
240 if ( in_array( $key, $skip_fields, true ) || strpos( $key, '_' ) === 0 ) {
241 continue;
242 }
243
244 // Prefer the original file name(s) for upload fields.
245 if ( isset( $upload_names[ $key ] ) && '' !== $upload_names[ $key ] ) {
246 return $upload_names[ $key ];
247 }
248
249 // Process the value
250 $field_value = $this->process_field_value( $value );
251
252 if ( ! empty( $field_value ) && '&mdash;' !== $field_value ) {
253 return $field_value;
254 }
255 }
256
257 return '<span class="na">&mdash;</span>';
258 }
259
260 /**
261 * Build a map of upload field meta keys to their original file name(s).
262 *
263 * Entry meta only stores the public file URL (with a hashed file name), so
264 * the original names are read from the full entry fields payload. See EVF-2095.
265 *
266 * @param object $entry Entry object.
267 * @return array Map of meta key => escaped, comma-separated original file names.
268 */
269 private function get_upload_field_names( $entry ) {
270 $names = array();
271
272 $fields = isset( $entry->fields ) ? evf_decode( $entry->fields ) : array();
273
274 if ( empty( $fields ) || ! is_array( $fields ) ) {
275 return $names;
276 }
277
278 foreach ( $fields as $field ) {
279 if ( empty( $field['meta_key'] ) || empty( $field['type'] ) ) {
280 continue;
281 }
282
283 if ( ! in_array( $field['type'], array( 'image-upload', 'file-upload' ), true ) ) {
284 continue;
285 }
286
287 if ( empty( $field['value_raw'] ) || ! is_array( $field['value_raw'] ) ) {
288 continue;
289 }
290
291 $file_names = array();
292 foreach ( $field['value_raw'] as $file ) {
293 if ( ! empty( $file['file_original'] ) ) {
294 $file_names[] = $file['file_original'];
295 } elseif ( ! empty( $file['name'] ) ) {
296 $file_names[] = $file['name'];
297 }
298 }
299
300 if ( ! empty( $file_names ) ) {
301 $names[ $field['meta_key'] ] = esc_html( implode( ', ', $file_names ) );
302 }
303 }
304
305 return $names;
306 }
307
308 /**
309 * Column for form name (All Forms view only)
310 *
311 * @param object $entry Entry object.
312 * @return string
313 */
314 public function column_form( $entry ) {
315 $form_title = get_the_title( $entry->form_id );
316
317 if ( empty( $form_title ) ) {
318 return '&mdash;';
319 }
320
321 return '<a href="' . esc_url( admin_url( 'admin.php?page=evf-entries&form_id=' . $entry->form_id ) ) . '">' . esc_html( $form_title ) . '</a>';
322 }
323
324 /**
325 * Process field value for display
326 *
327 * @param mixed $value Field value.
328 * @return string Processed value.
329 */
330 private function process_field_value( $value ) {
331 if ( empty( $value ) ) {
332 return '&mdash;';
333 }
334
335 if ( evf_is_json( $value ) ) {
336 $field_value = json_decode( $value, true );
337 $value = isset( $field_value['value'] ) ? $field_value['value'] : $value;
338 }
339
340 if ( is_serialized( $value ) ) {
341 $field_value = evf_maybe_unserialize( $value );
342 $field_label = ! empty( $field_value['label'] ) ? evf_clean( $field_value['label'] ) : $field_value;
343
344 if ( is_array( $field_label ) ) {
345 $value = implode( ', ', array_map( 'esc_html', $field_label ) );
346 } else {
347 $value = esc_html( $field_label );
348 }
349 }
350
351 if ( is_array( $value ) ) {
352 if ( isset( $value['label'] ) ) {
353 $value = is_array( $value['label'] ) ? implode( ', ', $value['label'] ) : $value['label'];
354 } else {
355 $value = implode( ', ', $value );
356 }
357 }
358
359 if ( is_string( $value ) && filter_var( $value, FILTER_VALIDATE_URL ) ) {
360 $path = wp_parse_url( $value, PHP_URL_PATH );
361 if ( ! empty( $path ) ) {
362 $value = basename( $path );
363 }
364 }
365
366 $value = (string) $value;
367 if ( strlen( $value ) > 100 ) {
368 $value = substr( $value, 0, 100 ) . '&hellip;';
369 }
370
371 $value = wp_strip_all_tags( trim( $value ) );
372
373 return $value;
374 }
375
376
377
378 /**
379 * Show specific form fields (for specific form view).
380 *
381 * @param object $entry Entry object.
382 * @param string $column_name Column Name.
383 * @return string
384 */
385 public function column_form_field( $entry, $column_name ) {
386 $field_id = str_replace( 'evf_field_', '', $column_name );
387 $meta_key = isset( $this->form_data['form_fields'][ $field_id ]['meta-key'] ) ? strtolower( $this->form_data['form_fields'][ $field_id ]['meta-key'] ) : $field_id;
388 $field_type = isset( $this->form_data['form_fields'][ $field_id ]['type'] ) ? $this->form_data['form_fields'][ $field_id ]['type'] : '';
389
390 if ( ! empty( $entry->meta[ $meta_key ] ) || ( isset( $entry->meta[ $meta_key ] ) && is_numeric( $entry->meta[ $meta_key ] ) ) ) {
391 $value = $entry->meta[ $meta_key ];
392 if ( evf_is_json( $value ) ) {
393 $field_value = json_decode( $value, true );
394 $decoded = isset( $field_value['value'] ) ? $field_value['value'] : $field_value;
395
396 // Coupons field stores data on array.
397 if ( is_array( $decoded ) ) {
398 $codes = array();
399 foreach ( $decoded as $item ) {
400 if ( is_array( $item ) && ! empty( $item['code'] ) ) {
401 $codes[] = esc_html( $item['code'] );
402 }
403 }
404 $value = ! empty( $codes ) ? implode( ', ', $codes ) : implode( ', ', array_filter( array_map( 'strval', $decoded ) ) );
405 } else {
406 $value = $decoded;
407 }
408 }
409
410 if ( is_serialized( $value ) ) {
411 $field_html = array();
412 $field_value = evf_maybe_unserialize( $value );
413
414 $field_label = ! empty( $field_value['label'] ) ? evf_clean( $field_value['label'] ) : $field_value;
415 if ( is_array( $field_label ) ) {
416 foreach ( $field_label as $item ) {
417 // Coupon field: each item is an array with 'code', 'discount_type', etc.
418 if ( is_array( $item ) ) {
419 if ( ! empty( $item['code'] ) ) {
420 $field_html[] = esc_html( $item['code'] );
421 }
422 } else {
423 $field_html[] = esc_html( $item );
424 }
425 }
426
427 $value = implode( ', ', $field_html );
428 } else {
429 $value = esc_html( $field_label );
430 }
431 }
432
433 $value = isset( $value['label'] ) && is_array( $value['label'] ) ? implode( ', ', $value['label'] ) : ( is_array( $value ) ? implode( ', ', $value ) : $value );
434
435 $value = (string) $value;
436
437 if ( false === strpos( $value, 'http' ) ) {
438 $lines = explode( "\n", $value );
439 $value = array_slice( $lines, 0, 4 );
440 $value = implode( "\n", $value );
441
442 if ( count( $lines ) > 5 ) {
443 $value .= '&hellip;';
444 } elseif ( strlen( $value ) > 75 ) {
445 $value = substr( $value, 0, 75 ) . '&hellip;';
446 }
447
448 $value = nl2br( wp_strip_all_tags( trim( $value ) ) );
449 }
450 $value = apply_filters( 'everest_forms_html_field_value', $value, $entry->meta[ $meta_key ], $entry, 'entry-table', $meta_key );
451
452 if ( in_array( $field_type, array( 'file-upload', 'image-upload', 'signature', 'wysiwyg', 'color', 'rating', 'country', 'likert', 'checkbox', 'radio', 'repeater-fields', 'payment-checkbox' ), true ) ) {
453 return nl2br( make_clickable( $value ) );
454 }elseif( 'address' === $field_type ){
455 $allowed_tags = array(
456 'br' => array(),
457 'span' => array(),
458 'p' => array(),
459 );
460
461 $output = nl2br( $value );
462 return wp_kses( $output, $allowed_tags );
463 }
464 else{
465 return esc_html( $value );
466 }
467 } else {
468 return '<span class="na">&mdash;</span>';
469 }
470 }
471
472 /**
473 * Renders the columns.
474 *
475 * @param object $entry Entry object.
476 * @param string $column_name Column Name.
477 * @return string
478 */
479 public function column_default( $entry, $column_name ) {
480 switch ( $column_name ) {
481 case 'id':
482 $value = absint( $entry->entry_id );
483 break;
484
485 case 'date':
486 $value = date_i18n(
487 'Y/m/d',
488 strtotime( $entry->date_created ) + ( get_option( 'gmt_offset' ) * 3600 )
489 );
490
491 break;
492
493 case 'sn':
494 $position = array_search( $entry, $this->items, true );
495 $value = $position + 1;
496 break;
497
498 case 'entry':
499 $value = $this->column_entry( $entry );
500 break;
501
502 case 'form':
503 $value = $this->column_form( $entry );
504 break;
505
506 default:
507 if ( false !== strpos( $column_name, 'evf_field_' ) ) {
508 $value = $this->column_form_field( $entry, $column_name );
509 } else {
510 $value = '';
511 }
512 break;
513 }
514
515 return apply_filters( 'everest_forms_entry_table_column_value', $value, $entry, $column_name );
516 }
517
518 /**
519 * Get row actions for an entry.
520 *
521 * @param object $entry Entry object.
522 * @return array
523 */
524 protected function get_row_actions( $entry ) {
525 $actions = array();
526 $status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '';
527
528 if ( 'trash' !== $entry->status ) {
529 if ( current_user_can( 'everest_forms_view_entry', $entry->entry_id ) ) {
530 $actions['view'] = '<a href="' . esc_url( admin_url( 'admin.php?page=evf-entries&amp;form_id=' . $entry->form_id . '&amp;view-entry=' . $entry->entry_id ) ) . '">' . esc_html__( 'View', 'everest-forms' ) . '</a>';
531 }
532
533 $user_can_edit_entry = is_admin() && current_user_can( 'everest_forms_edit_entry', $entry->entry_id );
534
535 if ( $user_can_edit_entry ) {
536 switch ( $status ) {
537 case 'spam':
538 $actions['unspam'] = '<a href="' . esc_url(
539 wp_nonce_url(
540 add_query_arg(
541 array(
542 'unspam-entry' => $entry->entry_id,
543 'form_id' => $entry->form_id,
544 ),
545 admin_url( 'admin.php?page=evf-entries' )
546 ),
547 'unspam-entry'
548 )
549 ) . '">' . esc_html__( 'Remove From Spam', 'everest-forms' ) . '</a>';
550 break;
551 default:
552 $actions['spam'] = '<a href="' . esc_url(
553 wp_nonce_url(
554 add_query_arg(
555 array(
556 'spam-entry' => $entry->entry_id,
557 'form_id' => $entry->form_id,
558 ),
559 admin_url( 'admin.php?page=evf-entries' )
560 ),
561 'spam-entry'
562 )
563 ) . '">' . esc_html__( 'Mark as Spam', 'everest-forms' ) . '</a>';
564 break;
565 }
566 }
567
568 if ( current_user_can( 'everest_forms_delete_entry', $entry->entry_id ) ) {
569 /* translators: %s: entry name */
570 $actions['trash'] = '<a class="submitdelete" aria-label="' . esc_attr__( 'Trash form entry', 'everest-forms' ) . '" href="' . esc_url(
571 wp_nonce_url(
572 add_query_arg(
573 array(
574 'trash' => $entry->entry_id,
575 'form_id' => $this->form_id,
576 ),
577 admin_url( 'admin.php?page=evf-entries' )
578 ),
579 'trash-entry'
580 )
581 ) . '">' . esc_html__( 'Trash', 'everest-forms' ) . '</a>';
582 }
583 } else {
584 if ( current_user_can( 'everest_forms_edit_entry', $entry->entry_id ) ) {
585 $actions['untrash'] = '<a aria-label="' . esc_attr__( 'Restore form entry from trash', 'everest-forms' ) . '" href="' . esc_url(
586 wp_nonce_url(
587 add_query_arg(
588 array(
589 'untrash' => $entry->entry_id,
590 'form_id' => $this->form_id,
591 ),
592 admin_url( 'admin.php?page=evf-entries' )
593 ),
594 'untrash-entry'
595 )
596 ) . '">' . esc_html__( 'Restore', 'everest-forms' ) . '</a>';
597 }
598
599 if ( current_user_can( 'everest_forms_delete_entry', $entry->entry_id ) ) {
600 /* translators: %s: entry name */
601 $actions['delete'] = '<a class="submitdelete" aria-label="' . esc_attr__( 'Delete form entry permanently', 'everest-forms' ) . '" href="' . esc_url(
602 wp_nonce_url(
603 add_query_arg(
604 array(
605 'delete' => $entry->entry_id,
606 'form_id' => $this->form_id,
607 ),
608 admin_url( 'admin.php?page=evf-entries' )
609 ),
610 'delete-entry'
611 )
612 ) . '">' . esc_html__( 'Delete Permanently', 'everest-forms' ) . '</a>';
613 }
614 }
615
616 return apply_filters( 'everest_forms_entry_table_actions', $actions, $entry );
617 }
618
619 /**
620 * Render the actions column.
621 *
622 * @param object $entry Entry object.
623 * @return string
624 */
625 public function column_actions( $entry ) {
626 $actions = $this->get_row_actions( $entry );
627 return implode( ' <span class="sep">|</span> ', $actions );
628 }
629
630 /**
631 * Handle row actions for the primary column.
632 *
633 * @param object $entry Entry object.
634 * @param string $column_name Current column name.
635 * @param string $primary Primary column name.
636 * @return string
637 */
638 protected function handle_row_actions( $entry, $column_name, $primary ) {
639 if ( $primary !== $column_name ) {
640 return '';
641 }
642
643 $actions = $this->get_row_actions( $entry );
644 return $this->row_actions( $actions, false );
645 }
646
647 /**
648 * Get the name of the primary column.
649 *
650 * @return string
651 */
652 protected function get_primary_column_name() {
653 // For All Forms view
654 if ( 0 === $this->form_id ) {
655 return 'entry';
656 }
657
658 // For specific form view - use existing logic
659 $columns = $this->get_columns();
660
661 unset( $columns['cb'], $columns['actions'], $columns['more'] );
662
663 $primary = '';
664 if ( ! empty( $columns ) ) {
665 foreach ( $columns as $column_key => $column_name ) {
666 if ( strpos( $column_key, 'evf_field_' ) === 0 ) {
667 $primary = $column_key;
668 break;
669 }
670 }
671
672 if ( empty( $primary ) ) {
673 reset( $columns );
674 $primary = key( $columns );
675 }
676 }
677
678 return $primary;
679 }
680
681 /**
682 * Get the status label for entries.
683 *
684 * @param string $status_name Status name.
685 * @param int $amount Amount of entries.
686 * @return array
687 */
688 private function get_status_label( $status_name, $amount ) {
689 $statuses = evf_get_entry_statuses( $this->form_data );
690
691 if ( isset( $statuses[ $status_name ] ) ) {
692 return array(
693 'singular' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ),
694 'plural' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ),
695 'context' => '',
696 'domain' => 'everest-forms',
697 );
698 }
699
700 return array(
701 'singular' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ),
702 'plural' => sprintf( '%s <span class="count">(%s)</span>', esc_html( $status_name ), $amount ),
703 'context' => '',
704 'domain' => 'everest-forms',
705 );
706 }
707
708 /**
709 * Table list views.
710 *
711 * @return array
712 */
713 protected function get_views() {
714
715 return array();
716
717 // $status_links = array();
718
719 // if ( 0 === $this->form_id ) {
720 // $num_entries = $this->get_all_forms_entry_counts();
721 // } else {
722 // $num_entries = evf_get_count_entries_by_status( $this->form_id );
723 // }
724
725 // $total_entries = apply_filters( 'everest_forms_total_entries_count', (int) $num_entries['publish'], $num_entries, $this->form_id );
726 // $spam_entries = apply_filters( 'everest_forms_spam_total_entries_count', (int) $num_entries['spam'], $num_entries, $this->form_id );
727
728 // $statuses = array_keys( evf_get_entry_statuses( $this->form_data ) );
729 // $class = empty( $_REQUEST['status'] ) ? ' class="current"' : ''; // phpcs:ignore WordPress.Security.NonceVerification
730
731 // $base_url = admin_url( 'admin.php?page=evf-entries' );
732 // if ( $this->form_id > 0 ) {
733 // $base_url = add_query_arg( 'form_id', $this->form_id, $base_url );
734 // }
735
736 // /* translators: %s: count */
737 // $status_links['all'] = "<a href='" . esc_url( $base_url ) . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_entries, 'entries', 'everest-forms' ), number_format_i18n( $total_entries ) ) . '</a>';
738
739 // /* translators: %s: count */
740 // $spam_url = add_query_arg( 'status', 'spam', $base_url );
741 // $spam_class = ( isset( $_REQUEST['status'] ) && 'spam' === $_REQUEST['status'] ) ? ' class="current"' : '';
742 // $status_links['spam'] = "<a href='" . esc_url( $spam_url ) . "'$spam_class>" . sprintf( _nx( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', $spam_entries, 'entries', 'everest-forms' ), number_format_i18n( $spam_entries ) ) . '</a>';
743
744 // foreach ( $statuses as $status_name ) {
745 // if ( 'publish' === $status_name ) {
746 // continue;
747 // }
748
749 // if ( isset( $_REQUEST['status'] ) && sanitize_key( wp_unslash( $_REQUEST['status'] ) ) === $status_name ) { // phpcs:ignore WordPress.Security.NonceVerification
750 // $class = ' class="current"';
751 // } else {
752 // $class = '';
753 // }
754
755 // $label = $this->get_status_label( $status_name, $num_entries[ $status_name ] );
756 // $status_url = add_query_arg( 'status', $status_name, $base_url );
757
758 // $status_links[ $status_name ] = "<a href='" . esc_url( $status_url ) . "'$class>" . sprintf( translate_nooped_plural( $label, $num_entries[ $status_name ] ), number_format_i18n( $num_entries[ $status_name ] ) ) . '</a>';
759 // }
760
761 // return apply_filters( 'everest_forms_entries_table_views', $status_links, $num_entries, $this->form_data );
762 }
763
764 /**
765 * Get entry counts across all forms
766 *
767 * @return array
768 */
769 private function get_all_forms_entry_counts() {
770 global $wpdb;
771
772 // Initialize counts array with default counts for each status
773 $counts = array(
774 'publish' => 0,
775 'spam' => 0,
776 'trash' => 0,
777 'pending' => 0,
778 'denied' => 0,
779 'unread' => 0,
780 'read' => 0,
781 'starred' => 0, // Add starred count
782 );
783
784 $results = $wpdb->get_results( "SELECT status, COUNT(*) as count FROM {$wpdb->prefix}evf_entries GROUP BY status" );
785
786 foreach ( $results as $row ) {
787 $counts[ $row->status ] = (int) $row->count;
788 }
789
790 // Count the unread entries (viewed = 0, status != 'trash')
791 $unread_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE viewed = 0 AND status != 'trash'" );
792
793 $read_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE viewed = 1 AND status != 'trash'" );
794
795 $counts['unread'] = (int) $unread_count;
796 $counts['read'] = (int) $read_count;
797
798 $starred_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE starred = 1 AND status != 'trash'" );
799
800 $counts['starred'] = (int) $starred_count;
801
802 return $counts;
803 }
804
805
806 /**
807 * Get bulk actions.
808 *
809 * @return array
810 */
811 protected function get_bulk_actions() {
812 if ( isset( $_GET['status'] ) && 'trash' === $_GET['status'] ) { // phpcs:ignore WordPress.Security.NonceVerification
813 $actions = array(
814 'untrash' => __( 'Restore', 'everest-forms' ),
815 'delete' => __( 'Delete Permanently', 'everest-forms' ),
816 );
817 } else {
818 $actions = array(
819 'trash' => __( 'Move to Trash', 'everest-forms' ),
820 );
821 }
822
823 return apply_filters( 'everest_forms_entry_bulk_actions', $actions );
824 }
825
826 /**
827 * Process bulk actions.
828 *
829 * @since 1.2.0
830 */
831 public function process_bulk_action() {
832 $pagenum = $this->get_pagenum();
833 $doaction = $this->current_action();
834 $entry_ids = isset( $_REQUEST['entry'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['entry'] ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification
835 $form_id = isset( $_REQUEST['form_id'] ) ? sanitize_key( wp_unslash( $_REQUEST['form_id'] ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification
836 $count = 0;
837
838 if ( $doaction ) {
839 check_admin_referer( 'bulk-entries' );
840
841 $sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted' ), wp_get_referer() );
842 if ( ! $sendback ) {
843 $sendback = admin_url( 'admin.php?page=evf-entries' );
844 }
845 $sendback = add_query_arg( 'paged', $pagenum, $sendback );
846
847 if ( ! isset( $entry_ids ) ) {
848 wp_safe_redirect( $sendback );
849 exit;
850 }
851
852 switch ( $doaction ) {
853 case 'star':
854 case 'unstar':
855 foreach ( $entry_ids as $entry_id ) {
856 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
857 ++$count;
858 }
859 }
860
861 add_settings_error(
862 'bulk_action',
863 'bulk_action',
864 /* translators: %d: number of entries, %s: entries status */
865 sprintf( _n( '%1$d entry successfully %2$s.', '%1$d entries successfully %2$s.', $count, 'everest-forms' ), $count, 'star' === $doaction ? 'starred' : 'unstarred' ),
866 'updated'
867 );
868 break;
869 case 'read':
870 case 'unread':
871 foreach ( $entry_ids as $entry_id ) {
872 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
873 ++$count;
874 }
875 }
876
877 add_settings_error(
878 'bulk_action',
879 'bulk_action',
880 /* translators: %d: number of entries, %s: entries status */
881 sprintf( _n( '%1$d entry successfully marked as %2$s.', '%1$d entries successfully marked as %2$s.', $count, 'everest-forms' ), $count, $doaction ),
882 'updated'
883 );
884 break;
885 case 'approved':
886 foreach ( $entry_ids as $entry_id ) {
887 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
888 $admin_email = esc_attr( get_bloginfo( 'admin_email' ) );
889 $header = "Reply-To: {$admin_email} \r\n";
890 $header .= 'Content-Type: text/html; charset=UTF-8';
891 $subject = '';
892 $message = '';
893
894 $entry = evf_get_entry( $entry_id );
895 $entry_date = $entry->date_created;
896 $entry_data = $entry->meta;
897 $site_name = get_option( 'blogname' );
898
899 $first_name = '';
900 $last_name = '';
901 $email = '';
902 $name = '';
903
904 foreach ( $entry_data as $key => $value ) {
905 if ( preg_match( '/^name/', $key ) ) {
906 $name = $value;
907 }
908
909 if ( preg_match( '/^first_name_/', $key ) ) {
910 $first_name = $value;
911 }
912
913 if ( preg_match( '/^last_name_/', $key ) ) {
914 $last_name = $value;
915 }
916
917 if ( preg_match( '/^email/', $key ) ) {
918 $email = $value;
919 }
920
921 if ( '' === $name ) {
922 if ( ! empty( $first_name ) && ! empty( $last_name ) ) {
923 $name = $first_name . ' ' . $last_name;
924 } elseif ( ! empty( $first_name ) ) {
925 $name = $first_name;
926 } else {
927 $name = $last_name;
928 }
929 } else {
930 $name = $name;
931 }
932
933 $subject = apply_filters( 'everest_forms_entry_submission_approval_subject', esc_html__( 'Form Entry Approved', 'everest-forms' ) );
934 /* translators:%s: User name of form entry */
935 $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>';
936 /* translators:%s: Form Entry Date */
937 $message .= '<br/>' . sprintf( __( 'We’re pleased to inform you that your form entry submitted on %s has been successfully approved.', 'everest-forms' ), $entry_date ) . '<br/>';
938 $message .= '<br/>' . __( 'Thank you for giving us your precious time', 'everest-forms' ) . '<br/>';
939 /* translators:%s: Site Name */
940 $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name );
941 $message = apply_filters( 'everest_forms_entry_approval_message', $message, $name, $entry_date, $site_name );
942 }
943 $email_obj = new EVF_Emails();
944 $email_obj->send( $email, $subject, $message );
945 ++$count;
946 }
947 }
948 break;
949 case 'denied':
950 foreach ( $entry_ids as $entry_id ) {
951 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
952 $admin_email = esc_attr( get_bloginfo( 'admin_email' ) );
953 $header = "Reply-To: {$admin_email} \r\n";
954 $header .= 'Content-Type: text/html; charset=UTF-8';
955 $subject = '';
956 $message = '';
957
958 $entry = evf_get_entry( $entry_id );
959 $entry_date = $entry->date_created;
960 $entry_data = $entry->meta;
961 $site_name = get_option( 'blogname' );
962
963 $first_name = '';
964 $last_name = '';
965 $email = '';
966 $name = '';
967
968 foreach ( $entry_data as $key => $value ) {
969 if ( preg_match( '/^name/', $key ) ) {
970 $name = $value;
971 }
972
973 if ( preg_match( '/^first_name_/', $key ) ) {
974 $first_name = $value;
975 }
976
977 if ( preg_match( '/^last_name_/', $key ) ) {
978 $last_name = $value;
979 }
980
981 if ( preg_match( '/^email/', $key ) ) {
982 $email = $value;
983 }
984
985 if ( '' === $name ) {
986 if ( ! empty( $first_name ) && ! empty( $last_name ) ) {
987 $name = $first_name . ' ' . $last_name;
988 } elseif ( ! empty( $first_name ) ) {
989 $name = $first_name;
990 } else {
991 $name = $last_name;
992 }
993 } else {
994 $name = $name;
995 }
996
997 $subject = apply_filters( 'everest_forms_entry_submission_denial_subject', esc_html__( 'Form Entry Denied', 'everest-forms' ) );
998 /* translators:%s: User name of form entry */
999 $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>';
1000 /* translators:%s: Form Entry Date */
1001 $message .= '<br/>' . sprintf( __( 'We regret to inform you that your form entry submitted on %s has been denied.', 'everest-forms' ), $entry_date ) . '<br/>';
1002 $message .= '<br/>' . __( 'Thank you for giving us your precious time', 'everest-forms' ) . '<br/>';
1003 /* translators:%s: Site Name */
1004 $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name );
1005 $message = apply_filters( 'everest_forms_entry_denial_message', $message, $name, $entry_date, $site_name );
1006 }
1007 $email_obj = new EVF_Emails();
1008 $email_obj->send( $email, $subject, $message );
1009 ++$count;
1010 }
1011 }
1012 break;
1013 case 'trash':
1014 foreach ( $entry_ids as $entry_id ) {
1015 if ( EVF_Admin_Entries::update_status( $entry_id, 'trash' ) ) {
1016 ++$count;
1017 }
1018 }
1019
1020 add_settings_error(
1021 'bulk_action',
1022 'bulk_action',
1023 /* translators: %d: number of entries */
1024 sprintf( _n( '%d entry moved to the Trash.', '%d entries moved to the Trash.', $count, 'everest-forms' ), $count ),
1025 'updated'
1026 );
1027 break;
1028 case 'untrash':
1029 foreach ( $entry_ids as $entry_id ) {
1030 if ( EVF_Admin_Entries::update_status( $entry_id, 'publish' ) ) {
1031 ++$count;
1032 }
1033 }
1034
1035 add_settings_error(
1036 'bulk_action',
1037 'bulk_action',
1038 /* translators: %d: number of entries */
1039 sprintf( _n( '%d entry restored from the Trash.', '%d entries restored from the Trash.', $count, 'everest-forms' ), $count ),
1040 'updated'
1041 );
1042 break;
1043 case 'delete':
1044 foreach ( $entry_ids as $entry_id ) {
1045 if ( EVF_Admin_Entries::remove_entry( $entry_id, $form_id ) ) {
1046 ++$count;
1047 }
1048 }
1049
1050 add_settings_error(
1051 'bulk_action',
1052 'bulk_action',
1053 /* translators: %d: number of entries */
1054 sprintf( _n( '%d entry permanently deleted.', '%d entries permanently deleted.', $count, 'everest-forms' ), $count ),
1055 'updated'
1056 );
1057 break;
1058 case 'spam':
1059 foreach ( $entry_ids as $entry_id ) {
1060 if ( EVF_Admin_Entries::update_status( $entry_id, 'spam' ) ) {
1061 ++$count;
1062 }
1063 }
1064
1065 add_settings_error(
1066 'bulk_action',
1067 'bulk_action',
1068 /* translators: %d: number of entries */
1069 sprintf( _n( '%d entry sent to spam.', '%d entries sent to Spam.', $count, 'everest-forms' ), $count ),
1070 'updated'
1071 );
1072 break;
1073 case 'unspam':
1074 foreach ( $entry_ids as $entry_id ) {
1075 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
1076 ++$count;
1077 }
1078 }
1079
1080 add_settings_error(
1081 'bulk_action',
1082 'bulk_action',
1083 /* translators: %d: number of entries */
1084 sprintf( _n( '%d removed from spam.', '%d entries removed from spam.', $count, 'everest-forms' ), $count ),
1085 'updated'
1086 );
1087 break;
1088 }
1089 $sendback = remove_query_arg( array( 'action', 'action2' ), $sendback );
1090
1091 wp_safe_redirect( $sendback );
1092 exit();
1093 } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) && isset( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1094 wp_safe_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
1095 exit();
1096 }
1097 }
1098
1099 /**
1100 * Extra controls to be displayed between bulk actions and pagination.
1101 *
1102 * @param string $which The location of the extra table nav markup.
1103 */
1104 protected function extra_tablenav( $which ) {
1105 global $entries_table_list, $wpdb;
1106 $num_entries = ( 0 === $this->form_id ) ? $this->get_all_forms_entry_counts() : evf_get_count_entries_by_status( $this->form_id );
1107 $show_export = isset( $_GET['status'] ) && 'trash' === $_GET['status'] ? false : true; // phpcs:ignore WordPress.Security.NonceVerification
1108 ?>
1109 <div class="everest-forms-extra-table-nav">
1110 <?php
1111 if ( ! empty( $this->forms ) && 'top' === $which ) {
1112 if ( defined( 'EFP_VERSION' ) && $this->form_id > 0 ) {
1113 ?>
1114 <button
1115 type="button"
1116 class="button evf-manage-columns-btn everest-forms-entries-setting"
1117 id="evf-manage-columns"
1118 data-evf-form_id="<?php echo esc_attr( $this->form_id ); ?>"
1119 >
1120 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align: middle; margin-right: 6px;">
1121 <path d="M2 4.66667H14M2 8H14M2 11.3333H14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
1122 </svg>
1123 <?php esc_html_e( 'Manage Columns', 'everest-forms' ); ?>
1124 </button>
1125 <?php
1126 }
1127
1128 $this->status_dropdown( $num_entries );
1129
1130 // Export CSV submit button.
1131 if ( apply_filters( 'everest_forms_enable_csv_export', $show_export ) && current_user_can( 'export' ) && $this->form_id > 0 ) {
1132 ?>
1133 <button type="submit" name="export_action" value="1" class="button" id="export-csv-submit">
1134 <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="vertical-align: middle; margin-right: 6px;">
1135 <path d="M14 10V12.6667C14 13.0203 13.8595 13.3594 13.6095 13.6095C13.3594 13.8595 13.0203 14 12.6667 14H3.33333C2.97971 14 2.64057 13.8595 2.39052 13.6095C2.14048 13.3594 2 13.0203 2 12.6667V10M11.3333 5.33333L8 2M8 2L4.66667 5.33333M8 2V10" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
1136 </svg>
1137 <?php esc_html_e( 'Export CSV', 'everest-forms' ); ?>
1138 </button>
1139 <?php
1140 }
1141
1142 if ( $num_entries['trash'] && isset( $_GET['status'] ) && 'trash' === $_GET['status'] && current_user_can( 'manage_everest_forms' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1143 submit_button( __( 'Empty Trash', 'everest-forms' ), 'apply', 'delete_all', false );
1144 }
1145 }
1146 ?>
1147 </div>
1148 <?php
1149 do_action( 'everest_forms_entries_table_extra_filters', $this->form_id, $which );
1150 }
1151
1152 /**
1153 * Display a form dropdown for filtering entries.
1154 */
1155 public function forms_dropdown() {
1156 $forms = evf_get_all_forms( true );
1157 $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : $this->form_id; // phpcs:ignore WordPress.Security.NonceVerification
1158 ?>
1159 <label for="filter-by-form" class="screen-reader-text"><?php esc_html_e( 'Filter by form', 'everest-forms' ); ?></label>
1160 <select name="form_id" id="filter-by-form" class="evf-enhanced-normal-select evf-auto-filter" style="min-width: 200px;" data-placeholder="<?php esc_attr_e( 'Search form...', 'everest-forms' ); ?>">
1161 <option value="0" <?php selected( $form_id, 0 ); ?>><?php esc_html_e( 'All Forms', 'everest-forms' ); ?></option>
1162 <?php foreach ( $forms as $id => $form ) : ?>
1163 <option value="<?php echo esc_attr( $id ); ?>" <?php selected( $form_id, $id ); ?>><?php echo esc_html( $form ); ?></option>
1164 <?php endforeach; ?>
1165 </select>
1166 <?php
1167 }
1168
1169 /**
1170 * Display a status dropdown for filtering entries.
1171 */
1172 public function status_dropdown( $num_entries ) {
1173 $current_status = isset( $_REQUEST['status'] ) ? sanitize_key( wp_unslash( $_REQUEST['status'] ) ) : '';
1174
1175 $statuses = array(
1176 'all' => __( 'All', 'everest-forms' ),
1177 'unread' => __( 'Unread', 'everest-forms' ),
1178 'read' => __( 'Read', 'everest-forms' ),
1179 'spam' => __( 'Spam', 'everest-forms' ),
1180 'trash' => __( 'Trash', 'everest-forms' ),
1181 );
1182
1183 if ( ! empty( $this->form_data ) ) {
1184 $extra_statuses = evf_get_entry_statuses( $this->form_data );
1185 foreach ( $extra_statuses as $key => $label ) {
1186 if ( ! isset( $statuses[ $key ] ) && 'publish' !== $key ) {
1187 $statuses[ $key ] = $label;
1188 }
1189 }
1190 }
1191
1192 // Map status keys to count keys.
1193 $count_map = array(
1194 'all' => 'publish',
1195 'unread' => 'unread',
1196 'read' => 'read',
1197 'spam' => 'spam',
1198 'trash' => 'trash',
1199 );
1200 ?>
1201 <select name="status" id="filter-by-status" class="evf-enhanced-normal-select evf-auto-filter">
1202 <?php
1203 foreach ( $statuses as $key => $label ) :
1204 $count_key = isset( $count_map[ $key ] ) ? $count_map[ $key ] : $key;
1205 $count = isset( $num_entries[ $count_key ] ) ? (int) $num_entries[ $count_key ] : 0;
1206 $display = sprintf( '%s (%d)', $label, $count );
1207 ?>
1208 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $current_status, $key ); ?>>
1209 <?php echo esc_html( $display ); ?>
1210 </option>
1211 <?php endforeach; ?>
1212 </select>
1213 <?php
1214 }
1215
1216
1217 /**
1218 * Prepare table list items.
1219 */
1220 public function prepare_items() {
1221 $per_page = $this->get_items_per_page( 'evf_entries_per_page' );
1222 $current_page = $this->get_pagenum();
1223
1224 // Query args.
1225 $args = array(
1226 'status' => 'publish',
1227 'form_id' => $this->form_id,
1228 'limit' => $per_page,
1229 'offset' => $per_page * ( $current_page - 1 ),
1230 );
1231
1232 // Handle the status query.
1233 if ( ! empty( $_REQUEST['status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1234 $status = sanitize_key( wp_unslash( $_REQUEST['status'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1235
1236 if ( 'unread' === $status ) {
1237 $args['status'] = 'publish';
1238 $args['viewed'] = 0;
1239 } elseif ( 'read' === $status ) {
1240 $args['status'] = 'publish';
1241 $args['viewed'] = 1;
1242 } elseif ( 'all' === $status ) {
1243 $args['status'] = 'publish';
1244 } else {
1245 $args['status'] = $status;
1246 }
1247 }
1248
1249 // Handle the search query.
1250 if ( ! empty( $_REQUEST['s'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1251 $args['search'] = sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1252 }
1253
1254 if ( ! empty( $_REQUEST['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1255 $args['orderby'] = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1256 }
1257
1258 if ( ! empty( $_REQUEST['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1259 $args['order'] = sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1260 }
1261
1262 // Get the entries.
1263 $entries = evf_search_entries( $args );
1264 $this->items = array_map( 'evf_get_entry', $entries );
1265
1266 // Get total items.
1267 $args['limit'] = -1;
1268 $args['offset'] = 0;
1269 $total_items = count( evf_search_entries( $args ) );
1270
1271 // Set the pagination.
1272 $this->set_pagination_args(
1273 array(
1274 'total_items' => $total_items,
1275 'per_page' => $per_page,
1276 'total_pages' => ceil( $total_items / $per_page ),
1277 )
1278 );
1279 }
1280 }
1281