PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.3
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 1 week ago form-migrator 2 months ago plugin-updates 8 years ago settings 1 week ago views 1 week ago class-evf-admin-addons.php 5 months ago class-evf-admin-assets.php 1 week ago class-evf-admin-builder.php 3 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 week ago class-evf-admin-entries.php 1 week ago class-evf-admin-form-templates.php 2 months ago class-evf-admin-forms-table-list.php 5 months ago class-evf-admin-forms.php 5 months ago class-evf-admin-import-export.php 2 months ago class-evf-admin-menus.php 1 week ago class-evf-admin-notices.php 5 months ago class-evf-admin-preview-confirmation.php 1 year ago class-evf-admin-settings.php 2 months ago class-evf-admin-tools.php 3 months ago class-evf-admin-welcome.php 2 years ago class-evf-admin.php 3 months ago class-evf-base-list-table.php 5 months ago evf-admin-functions.php 2 months ago
class-evf-admin-entries-table-list.php
1292 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 $key = array_search( 'sn', $entry_columns, true );
184 if ( false !== $key ) {
185 unset( $entry_columns[ $key ] );
186 $entry_columns = array_merge( array( 'sn' ), $entry_columns );
187 }
188
189 $key = array_search( 'id', $entry_columns, true );
190 if ( false !== $key ) {
191 unset( $entry_columns[ $key ] );
192 $entry_columns = array_merge( array( 'id' ), $entry_columns );
193 }
194 foreach ( $entry_columns as $id ) {
195 // Check to make sure the field as not been removed.
196 $status = defined( 'EFP_VERSION' ) ? true : false;
197 $status = apply_filters( 'everest_forms_plugin_active_status', $status );
198 if ( empty( $this->form_data['form_fields'][ $id ] ) ) {
199 if ( $status ) {
200 if ( 'sn' === $id ) {
201 $extra_column = apply_filters( 'everest_forms_entries_table_extra_columns', array(), 0, array() );
202 $columns = array_merge( $columns, $extra_column );
203 }
204 if ( 'id' === $id ) {
205 $extra_column = apply_filters( 'everest_forms_entries_table_extra_columns_id', array(), 0, array() );
206 $columns = array_merge( $columns, $extra_column );
207 }
208 }
209 continue;
210 }
211
212 $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' );
213 }
214 }
215
216 return apply_filters( 'everest_forms_entries_table_form_field_columns', $columns, $this->form_id, $this->form_data );
217 }
218
219 /**
220 * Column cb.
221 *
222 * @param object $entry Entry object.
223 * @return string
224 */
225 public function column_cb( $entry ) {
226 return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $entry->entry_id );
227 }
228
229 /**
230 * Column for simplified "Entry" view (All Forms only)
231 *
232 * @param object $entry Entry object.
233 * @return string
234 */
235 public function column_entry( $entry ) {
236 if ( empty( $entry->meta ) ) {
237 return '<span class="na">&mdash;</span>';
238 }
239
240 // Skip system fields
241 $skip_fields = array( 'entry_id', 'form_id', 'user_id', 'user_device', 'user_ip_address', 'viewed', 'starred', 'status' );
242
243 // Upload fields store only the hashed file URL in entry meta, so map each
244 // upload field's meta key to its original file name(s) from the full
245 // entry fields. This keeps the preview readable (e.g. "photo.png") instead
246 // of the full URL / hashed file name. See EVF-2095.
247 $upload_names = $this->get_upload_field_names( $entry );
248
249 // Find first non-empty field value
250 foreach ( $entry->meta as $key => $value ) {
251 if ( in_array( $key, $skip_fields, true ) || strpos( $key, '_' ) === 0 ) {
252 continue;
253 }
254
255 // Prefer the original file name(s) for upload fields.
256 if ( isset( $upload_names[ $key ] ) && '' !== $upload_names[ $key ] ) {
257 return $upload_names[ $key ];
258 }
259
260 // Process the value
261 $field_value = $this->process_field_value( $value );
262
263 if ( ! empty( $field_value ) && '&mdash;' !== $field_value ) {
264 return $field_value;
265 }
266 }
267
268 return '<span class="na">&mdash;</span>';
269 }
270
271 /**
272 * Build a map of upload field meta keys to their original file name(s).
273 *
274 * Entry meta only stores the public file URL (with a hashed file name), so
275 * the original names are read from the full entry fields payload. See EVF-2095.
276 *
277 * @param object $entry Entry object.
278 * @return array Map of meta key => escaped, comma-separated original file names.
279 */
280 private function get_upload_field_names( $entry ) {
281 $names = array();
282
283 $fields = isset( $entry->fields ) ? evf_decode( $entry->fields ) : array();
284
285 if ( empty( $fields ) || ! is_array( $fields ) ) {
286 return $names;
287 }
288
289 foreach ( $fields as $field ) {
290 if ( empty( $field['meta_key'] ) || empty( $field['type'] ) ) {
291 continue;
292 }
293
294 if ( ! in_array( $field['type'], array( 'image-upload', 'file-upload' ), true ) ) {
295 continue;
296 }
297
298 if ( empty( $field['value_raw'] ) || ! is_array( $field['value_raw'] ) ) {
299 continue;
300 }
301
302 $file_names = array();
303 foreach ( $field['value_raw'] as $file ) {
304 if ( ! empty( $file['file_original'] ) ) {
305 $file_names[] = $file['file_original'];
306 } elseif ( ! empty( $file['name'] ) ) {
307 $file_names[] = $file['name'];
308 }
309 }
310
311 if ( ! empty( $file_names ) ) {
312 $names[ $field['meta_key'] ] = esc_html( implode( ', ', $file_names ) );
313 }
314 }
315
316 return $names;
317 }
318
319 /**
320 * Column for form name (All Forms view only)
321 *
322 * @param object $entry Entry object.
323 * @return string
324 */
325 public function column_form( $entry ) {
326 $form_title = get_the_title( $entry->form_id );
327
328 if ( empty( $form_title ) ) {
329 return '&mdash;';
330 }
331
332 return '<a href="' . esc_url( admin_url( 'admin.php?page=evf-entries&form_id=' . $entry->form_id ) ) . '">' . esc_html( $form_title ) . '</a>';
333 }
334
335 /**
336 * Process field value for display
337 *
338 * @param mixed $value Field value.
339 * @return string Processed value.
340 */
341 private function process_field_value( $value ) {
342 if ( empty( $value ) ) {
343 return '&mdash;';
344 }
345
346 if ( evf_is_json( $value ) ) {
347 $field_value = json_decode( $value, true );
348 $value = isset( $field_value['value'] ) ? $field_value['value'] : $value;
349 }
350
351 if ( is_serialized( $value ) ) {
352 $field_value = evf_maybe_unserialize( $value );
353 $field_label = ! empty( $field_value['label'] ) ? evf_clean( $field_value['label'] ) : $field_value;
354
355 if ( is_array( $field_label ) ) {
356 $value = implode( ', ', array_map( 'esc_html', $field_label ) );
357 } else {
358 $value = esc_html( $field_label );
359 }
360 }
361
362 if ( is_array( $value ) ) {
363 if ( isset( $value['label'] ) ) {
364 $value = is_array( $value['label'] ) ? implode( ', ', $value['label'] ) : $value['label'];
365 } else {
366 $value = implode( ', ', $value );
367 }
368 }
369
370 if ( is_string( $value ) && filter_var( $value, FILTER_VALIDATE_URL ) ) {
371 $path = wp_parse_url( $value, PHP_URL_PATH );
372 if ( ! empty( $path ) ) {
373 $value = basename( $path );
374 }
375 }
376
377 $value = (string) $value;
378 if ( strlen( $value ) > 100 ) {
379 $value = substr( $value, 0, 100 ) . '&hellip;';
380 }
381
382 $value = wp_strip_all_tags( trim( $value ) );
383
384 return $value;
385 }
386
387
388
389 /**
390 * Show specific form fields (for specific form view).
391 *
392 * @param object $entry Entry object.
393 * @param string $column_name Column Name.
394 * @return string
395 */
396 public function column_form_field( $entry, $column_name ) {
397 $field_id = str_replace( 'evf_field_', '', $column_name );
398 $meta_key = isset( $this->form_data['form_fields'][ $field_id ]['meta-key'] ) ? strtolower( $this->form_data['form_fields'][ $field_id ]['meta-key'] ) : $field_id;
399 $field_type = isset( $this->form_data['form_fields'][ $field_id ]['type'] ) ? $this->form_data['form_fields'][ $field_id ]['type'] : '';
400
401 if ( ! empty( $entry->meta[ $meta_key ] ) || ( isset( $entry->meta[ $meta_key ] ) && is_numeric( $entry->meta[ $meta_key ] ) ) ) {
402 $value = $entry->meta[ $meta_key ];
403 if ( evf_is_json( $value ) ) {
404 $field_value = json_decode( $value, true );
405 $decoded = isset( $field_value['value'] ) ? $field_value['value'] : $field_value;
406
407 // Coupons field stores data on array.
408 if ( is_array( $decoded ) ) {
409 $codes = array();
410 foreach ( $decoded as $item ) {
411 if ( is_array( $item ) && ! empty( $item['code'] ) ) {
412 $codes[] = esc_html( $item['code'] );
413 }
414 }
415 $value = ! empty( $codes ) ? implode( ', ', $codes ) : implode( ', ', array_filter( array_map( 'strval', $decoded ) ) );
416 } else {
417 $value = $decoded;
418 }
419 }
420
421 if ( is_serialized( $value ) ) {
422 $field_html = array();
423 $field_value = evf_maybe_unserialize( $value );
424
425 $field_label = ! empty( $field_value['label'] ) ? evf_clean( $field_value['label'] ) : $field_value;
426 if ( is_array( $field_label ) ) {
427 foreach ( $field_label as $item ) {
428 // Coupon field: each item is an array with 'code', 'discount_type', etc.
429 if ( is_array( $item ) ) {
430 if ( ! empty( $item['code'] ) ) {
431 $field_html[] = esc_html( $item['code'] );
432 }
433 } else {
434 $field_html[] = esc_html( $item );
435 }
436 }
437
438 $value = implode( ', ', $field_html );
439 } else {
440 $value = esc_html( $field_label );
441 }
442 }
443
444 $value = isset( $value['label'] ) && is_array( $value['label'] ) ? implode( ', ', $value['label'] ) : ( is_array( $value ) ? implode( ', ', $value ) : $value );
445
446 $value = (string) $value;
447
448 if ( false === strpos( $value, 'http' ) ) {
449 $lines = explode( "\n", $value );
450 $value = array_slice( $lines, 0, 4 );
451 $value = implode( "\n", $value );
452
453 if ( count( $lines ) > 5 ) {
454 $value .= '&hellip;';
455 } elseif ( strlen( $value ) > 75 ) {
456 $value = substr( $value, 0, 75 ) . '&hellip;';
457 }
458
459 $value = nl2br( wp_strip_all_tags( trim( $value ) ) );
460 }
461 $value = apply_filters( 'everest_forms_html_field_value', $value, $entry->meta[ $meta_key ], $entry, 'entry-table', $meta_key );
462
463 if ( in_array( $field_type, array( 'file-upload', 'image-upload', 'signature', 'wysiwyg', 'color', 'rating', 'country', 'likert', 'checkbox', 'radio', 'repeater-fields', 'payment-checkbox' ), true ) ) {
464 return nl2br( make_clickable( $value ) );
465 }elseif( 'address' === $field_type ){
466 $allowed_tags = array(
467 'br' => array(),
468 'span' => array(),
469 'p' => array(),
470 );
471
472 $output = nl2br( $value );
473 return wp_kses( $output, $allowed_tags );
474 }
475 else{
476 return esc_html( $value );
477 }
478 } else {
479 return '<span class="na">&mdash;</span>';
480 }
481 }
482
483 /**
484 * Renders the columns.
485 *
486 * @param object $entry Entry object.
487 * @param string $column_name Column Name.
488 * @return string
489 */
490 public function column_default( $entry, $column_name ) {
491 switch ( $column_name ) {
492 case 'id':
493 $value = absint( $entry->entry_id );
494 break;
495
496 case 'date':
497 $value = date_i18n(
498 'Y/m/d',
499 strtotime( $entry->date_created ) + ( get_option( 'gmt_offset' ) * 3600 )
500 );
501
502 break;
503
504 case 'sn':
505 $position = array_search( $entry, $this->items, true );
506 $value = $position + 1;
507 break;
508
509 case 'entry':
510 $value = $this->column_entry( $entry );
511 break;
512
513 case 'form':
514 $value = $this->column_form( $entry );
515 break;
516
517 default:
518 if ( false !== strpos( $column_name, 'evf_field_' ) ) {
519 $value = $this->column_form_field( $entry, $column_name );
520 } else {
521 $value = '';
522 }
523 break;
524 }
525
526 return apply_filters( 'everest_forms_entry_table_column_value', $value, $entry, $column_name );
527 }
528
529 /**
530 * Get row actions for an entry.
531 *
532 * @param object $entry Entry object.
533 * @return array
534 */
535 protected function get_row_actions( $entry ) {
536 $actions = array();
537 $status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '';
538
539 if ( 'trash' !== $entry->status ) {
540 if ( current_user_can( 'everest_forms_view_entry', $entry->entry_id ) ) {
541 $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>';
542 }
543
544 $user_can_edit_entry = is_admin() && current_user_can( 'everest_forms_edit_entry', $entry->entry_id );
545
546 if ( $user_can_edit_entry ) {
547 switch ( $status ) {
548 case 'spam':
549 $actions['unspam'] = '<a href="' . esc_url(
550 wp_nonce_url(
551 add_query_arg(
552 array(
553 'unspam-entry' => $entry->entry_id,
554 'form_id' => $entry->form_id,
555 ),
556 admin_url( 'admin.php?page=evf-entries' )
557 ),
558 'unspam-entry'
559 )
560 ) . '">' . esc_html__( 'Remove From Spam', 'everest-forms' ) . '</a>';
561 break;
562 default:
563 $actions['spam'] = '<a href="' . esc_url(
564 wp_nonce_url(
565 add_query_arg(
566 array(
567 'spam-entry' => $entry->entry_id,
568 'form_id' => $entry->form_id,
569 ),
570 admin_url( 'admin.php?page=evf-entries' )
571 ),
572 'spam-entry'
573 )
574 ) . '">' . esc_html__( 'Mark as Spam', 'everest-forms' ) . '</a>';
575 break;
576 }
577 }
578
579 if ( current_user_can( 'everest_forms_delete_entry', $entry->entry_id ) ) {
580 /* translators: %s: entry name */
581 $actions['trash'] = '<a class="submitdelete" aria-label="' . esc_attr__( 'Trash form entry', 'everest-forms' ) . '" href="' . esc_url(
582 wp_nonce_url(
583 add_query_arg(
584 array(
585 'trash' => $entry->entry_id,
586 'form_id' => $this->form_id,
587 ),
588 admin_url( 'admin.php?page=evf-entries' )
589 ),
590 'trash-entry'
591 )
592 ) . '">' . esc_html__( 'Trash', 'everest-forms' ) . '</a>';
593 }
594 } else {
595 if ( current_user_can( 'everest_forms_edit_entry', $entry->entry_id ) ) {
596 $actions['untrash'] = '<a aria-label="' . esc_attr__( 'Restore form entry from trash', 'everest-forms' ) . '" href="' . esc_url(
597 wp_nonce_url(
598 add_query_arg(
599 array(
600 'untrash' => $entry->entry_id,
601 'form_id' => $this->form_id,
602 ),
603 admin_url( 'admin.php?page=evf-entries' )
604 ),
605 'untrash-entry'
606 )
607 ) . '">' . esc_html__( 'Restore', 'everest-forms' ) . '</a>';
608 }
609
610 if ( current_user_can( 'everest_forms_delete_entry', $entry->entry_id ) ) {
611 /* translators: %s: entry name */
612 $actions['delete'] = '<a class="submitdelete" aria-label="' . esc_attr__( 'Delete form entry permanently', 'everest-forms' ) . '" href="' . esc_url(
613 wp_nonce_url(
614 add_query_arg(
615 array(
616 'delete' => $entry->entry_id,
617 'form_id' => $this->form_id,
618 ),
619 admin_url( 'admin.php?page=evf-entries' )
620 ),
621 'delete-entry'
622 )
623 ) . '">' . esc_html__( 'Delete Permanently', 'everest-forms' ) . '</a>';
624 }
625 }
626
627 return apply_filters( 'everest_forms_entry_table_actions', $actions, $entry );
628 }
629
630 /**
631 * Render the actions column.
632 *
633 * @param object $entry Entry object.
634 * @return string
635 */
636 public function column_actions( $entry ) {
637 $actions = $this->get_row_actions( $entry );
638 return implode( ' <span class="sep">|</span> ', $actions );
639 }
640
641 /**
642 * Handle row actions for the primary column.
643 *
644 * @param object $entry Entry object.
645 * @param string $column_name Current column name.
646 * @param string $primary Primary column name.
647 * @return string
648 */
649 protected function handle_row_actions( $entry, $column_name, $primary ) {
650 if ( $primary !== $column_name ) {
651 return '';
652 }
653
654 $actions = $this->get_row_actions( $entry );
655 return $this->row_actions( $actions, false );
656 }
657
658 /**
659 * Get the name of the primary column.
660 *
661 * @return string
662 */
663 protected function get_primary_column_name() {
664 // For All Forms view
665 if ( 0 === $this->form_id ) {
666 return 'entry';
667 }
668
669 // For specific form view - use existing logic
670 $columns = $this->get_columns();
671
672 unset( $columns['cb'], $columns['actions'], $columns['more'] );
673
674 $primary = '';
675 if ( ! empty( $columns ) ) {
676 foreach ( $columns as $column_key => $column_name ) {
677 if ( strpos( $column_key, 'evf_field_' ) === 0 ) {
678 $primary = $column_key;
679 break;
680 }
681 }
682
683 if ( empty( $primary ) ) {
684 reset( $columns );
685 $primary = key( $columns );
686 }
687 }
688
689 return $primary;
690 }
691
692 /**
693 * Get the status label for entries.
694 *
695 * @param string $status_name Status name.
696 * @param int $amount Amount of entries.
697 * @return array
698 */
699 private function get_status_label( $status_name, $amount ) {
700 $statuses = evf_get_entry_statuses( $this->form_data );
701
702 if ( isset( $statuses[ $status_name ] ) ) {
703 return array(
704 'singular' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ),
705 'plural' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ),
706 'context' => '',
707 'domain' => 'everest-forms',
708 );
709 }
710
711 return array(
712 'singular' => sprintf( '%s <span class="count">(<span class="%s-count">%s</span>)</span>', esc_html( $statuses[ $status_name ] ), $status_name, $amount ),
713 'plural' => sprintf( '%s <span class="count">(%s)</span>', esc_html( $status_name ), $amount ),
714 'context' => '',
715 'domain' => 'everest-forms',
716 );
717 }
718
719 /**
720 * Table list views.
721 *
722 * @return array
723 */
724 protected function get_views() {
725
726 return array();
727
728 // $status_links = array();
729
730 // if ( 0 === $this->form_id ) {
731 // $num_entries = $this->get_all_forms_entry_counts();
732 // } else {
733 // $num_entries = evf_get_count_entries_by_status( $this->form_id );
734 // }
735
736 // $total_entries = apply_filters( 'everest_forms_total_entries_count', (int) $num_entries['publish'], $num_entries, $this->form_id );
737 // $spam_entries = apply_filters( 'everest_forms_spam_total_entries_count', (int) $num_entries['spam'], $num_entries, $this->form_id );
738
739 // $statuses = array_keys( evf_get_entry_statuses( $this->form_data ) );
740 // $class = empty( $_REQUEST['status'] ) ? ' class="current"' : ''; // phpcs:ignore WordPress.Security.NonceVerification
741
742 // $base_url = admin_url( 'admin.php?page=evf-entries' );
743 // if ( $this->form_id > 0 ) {
744 // $base_url = add_query_arg( 'form_id', $this->form_id, $base_url );
745 // }
746
747 // /* translators: %s: count */
748 // $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>';
749
750 // /* translators: %s: count */
751 // $spam_url = add_query_arg( 'status', 'spam', $base_url );
752 // $spam_class = ( isset( $_REQUEST['status'] ) && 'spam' === $_REQUEST['status'] ) ? ' class="current"' : '';
753 // $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>';
754
755 // foreach ( $statuses as $status_name ) {
756 // if ( 'publish' === $status_name ) {
757 // continue;
758 // }
759
760 // if ( isset( $_REQUEST['status'] ) && sanitize_key( wp_unslash( $_REQUEST['status'] ) ) === $status_name ) { // phpcs:ignore WordPress.Security.NonceVerification
761 // $class = ' class="current"';
762 // } else {
763 // $class = '';
764 // }
765
766 // $label = $this->get_status_label( $status_name, $num_entries[ $status_name ] );
767 // $status_url = add_query_arg( 'status', $status_name, $base_url );
768
769 // $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>';
770 // }
771
772 // return apply_filters( 'everest_forms_entries_table_views', $status_links, $num_entries, $this->form_data );
773 }
774
775 /**
776 * Get entry counts across all forms
777 *
778 * @return array
779 */
780 private function get_all_forms_entry_counts() {
781 global $wpdb;
782
783 // Initialize counts array with default counts for each status
784 $counts = array(
785 'publish' => 0,
786 'spam' => 0,
787 'trash' => 0,
788 'pending' => 0,
789 'denied' => 0,
790 'unread' => 0,
791 'read' => 0,
792 'starred' => 0, // Add starred count
793 );
794
795 $results = $wpdb->get_results( "SELECT status, COUNT(*) as count FROM {$wpdb->prefix}evf_entries GROUP BY status" );
796
797 foreach ( $results as $row ) {
798 $counts[ $row->status ] = (int) $row->count;
799 }
800
801 // Count the unread entries (viewed = 0, status != 'trash')
802 $unread_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE viewed = 0 AND status != 'trash'" );
803
804 $read_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE viewed = 1 AND status != 'trash'" );
805
806 $counts['unread'] = (int) $unread_count;
807 $counts['read'] = (int) $read_count;
808
809 $starred_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}evf_entries WHERE starred = 1 AND status != 'trash'" );
810
811 $counts['starred'] = (int) $starred_count;
812
813 return $counts;
814 }
815
816
817 /**
818 * Get bulk actions.
819 *
820 * @return array
821 */
822 protected function get_bulk_actions() {
823 if ( isset( $_GET['status'] ) && 'trash' === $_GET['status'] ) { // phpcs:ignore WordPress.Security.NonceVerification
824 $actions = array(
825 'untrash' => __( 'Restore', 'everest-forms' ),
826 'delete' => __( 'Delete Permanently', 'everest-forms' ),
827 );
828 } else {
829 $actions = array(
830 'trash' => __( 'Move to Trash', 'everest-forms' ),
831 );
832 }
833
834 return apply_filters( 'everest_forms_entry_bulk_actions', $actions );
835 }
836
837 /**
838 * Process bulk actions.
839 *
840 * @since 1.2.0
841 */
842 public function process_bulk_action() {
843 $pagenum = $this->get_pagenum();
844 $doaction = $this->current_action();
845 $entry_ids = isset( $_REQUEST['entry'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['entry'] ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification
846 $form_id = isset( $_REQUEST['form_id'] ) ? sanitize_key( wp_unslash( $_REQUEST['form_id'] ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification
847 $count = 0;
848
849 if ( $doaction ) {
850 check_admin_referer( 'bulk-entries' );
851
852 $sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted' ), wp_get_referer() );
853 if ( ! $sendback ) {
854 $sendback = admin_url( 'admin.php?page=evf-entries' );
855 }
856 $sendback = add_query_arg( 'paged', $pagenum, $sendback );
857
858 if ( ! isset( $entry_ids ) ) {
859 wp_safe_redirect( $sendback );
860 exit;
861 }
862
863 switch ( $doaction ) {
864 case 'star':
865 case 'unstar':
866 foreach ( $entry_ids as $entry_id ) {
867 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
868 ++$count;
869 }
870 }
871
872 add_settings_error(
873 'bulk_action',
874 'bulk_action',
875 /* translators: %d: number of entries, %s: entries status */
876 sprintf( _n( '%1$d entry successfully %2$s.', '%1$d entries successfully %2$s.', $count, 'everest-forms' ), $count, 'star' === $doaction ? 'starred' : 'unstarred' ),
877 'updated'
878 );
879 break;
880 case 'read':
881 case 'unread':
882 foreach ( $entry_ids as $entry_id ) {
883 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
884 ++$count;
885 }
886 }
887
888 add_settings_error(
889 'bulk_action',
890 'bulk_action',
891 /* translators: %d: number of entries, %s: entries status */
892 sprintf( _n( '%1$d entry successfully marked as %2$s.', '%1$d entries successfully marked as %2$s.', $count, 'everest-forms' ), $count, $doaction ),
893 'updated'
894 );
895 break;
896 case 'approved':
897 foreach ( $entry_ids as $entry_id ) {
898 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
899 $admin_email = esc_attr( get_bloginfo( 'admin_email' ) );
900 $header = "Reply-To: {$admin_email} \r\n";
901 $header .= 'Content-Type: text/html; charset=UTF-8';
902 $subject = '';
903 $message = '';
904
905 $entry = evf_get_entry( $entry_id );
906 $entry_date = $entry->date_created;
907 $entry_data = $entry->meta;
908 $site_name = get_option( 'blogname' );
909
910 $first_name = '';
911 $last_name = '';
912 $email = '';
913 $name = '';
914
915 foreach ( $entry_data as $key => $value ) {
916 if ( preg_match( '/^name/', $key ) ) {
917 $name = $value;
918 }
919
920 if ( preg_match( '/^first_name_/', $key ) ) {
921 $first_name = $value;
922 }
923
924 if ( preg_match( '/^last_name_/', $key ) ) {
925 $last_name = $value;
926 }
927
928 if ( preg_match( '/^email/', $key ) ) {
929 $email = $value;
930 }
931
932 if ( '' === $name ) {
933 if ( ! empty( $first_name ) && ! empty( $last_name ) ) {
934 $name = $first_name . ' ' . $last_name;
935 } elseif ( ! empty( $first_name ) ) {
936 $name = $first_name;
937 } else {
938 $name = $last_name;
939 }
940 } else {
941 $name = $name;
942 }
943
944 $subject = apply_filters( 'everest_forms_entry_submission_approval_subject', esc_html__( 'Form Entry Approved', 'everest-forms' ) );
945 /* translators:%s: User name of form entry */
946 $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>';
947 /* translators:%s: Form Entry Date */
948 $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/>';
949 $message .= '<br/>' . __( 'Thank you for giving us your precious time', 'everest-forms' ) . '<br/>';
950 /* translators:%s: Site Name */
951 $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name );
952 $message = apply_filters( 'everest_forms_entry_approval_message', $message, $name, $entry_date, $site_name );
953 }
954 $email_obj = new EVF_Emails();
955 $email_obj->send( $email, $subject, $message );
956 ++$count;
957 }
958 }
959 break;
960 case 'denied':
961 foreach ( $entry_ids as $entry_id ) {
962 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
963 $admin_email = esc_attr( get_bloginfo( 'admin_email' ) );
964 $header = "Reply-To: {$admin_email} \r\n";
965 $header .= 'Content-Type: text/html; charset=UTF-8';
966 $subject = '';
967 $message = '';
968
969 $entry = evf_get_entry( $entry_id );
970 $entry_date = $entry->date_created;
971 $entry_data = $entry->meta;
972 $site_name = get_option( 'blogname' );
973
974 $first_name = '';
975 $last_name = '';
976 $email = '';
977 $name = '';
978
979 foreach ( $entry_data as $key => $value ) {
980 if ( preg_match( '/^name/', $key ) ) {
981 $name = $value;
982 }
983
984 if ( preg_match( '/^first_name_/', $key ) ) {
985 $first_name = $value;
986 }
987
988 if ( preg_match( '/^last_name_/', $key ) ) {
989 $last_name = $value;
990 }
991
992 if ( preg_match( '/^email/', $key ) ) {
993 $email = $value;
994 }
995
996 if ( '' === $name ) {
997 if ( ! empty( $first_name ) && ! empty( $last_name ) ) {
998 $name = $first_name . ' ' . $last_name;
999 } elseif ( ! empty( $first_name ) ) {
1000 $name = $first_name;
1001 } else {
1002 $name = $last_name;
1003 }
1004 } else {
1005 $name = $name;
1006 }
1007
1008 $subject = apply_filters( 'everest_forms_entry_submission_denial_subject', esc_html__( 'Form Entry Denied', 'everest-forms' ) );
1009 /* translators:%s: User name of form entry */
1010 $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>';
1011 /* translators:%s: Form Entry Date */
1012 $message .= '<br/>' . sprintf( __( 'We regret to inform you that your form entry submitted on %s has been denied.', 'everest-forms' ), $entry_date ) . '<br/>';
1013 $message .= '<br/>' . __( 'Thank you for giving us your precious time', 'everest-forms' ) . '<br/>';
1014 /* translators:%s: Site Name */
1015 $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name );
1016 $message = apply_filters( 'everest_forms_entry_denial_message', $message, $name, $entry_date, $site_name );
1017 }
1018 $email_obj = new EVF_Emails();
1019 $email_obj->send( $email, $subject, $message );
1020 ++$count;
1021 }
1022 }
1023 break;
1024 case 'trash':
1025 foreach ( $entry_ids as $entry_id ) {
1026 if ( EVF_Admin_Entries::update_status( $entry_id, 'trash' ) ) {
1027 ++$count;
1028 }
1029 }
1030
1031 add_settings_error(
1032 'bulk_action',
1033 'bulk_action',
1034 /* translators: %d: number of entries */
1035 sprintf( _n( '%d entry moved to the Trash.', '%d entries moved to the Trash.', $count, 'everest-forms' ), $count ),
1036 'updated'
1037 );
1038 break;
1039 case 'untrash':
1040 foreach ( $entry_ids as $entry_id ) {
1041 if ( EVF_Admin_Entries::update_status( $entry_id, 'publish' ) ) {
1042 ++$count;
1043 }
1044 }
1045
1046 add_settings_error(
1047 'bulk_action',
1048 'bulk_action',
1049 /* translators: %d: number of entries */
1050 sprintf( _n( '%d entry restored from the Trash.', '%d entries restored from the Trash.', $count, 'everest-forms' ), $count ),
1051 'updated'
1052 );
1053 break;
1054 case 'delete':
1055 foreach ( $entry_ids as $entry_id ) {
1056 if ( EVF_Admin_Entries::remove_entry( $entry_id, $form_id ) ) {
1057 ++$count;
1058 }
1059 }
1060
1061 add_settings_error(
1062 'bulk_action',
1063 'bulk_action',
1064 /* translators: %d: number of entries */
1065 sprintf( _n( '%d entry permanently deleted.', '%d entries permanently deleted.', $count, 'everest-forms' ), $count ),
1066 'updated'
1067 );
1068 break;
1069 case 'spam':
1070 foreach ( $entry_ids as $entry_id ) {
1071 if ( EVF_Admin_Entries::update_status( $entry_id, 'spam' ) ) {
1072 ++$count;
1073 }
1074 }
1075
1076 add_settings_error(
1077 'bulk_action',
1078 'bulk_action',
1079 /* translators: %d: number of entries */
1080 sprintf( _n( '%d entry sent to spam.', '%d entries sent to Spam.', $count, 'everest-forms' ), $count ),
1081 'updated'
1082 );
1083 break;
1084 case 'unspam':
1085 foreach ( $entry_ids as $entry_id ) {
1086 if ( EVF_Admin_Entries::update_status( $entry_id, $doaction ) ) {
1087 ++$count;
1088 }
1089 }
1090
1091 add_settings_error(
1092 'bulk_action',
1093 'bulk_action',
1094 /* translators: %d: number of entries */
1095 sprintf( _n( '%d removed from spam.', '%d entries removed from spam.', $count, 'everest-forms' ), $count ),
1096 'updated'
1097 );
1098 break;
1099 }
1100 $sendback = remove_query_arg( array( 'action', 'action2' ), $sendback );
1101
1102 wp_safe_redirect( $sendback );
1103 exit();
1104 } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) && isset( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1105 wp_safe_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
1106 exit();
1107 }
1108 }
1109
1110 /**
1111 * Extra controls to be displayed between bulk actions and pagination.
1112 *
1113 * @param string $which The location of the extra table nav markup.
1114 */
1115 protected function extra_tablenav( $which ) {
1116 global $entries_table_list, $wpdb;
1117 $num_entries = ( 0 === $this->form_id ) ? $this->get_all_forms_entry_counts() : evf_get_count_entries_by_status( $this->form_id );
1118 $show_export = isset( $_GET['status'] ) && 'trash' === $_GET['status'] ? false : true; // phpcs:ignore WordPress.Security.NonceVerification
1119 ?>
1120 <div class="everest-forms-extra-table-nav">
1121 <?php
1122 if ( ! empty( $this->forms ) && 'top' === $which ) {
1123 if ( defined( 'EFP_VERSION' ) && $this->form_id > 0 ) {
1124 ?>
1125 <button
1126 type="button"
1127 class="button evf-manage-columns-btn everest-forms-entries-setting"
1128 id="evf-manage-columns"
1129 data-evf-form_id="<?php echo esc_attr( $this->form_id ); ?>"
1130 >
1131 <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;">
1132 <path d="M2 4.66667H14M2 8H14M2 11.3333H14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
1133 </svg>
1134 <?php esc_html_e( 'Manage Columns', 'everest-forms' ); ?>
1135 </button>
1136 <?php
1137 }
1138
1139 $this->status_dropdown( $num_entries );
1140
1141 // Export CSV submit button.
1142 if ( apply_filters( 'everest_forms_enable_csv_export', $show_export ) && current_user_can( 'export' ) && $this->form_id > 0 ) {
1143 ?>
1144 <button type="submit" name="export_action" value="1" class="button" id="export-csv-submit">
1145 <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;">
1146 <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"/>
1147 </svg>
1148 <?php esc_html_e( 'Export CSV', 'everest-forms' ); ?>
1149 </button>
1150 <?php
1151 }
1152
1153 if ( $num_entries['trash'] && isset( $_GET['status'] ) && 'trash' === $_GET['status'] && current_user_can( 'manage_everest_forms' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1154 submit_button( __( 'Empty Trash', 'everest-forms' ), 'apply', 'delete_all', false );
1155 }
1156 }
1157 ?>
1158 </div>
1159 <?php
1160 do_action( 'everest_forms_entries_table_extra_filters', $this->form_id, $which );
1161 }
1162
1163 /**
1164 * Display a form dropdown for filtering entries.
1165 */
1166 public function forms_dropdown() {
1167 $forms = evf_get_all_forms( true );
1168 $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : $this->form_id; // phpcs:ignore WordPress.Security.NonceVerification
1169 ?>
1170 <label for="filter-by-form" class="screen-reader-text"><?php esc_html_e( 'Filter by form', 'everest-forms' ); ?></label>
1171 <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' ); ?>">
1172 <option value="0" <?php selected( $form_id, 0 ); ?>><?php esc_html_e( 'All Forms', 'everest-forms' ); ?></option>
1173 <?php foreach ( $forms as $id => $form ) : ?>
1174 <option value="<?php echo esc_attr( $id ); ?>" <?php selected( $form_id, $id ); ?>><?php echo esc_html( $form ); ?></option>
1175 <?php endforeach; ?>
1176 </select>
1177 <?php
1178 }
1179
1180 /**
1181 * Display a status dropdown for filtering entries.
1182 */
1183 public function status_dropdown( $num_entries ) {
1184 $current_status = isset( $_REQUEST['status'] ) ? sanitize_key( wp_unslash( $_REQUEST['status'] ) ) : '';
1185
1186 $statuses = array(
1187 'all' => __( 'All', 'everest-forms' ),
1188 'unread' => __( 'Unread', 'everest-forms' ),
1189 'read' => __( 'Read', 'everest-forms' ),
1190 'spam' => __( 'Spam', 'everest-forms' ),
1191 'trash' => __( 'Trash', 'everest-forms' ),
1192 );
1193
1194 if ( ! empty( $this->form_data ) ) {
1195 $extra_statuses = evf_get_entry_statuses( $this->form_data );
1196 foreach ( $extra_statuses as $key => $label ) {
1197 if ( ! isset( $statuses[ $key ] ) && 'publish' !== $key ) {
1198 $statuses[ $key ] = $label;
1199 }
1200 }
1201 }
1202
1203 // Map status keys to count keys.
1204 $count_map = array(
1205 'all' => 'publish',
1206 'unread' => 'unread',
1207 'read' => 'read',
1208 'spam' => 'spam',
1209 'trash' => 'trash',
1210 );
1211 ?>
1212 <select name="status" id="filter-by-status" class="evf-enhanced-normal-select evf-auto-filter">
1213 <?php
1214 foreach ( $statuses as $key => $label ) :
1215 $count_key = isset( $count_map[ $key ] ) ? $count_map[ $key ] : $key;
1216 $count = isset( $num_entries[ $count_key ] ) ? (int) $num_entries[ $count_key ] : 0;
1217 $display = sprintf( '%s (%d)', $label, $count );
1218 ?>
1219 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $current_status, $key ); ?>>
1220 <?php echo esc_html( $display ); ?>
1221 </option>
1222 <?php endforeach; ?>
1223 </select>
1224 <?php
1225 }
1226
1227
1228 /**
1229 * Prepare table list items.
1230 */
1231 public function prepare_items() {
1232 $per_page = $this->get_items_per_page( 'evf_entries_per_page' );
1233 $current_page = $this->get_pagenum();
1234
1235 // Query args.
1236 $args = array(
1237 'status' => 'publish',
1238 'form_id' => $this->form_id,
1239 'limit' => $per_page,
1240 'offset' => $per_page * ( $current_page - 1 ),
1241 );
1242
1243 // Handle the status query.
1244 if ( ! empty( $_REQUEST['status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1245 $status = sanitize_key( wp_unslash( $_REQUEST['status'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1246
1247 if ( 'unread' === $status ) {
1248 $args['status'] = 'publish';
1249 $args['viewed'] = 0;
1250 } elseif ( 'read' === $status ) {
1251 $args['status'] = 'publish';
1252 $args['viewed'] = 1;
1253 } elseif ( 'all' === $status ) {
1254 $args['status'] = 'publish';
1255 } else {
1256 $args['status'] = $status;
1257 }
1258 }
1259
1260 // Handle the search query.
1261 if ( ! empty( $_REQUEST['s'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1262 $args['search'] = sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1263 }
1264
1265 if ( ! empty( $_REQUEST['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1266 $args['orderby'] = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1267 }
1268
1269 if ( ! empty( $_REQUEST['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1270 $args['order'] = sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1271 }
1272
1273 // Get the entries.
1274 $entries = evf_search_entries( $args );
1275 $this->items = array_map( 'evf_get_entry', $entries );
1276
1277 // Get total items.
1278 $args['limit'] = -1;
1279 $args['offset'] = 0;
1280 $total_items = count( evf_search_entries( $args ) );
1281
1282 // Set the pagination.
1283 $this->set_pagination_args(
1284 array(
1285 'total_items' => $total_items,
1286 'per_page' => $per_page,
1287 'total_pages' => ceil( $total_items / $per_page ),
1288 )
1289 );
1290 }
1291 }
1292