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.php
everest-forms / includes / admin Last commit date
builder 1 week ago form-migrator 1 month 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 1 month 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 1 month 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 1 month 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 1 month 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 1 month ago
class-evf-admin-entries.php
656 lines
1 <?php
2 /**
3 * EverestForms Admin Entries Class - All Forms Support
4 *
5 * @package EverestForms\Admin
6 * @since 1.1.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Admin_Entries class.
13 */
14 class EVF_Admin_Entries {
15
16 /**
17 * Initialize the entries admin actions.
18 */
19 public function __construct() {
20 add_action( 'admin_init', array( $this, 'actions' ) );
21 add_filter( 'heartbeat_received', array( $this, 'check_new_entries' ), 10, 3 );
22 add_action( 'everest_forms_after_delete_entries', array( $this, 'evf_delete_booked_slot' ), 10, 2 );
23 }
24
25 /**
26 * Check if is entries page.
27 *
28 * @return bool
29 */
30 private function is_entries_page() {
31 return isset( $_GET['page'] ) && 'evf-entries' === $_GET['page']; // phpcs:ignore WordPress.Security.NonceVerification
32 }
33
34 /**
35 * Page output.
36 */
37 public static function page_output() {
38 if ( apply_filters( 'everest_forms_entries_list_actions', false ) ) {
39 do_action( 'everest_forms_entries_list_actions_execute' );
40 } elseif ( isset( $_GET['view-entry'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
41 include 'views/html-admin-page-entries-view.php';
42 } else {
43 self::table_list_output();
44 }
45 }
46
47 /**
48 * Table list output.
49 */
50 private static function table_list_output() {
51 global $entries_table_list, $wpdb;
52
53 $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
54 $current_status = isset( $_REQUEST['status'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) : 'publish'; // phpcs:ignore WordPress.Security.NonceVerification
55
56 if ( $form_id > 0 ) {
57
58 $has_publish = $wpdb->get_var(
59 $wpdb->prepare(
60 "SELECT 1 FROM {$wpdb->prefix}evf_entries
61 WHERE form_id = %d AND status = 'publish'
62 LIMIT 1",
63 $form_id
64 )
65 );
66
67 if ( $has_publish ) {
68 $current_status = 'publish';
69 } else {
70
71 $has_trash = $wpdb->get_var(
72 $wpdb->prepare(
73 "SELECT 1 FROM {$wpdb->prefix}evf_entries
74 WHERE form_id = %d AND status = 'trash'
75 LIMIT 1",
76 $form_id
77 )
78 );
79
80 $current_status = $has_trash ? 'trash' : '';
81 }
82 } else {
83
84 $has_publish = $wpdb->get_var(
85 "SELECT 1 FROM {$wpdb->prefix}evf_entries
86 WHERE status = 'publish'
87 LIMIT 1"
88 );
89
90 if ( $has_publish ) {
91 $current_status = 'publish';
92 } else {
93
94 $has_trash = $wpdb->get_var(
95 "SELECT 1 FROM {$wpdb->prefix}evf_entries
96 WHERE status = 'trash'
97 LIMIT 1"
98 );
99
100 $current_status = $has_trash ? 'trash' : '';
101 }
102 }
103
104 $current_status = $current_status ? $current_status : 'publish';
105
106 $entries_table_list->process_bulk_action();
107 $entries_table_list->prepare_items();
108
109 $use_react_header = apply_filters( 'everest_forms_use_react_header', true, 'entries' );
110 if ( $use_react_header ) {
111 ?>
112 <div id="evf-react-header-root" data-active-menu="entries"></div>
113 <?php
114 }
115 ?>
116
117 <div id="everest-forms-entries-list" class="wrap">
118 <?php settings_errors(); ?>
119
120 <?php $entry_ids = evf_get_entries_ids( $entries_table_list->form_id ); ?>
121 <form
122 id="entries-list"
123 method="get"
124 data-form-id="<?php echo absint( $entries_table_list->form_id ); ?>"
125 data-last-entry-id="<?php echo ! empty( $entry_ids ) ? absint( end( $entry_ids ) ) : 0; ?>"
126 >
127 <input type="hidden" name="page" value="evf-entries" />
128
129 <?php if ( ! empty( $_REQUEST['form_id'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification ?>
130 <input type="hidden" name="form_id" value="<?php echo absint( $_REQUEST['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification ?>" />
131 <?php endif; ?>
132
133 <?php if ( ! empty( $_REQUEST['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification ?>
134 <input type="hidden" name="status" value="<?php echo esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification ?>" />
135 <?php endif; ?>
136
137 <div class="everest-forms-base-list-table-heading">
138 <div class="evf-entries-tab-header" style="flex: 1; border-bottom: none; padding-bottom: 0; margin-bottom: 0;">
139 <div class="evf-entries-tab-header-title">
140 <span class="evf-entries-tab-header-title__text">
141 <?php esc_html_e( 'Entries', 'everest-forms' ); ?>
142 </span>
143 </div>
144 <div class="evf-entries-form-selector">
145 <label for="filter-by-form" class="screen-reader-text"><?php esc_html_e( 'Filter by form', 'everest-forms' ); ?></label>
146 <select
147 name="form_id"
148 id="filter-by-form"
149 class="evf-enhanced-normal-select evf-auto-filter"
150 data-placeholder="<?php esc_attr_e( 'Search form...', 'everest-forms' ); ?>"
151 >
152 <option value="0" <?php selected( $form_id, 0 ); ?>><?php esc_html_e( 'All Forms', 'everest-forms' ); ?></option>
153 <?php
154 $forms = evf_get_all_forms( true );
155 foreach ( $forms as $id => $form ) :
156 ?>
157 <option value="<?php echo esc_attr( $id ); ?>" <?php selected( $form_id, $id ); ?>><?php echo esc_html( $form ); ?></option>
158 <?php endforeach; ?>
159 </select>
160 </div>
161 <div class="evf-entries-header-actions">
162 <?php
163 do_action( 'everest_forms_entries_header_buttons', $form_id );
164 $analytics_url = $form_id > 0
165 ? admin_url( 'admin.php?page=evf-analytics&unit=day&scope=all&form_id=' . $form_id )
166 : admin_url( 'admin.php?page=evf-analytics&unit=day&scope=all' );
167 ?>
168 <a href="<?php echo esc_url( $analytics_url ); ?>" class="button evf-btn-view-analytics">
169 <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align: middle; margin-right: 4px;">
170 <line x1="18" y1="20" x2="18" y2="10"/>
171 <line x1="12" y1="20" x2="12" y2="4"/>
172 <line x1="6" y1="20" x2="6" y2="14"/>
173 </svg>
174 <?php esc_html_e( 'View Analytics', 'everest-forms' ); ?>
175 </a>
176 </div>
177 </div>
178
179 <div class="search-box" style="flex: 0 0 auto; margin: 0; right: 0;">
180 <?php $entries_table_list->search_box( esc_html__( 'Search Entries', 'everest-forms' ), 'everest-forms' ); ?>
181 </div>
182 </div>
183
184 <?php $entries_table_list->views(); ?>
185 <?php $entries_table_list->display(); ?>
186
187 </form>
188 </div>
189 <?php
190 }
191
192 /**
193 * Entries admin actions.
194 */
195 public function actions() {
196 if ( $this->is_entries_page() ) {
197
198 // Trash entry.
199 if ( isset( $_GET['trash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
200 $this->trash_entry();
201 }
202
203 // Untrash entry.
204 if ( isset( $_GET['untrash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
205 $this->untrash_entry();
206 }
207
208 // Delete entry.
209 if ( isset( $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
210 $this->delete_entry();
211 }
212
213 // Export CSV.
214 if ( isset( $_REQUEST['export_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
215 $this->export_csv();
216 }
217
218 // Empty Trash.
219 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
220 $this->empty_trash();
221 }
222 }
223 }
224
225 /**
226 * Trash entry.
227 */
228 private function trash_entry() {
229 check_admin_referer( 'trash-entry' );
230
231 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
232
233 if ( isset( $_GET['trash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
234 $entry_id = absint( $_GET['trash'] ); // phpcs:ignore WordPress.Security.NonceVerification
235
236 if ( $entry_id ) {
237 if ( ! current_user_can( 'everest_forms_delete_entry', $entry_id ) ) {
238 wp_die( esc_html__( 'You do not have permission to trash this entry.', 'everest-forms' ), 403 );
239 }
240 self::update_status( $entry_id, 'trash' );
241 }
242 }
243 wp_safe_redirect(
244 esc_url_raw(
245 add_query_arg(
246 array(
247 'form_id' => $form_id,
248 'trashed' => 1,
249 ),
250 admin_url( 'admin.php?page=evf-entries' )
251 )
252 )
253 );
254 exit();
255 }
256
257 /**
258 * Untrash entry.
259 */
260 private function untrash_entry() {
261 check_admin_referer( 'untrash-entry' );
262
263 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
264
265 if ( isset( $_GET['untrash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
266 $entry_id = absint( $_GET['untrash'] ); // phpcs:ignore WordPress.Security.NonceVerification
267
268 if ( $entry_id ) {
269 if ( ! current_user_can( 'everest_forms_edit_entry', $entry_id ) ) {
270 wp_die( esc_html__( 'You do not have permission to restore this entry.', 'everest-forms' ), 403 );
271 }
272 self::update_status( $entry_id, 'publish' );
273 }
274 }
275
276 wp_safe_redirect(
277 esc_url_raw(
278 add_query_arg(
279 array(
280 'form_id' => $form_id,
281 'untrashed' => 1,
282 ),
283 admin_url( 'admin.php?page=evf-entries' )
284 )
285 )
286 );
287 exit();
288 }
289
290 /**
291 * Delete entry.
292 */
293 private function delete_entry() {
294 check_admin_referer( 'delete-entry' );
295
296 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
297
298 if ( isset( $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
299 $entry_id = absint( $_GET['delete'] ); // phpcs:ignore WordPress.Security.NonceVerification
300
301 if ( $entry_id ) {
302 if ( ! current_user_can( 'everest_forms_delete_entry', $entry_id ) ) {
303 wp_die( esc_html__( 'You do not have permission to delete this entry.', 'everest-forms' ), 403 );
304 }
305 self::remove_entry( $entry_id, $form_id );
306 }
307 }
308
309 wp_safe_redirect(
310 esc_url_raw(
311 add_query_arg(
312 array(
313 'form_id' => $form_id,
314 'deleted' => 1,
315 ),
316 admin_url( 'admin.php?page=evf-entries' )
317 )
318 )
319 );
320 exit();
321 }
322
323 /**
324 * Empty Trash.
325 */
326 public function empty_trash() {
327 global $wpdb;
328
329 check_admin_referer( 'bulk-entries' );
330
331 if ( isset( $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
332 $form_id = absint( $_GET['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification
333
334 if ( $form_id ) {
335 $count = 0;
336 $results = $wpdb->get_results( $wpdb->prepare( "SELECT entry_id FROM {$wpdb->prefix}evf_entries WHERE `status` = 'trash' AND form_id = %d", $form_id ) ); // WPCS: cache ok, DB call ok.
337 $entry_ids = array_map( 'intval', wp_list_pluck( $results, 'entry_id' ) );
338
339 foreach ( $entry_ids as $entry_id ) {
340 if ( self::remove_entry( $entry_id, $form_id ) ) {
341 ++$count;
342 }
343 }
344
345 add_settings_error(
346 'empty_trash',
347 'empty_trash',
348 /* translators: %d: number of entries */
349 sprintf( _n( '%d entry permanently deleted.', '%d entries permanently deleted.', $count, 'everest-forms' ), $count ),
350 'updated'
351 );
352 }
353 }
354 }
355
356 /**
357 * Do the entries export.
358 *
359 * @since 1.3.0
360 */
361 public function export_csv() {
362 check_admin_referer( 'bulk-entries' );
363
364 if ( isset( $_REQUEST['form_id'] ) && current_user_can( 'export' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
365 include_once EVF_ABSPATH . 'includes/export/class-evf-entry-csv-exporter.php';
366 $form_id = absint( $_REQUEST['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification
367 $form_name = strtolower( get_the_title( $form_id ) );
368
369 if ( $form_name ) {
370 $exporter = new EVF_Entry_CSV_Exporter( $form_id );
371 $exporter->set_filename( evf_get_entry_export_file_name( $form_name ) );
372 }
373
374 $exporter->export();
375 }
376 }
377
378 /**
379 * Remove entry.
380 *
381 * @param int $entry_id Entry ID.
382 * @param int $form_id Form ID.
383 * @return bool
384 */
385 public static function remove_entry( $entry_id, $form_id = 0 ) {
386 global $wpdb;
387
388 do_action( 'everest_forms_before_delete_entries', $entry_id );
389
390 $delete = $wpdb->delete( $wpdb->prefix . 'evf_entries', array( 'entry_id' => $entry_id ), array( '%d' ) );
391
392 if ( apply_filters( 'everest_forms_delete_entrymeta', true ) ) {
393 $wpdb->delete( $wpdb->prefix . 'evf_entrymeta', array( 'entry_id' => $entry_id ), array( '%d' ) );
394 }
395
396 do_action( 'everest_forms_after_delete_entries', $form_id, $entry_id );
397
398 return $delete;
399 }
400
401 /**
402 * Set entry status.
403 *
404 * @param int $entry_id Entry ID.
405 * @param string $status Entry status.
406 */
407 public static function update_status( $entry_id, $status = 'publish' ) {
408 global $wpdb;
409
410 $update = false;
411 $is_bulk_action = isset( $_GET['bulk_action'] ) && 'Apply' == $_GET['bulk_action'] ? true : false; // phpcs:ignore WordPress.Security.NonceVerification
412 if ( in_array( $status, array( 'star', 'unstar' ), true ) ) {
413 $update = $wpdb->update(
414 $wpdb->prefix . 'evf_entries',
415 array(
416 'starred' => 'star' === $status ? 1 : 0,
417 ),
418 array( 'entry_id' => $entry_id ),
419 array( '%d' ),
420 array( '%d' )
421 );
422 } elseif ( in_array( $status, array( 'read', 'unread' ), true ) ) {
423 $update = $wpdb->update(
424 $wpdb->prefix . 'evf_entries',
425 array(
426 'viewed' => 'read' === $status ? 1 : 0,
427 ),
428 array( 'entry_id' => $entry_id ),
429 array( '%d' ),
430 array( '%d' )
431 );
432 } elseif ( 'approved' === $status ) {
433 $update = $wpdb->update(
434 $wpdb->prefix . 'evf_entries',
435 array(
436 'status' => 'publish',
437 ),
438 array( 'entry_id' => $entry_id ),
439 array( '%s' ),
440 array( '%d' )
441 );
442
443 $entry = evf_get_entry( $entry_id );
444 $entry_meta = $entry->meta;
445 $entry_date = $entry->date_created;
446 $first_name = '';
447 $last_name = '';
448 $email = '';
449 $site_name = get_option( 'blogname', '' );
450 $subject = '';
451 $message = '';
452 $name = '';
453
454 foreach ( $entry_meta as $key => $value ) {
455 if ( preg_match( '/^first_name_/', $key ) ) {
456 $first_name = $value;
457 }
458
459 if ( preg_match( '/^last_name_/', $key ) ) {
460 $last_name = $value;
461 }
462
463 if ( preg_match( '/^email/', $key ) ) {
464 $email = $value;
465 }
466
467 if ( '' === $name ) {
468 if ( ! empty( $first_name ) && ! empty( $last_name ) ) {
469 $name = $first_name . ' ' . $last_name;
470 } elseif ( ! empty( $first_name ) ) {
471 $name = $first_name;
472 } else {
473 $name = $last_name;
474 }
475 }
476
477 $subject = apply_filters( 'everest_forms_entry_submission_approval_subject', esc_html__( 'Form Entry Approved', 'everest-forms' ) );
478 /* translators:%s: User name of form entry */
479 $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>';
480 /* translators:%s: Form Entry Date */
481 $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/>';
482 $message .= '<br/>' . __( 'Thank you for giving us your precious time.', 'everest-forms' ) . '<br/>';
483 /* translators:%s: Site Name*/
484 $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name );
485 $message = apply_filters( 'everest_forms_entry_approval_message', $message, $name, $entry_date, $site_name );
486 }
487
488 if ( ! $is_bulk_action ) {
489 $email_obj = new EVF_Emails();
490 $email_obj->send( $email, $subject, $message );
491 }
492 } elseif ( 'denied' === $status ) {
493 $update = $wpdb->update(
494 $wpdb->prefix . 'evf_entries',
495 array(
496 'status' => $status,
497 ),
498 array( 'entry_id' => $entry_id ),
499 array( '%s' ),
500 array( '%d' )
501 );
502
503 $entry = evf_get_entry( $entry_id );
504 $entry_meta = $entry->meta;
505 $entry_date = $entry->date_created;
506 $first_name = '';
507 $last_name = '';
508 $email = '';
509 $site_name = get_option( 'blogname', '' );
510 $name = '';
511
512 foreach ( $entry_meta as $key => $value ) {
513 if ( preg_match( '/^first_name/', $key ) ) {
514 $first_name = $value;
515 }
516
517 if ( preg_match( '/^last_name/', $key ) ) {
518 $last_name = $value;
519 }
520
521 if ( preg_match( '/^email/', $key ) ) {
522 $email = $value;
523 }
524
525 if ( '' === $name ) {
526 if ( ! empty( $first_name ) && ! empty( $last_name ) ) {
527 $name = $first_name . ' ' . $last_name;
528 } elseif ( ! empty( $first_name ) ) {
529 $name = $first_name;
530 } else {
531 $name = $last_name;
532 }
533 }
534
535 $subject = apply_filters( 'everest_forms_entry_submission_denial_subject', esc_html__( 'Entry Submission Denied', 'everest-forms' ) );
536 /* translators:%s: User name of form entry */
537 $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>';
538 /* translators:%s: Form Entry Date */
539 $message .= '<br/>' . sprintf( __( 'We regret to inform you that your form entry submitted on %s has been denied.', 'everest-forms' ), $entry_date ) . '<br/>';
540 $message .= '<br/>' . __( 'Thank you for giving us your precious time.', 'everest-forms' ) . '<br/>';
541 /* translator: %s: Site Name */
542 $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name );
543 $message = apply_filters( 'everest_forms_entry_denial_message', $message, $name, $entry_date, $site_name );
544 }
545
546 if ( ! $is_bulk_action ) {
547 $email_obj = new EVF_Emails();
548 $email_obj->send( $email, $subject, $message );
549 }
550 } elseif ( 'unspam' === $status ) {
551 $update = $wpdb->update(
552 $wpdb->prefix . 'evf_entries',
553 array(
554 'status' => 'publish',
555 ),
556 array( 'entry_id' => $entry_id ),
557 array( '%s' ),
558 array( '%d' )
559 );
560 } else {
561 $entry = evf_get_entry( $entry_id );
562
563 // Preserve entry status.
564 if ( 'trash' === $status ) {
565 $wpdb->insert(
566 $wpdb->prefix . 'evf_entrymeta',
567 array(
568 'entry_id' => $entry_id,
569 'meta_key' => '_evf_trash_entry_status',
570 'meta_value' => sanitize_text_field( $entry->status ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
571 )
572 );
573 } elseif ( 'publish' === $status ) {
574 $status = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->prefix}evf_entrymeta WHERE entry_id = %d AND meta_key = '_evf_trash_entry_status'", $entry_id ) );
575 $wpdb->delete(
576 $wpdb->prefix . 'evf_entrymeta',
577 array(
578 'entry_id' => $entry_id,
579 'meta_key' => '_evf_trash_entry_status',
580 )
581 );
582 }
583
584 $update = $wpdb->update(
585 $wpdb->prefix . 'evf_entries',
586 array( 'status' => $status ),
587 array( 'entry_id' => $entry_id ),
588 array( '%s' ),
589 array( '%d' )
590 );
591 }
592
593 if ( false !== $update && $update > 0 ) {
594 do_action( 'everest_forms_entry_status_updated', $entry_id, $status );
595 }
596
597 return $update;
598 }
599
600 /**
601 * Check new entries with heartbeat API.
602 *
603 * @since 1.5.0
604 *
605 * @param array $response The Heartbeat response.
606 * @param array $data The $_POST data sent.
607 * @param string $screen_id The screen id.
608 * @return array The Heartbeat response.
609 */
610 public function check_new_entries( $response, $data, $screen_id ) {
611 if ( 'everest-forms_page_evf-entries' === $screen_id ) {
612 $form_id = ! empty( $data['evf_new_entries_form_id'] ) ? absint( $data['evf_new_entries_form_id'] ) : 0;
613 $last_entry_id = ! empty( $data['evf_new_entries_last_entry_id'] ) ? absint( $data['evf_new_entries_last_entry_id'] ) : 0;
614
615 // Count new entries.
616 $entries_count = evf_get_count_entries_by_last_entry( $form_id, $last_entry_id );
617
618 if ( ! empty( $entries_count ) ) {
619 /* translators: %d - New form entries count. */
620 $response['evf_new_entries_notification'] = esc_html( sprintf( _n( '%d new entry since you last checked.', '%d new entries since you last checked.', $entries_count, 'everest-forms' ), $entries_count ) );
621 }
622 }
623
624 return $response;
625 }
626
627 /**
628 * Delete booked slot after deleting the entries.
629 *
630 * @param int $form_id Form ID.
631 * @param int $entry_id Entry ID.
632 */
633 public function evf_delete_booked_slot( $form_id, $entry_id ) {
634 $form_data = get_post( $form_id );
635 $form_content = json_decode( $form_data->post_content, true );
636 $form_fields = $form_content['form_fields'];
637 foreach ( $form_fields as $field_name => $field ) {
638 if ( 'date-time' === $field['type'] && isset( $field['slot_booking_advanced'] ) && evf_string_to_bool( $field['slot_booking_advanced'] ) ) {
639 $booked_slot = evf_maybe_unserialize( get_option( 'evf_booked_slot', '' ) );
640 if ( ! empty( $booked_slot ) && array_key_exists( $form_id, $booked_slot ) ) {
641 $form_booked_slot = $booked_slot[ $form_id ];
642 if ( array_key_exists( $entry_id, $form_booked_slot ) ) {
643 unset( $form_booked_slot[ $entry_id ] );
644 $booked_slot[ $form_id ] = $form_booked_slot;
645
646 $booked_slot = maybe_serialize( $booked_slot );
647 update_option( 'evf_booked_slot', $booked_slot );
648 }
649 }
650 }
651 }
652 }
653 }
654
655 new EVF_Admin_Entries();
656