builder
3 weeks ago
form-migrator
3 weeks ago
plugin-updates
8 years ago
settings
3 weeks ago
views
3 weeks ago
class-evf-admin-addons.php
4 months ago
class-evf-admin-assets.php
4 days ago
class-evf-admin-builder.php
2 months ago
class-evf-admin-dashboard.php
3 weeks 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
2 months ago
class-evf-admin-entries.php
2 months ago
class-evf-admin-form-templates.php
3 weeks ago
class-evf-admin-forms-table-list.php
4 months ago
class-evf-admin-forms.php
4 months ago
class-evf-admin-import-export.php
3 weeks ago
class-evf-admin-menus.php
3 weeks ago
class-evf-admin-notices.php
4 months ago
class-evf-admin-preview-confirmation.php
11 months ago
class-evf-admin-settings.php
3 weeks ago
class-evf-admin-tools.php
2 months ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 months ago
class-evf-base-list-table.php
4 months ago
evf-admin-functions.php
3 weeks ago
class-evf-admin-entries.php
647 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 | self::update_status( $entry_id, 'trash' ); |
| 238 | } |
| 239 | } |
| 240 | wp_safe_redirect( |
| 241 | esc_url_raw( |
| 242 | add_query_arg( |
| 243 | array( |
| 244 | 'form_id' => $form_id, |
| 245 | 'trashed' => 1, |
| 246 | ), |
| 247 | admin_url( 'admin.php?page=evf-entries' ) |
| 248 | ) |
| 249 | ) |
| 250 | ); |
| 251 | exit(); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Untrash entry. |
| 256 | */ |
| 257 | private function untrash_entry() { |
| 258 | check_admin_referer( 'untrash-entry' ); |
| 259 | |
| 260 | $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : ''; |
| 261 | |
| 262 | if ( isset( $_GET['untrash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 263 | $entry_id = absint( $_GET['untrash'] ); // phpcs:ignore WordPress.Security.NonceVerification |
| 264 | |
| 265 | if ( $entry_id ) { |
| 266 | self::update_status( $entry_id, 'publish' ); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | wp_safe_redirect( |
| 271 | esc_url_raw( |
| 272 | add_query_arg( |
| 273 | array( |
| 274 | 'form_id' => $form_id, |
| 275 | 'untrashed' => 1, |
| 276 | ), |
| 277 | admin_url( 'admin.php?page=evf-entries' ) |
| 278 | ) |
| 279 | ) |
| 280 | ); |
| 281 | exit(); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Delete entry. |
| 286 | */ |
| 287 | private function delete_entry() { |
| 288 | check_admin_referer( 'delete-entry' ); |
| 289 | |
| 290 | $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : ''; |
| 291 | |
| 292 | if ( isset( $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 293 | $entry_id = absint( $_GET['delete'] ); // phpcs:ignore WordPress.Security.NonceVerification |
| 294 | |
| 295 | if ( $entry_id ) { |
| 296 | self::remove_entry( $entry_id, $form_id ); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | wp_safe_redirect( |
| 301 | esc_url_raw( |
| 302 | add_query_arg( |
| 303 | array( |
| 304 | 'form_id' => $form_id, |
| 305 | 'deleted' => 1, |
| 306 | ), |
| 307 | admin_url( 'admin.php?page=evf-entries' ) |
| 308 | ) |
| 309 | ) |
| 310 | ); |
| 311 | exit(); |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Empty Trash. |
| 316 | */ |
| 317 | public function empty_trash() { |
| 318 | global $wpdb; |
| 319 | |
| 320 | check_admin_referer( 'bulk-entries' ); |
| 321 | |
| 322 | if ( isset( $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 323 | $form_id = absint( $_GET['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification |
| 324 | |
| 325 | if ( $form_id ) { |
| 326 | $count = 0; |
| 327 | $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. |
| 328 | $entry_ids = array_map( 'intval', wp_list_pluck( $results, 'entry_id' ) ); |
| 329 | |
| 330 | foreach ( $entry_ids as $entry_id ) { |
| 331 | if ( self::remove_entry( $entry_id, $form_id ) ) { |
| 332 | ++$count; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | add_settings_error( |
| 337 | 'empty_trash', |
| 338 | 'empty_trash', |
| 339 | /* translators: %d: number of entries */ |
| 340 | sprintf( _n( '%d entry permanently deleted.', '%d entries permanently deleted.', $count, 'everest-forms' ), $count ), |
| 341 | 'updated' |
| 342 | ); |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Do the entries export. |
| 349 | * |
| 350 | * @since 1.3.0 |
| 351 | */ |
| 352 | public function export_csv() { |
| 353 | check_admin_referer( 'bulk-entries' ); |
| 354 | |
| 355 | if ( isset( $_REQUEST['form_id'] ) && current_user_can( 'export' ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 356 | include_once EVF_ABSPATH . 'includes/export/class-evf-entry-csv-exporter.php'; |
| 357 | $form_id = absint( $_REQUEST['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification |
| 358 | $form_name = strtolower( get_the_title( $form_id ) ); |
| 359 | |
| 360 | if ( $form_name ) { |
| 361 | $exporter = new EVF_Entry_CSV_Exporter( $form_id ); |
| 362 | $exporter->set_filename( evf_get_entry_export_file_name( $form_name ) ); |
| 363 | } |
| 364 | |
| 365 | $exporter->export(); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Remove entry. |
| 371 | * |
| 372 | * @param int $entry_id Entry ID. |
| 373 | * @param int $form_id Form ID. |
| 374 | * @return bool |
| 375 | */ |
| 376 | public static function remove_entry( $entry_id, $form_id = 0 ) { |
| 377 | global $wpdb; |
| 378 | |
| 379 | do_action( 'everest_forms_before_delete_entries', $entry_id ); |
| 380 | |
| 381 | $delete = $wpdb->delete( $wpdb->prefix . 'evf_entries', array( 'entry_id' => $entry_id ), array( '%d' ) ); |
| 382 | |
| 383 | if ( apply_filters( 'everest_forms_delete_entrymeta', true ) ) { |
| 384 | $wpdb->delete( $wpdb->prefix . 'evf_entrymeta', array( 'entry_id' => $entry_id ), array( '%d' ) ); |
| 385 | } |
| 386 | |
| 387 | do_action( 'everest_forms_after_delete_entries', $form_id, $entry_id ); |
| 388 | |
| 389 | return $delete; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Set entry status. |
| 394 | * |
| 395 | * @param int $entry_id Entry ID. |
| 396 | * @param string $status Entry status. |
| 397 | */ |
| 398 | public static function update_status( $entry_id, $status = 'publish' ) { |
| 399 | global $wpdb; |
| 400 | |
| 401 | $update = false; |
| 402 | $is_bulk_action = isset( $_GET['bulk_action'] ) && 'Apply' == $_GET['bulk_action'] ? true : false; // phpcs:ignore WordPress.Security.NonceVerification |
| 403 | if ( in_array( $status, array( 'star', 'unstar' ), true ) ) { |
| 404 | $update = $wpdb->update( |
| 405 | $wpdb->prefix . 'evf_entries', |
| 406 | array( |
| 407 | 'starred' => 'star' === $status ? 1 : 0, |
| 408 | ), |
| 409 | array( 'entry_id' => $entry_id ), |
| 410 | array( '%d' ), |
| 411 | array( '%d' ) |
| 412 | ); |
| 413 | } elseif ( in_array( $status, array( 'read', 'unread' ), true ) ) { |
| 414 | $update = $wpdb->update( |
| 415 | $wpdb->prefix . 'evf_entries', |
| 416 | array( |
| 417 | 'viewed' => 'read' === $status ? 1 : 0, |
| 418 | ), |
| 419 | array( 'entry_id' => $entry_id ), |
| 420 | array( '%d' ), |
| 421 | array( '%d' ) |
| 422 | ); |
| 423 | } elseif ( 'approved' === $status ) { |
| 424 | $update = $wpdb->update( |
| 425 | $wpdb->prefix . 'evf_entries', |
| 426 | array( |
| 427 | 'status' => 'publish', |
| 428 | ), |
| 429 | array( 'entry_id' => $entry_id ), |
| 430 | array( '%s' ), |
| 431 | array( '%d' ) |
| 432 | ); |
| 433 | |
| 434 | $entry = evf_get_entry( $entry_id ); |
| 435 | $entry_meta = $entry->meta; |
| 436 | $entry_date = $entry->date_created; |
| 437 | $first_name = ''; |
| 438 | $last_name = ''; |
| 439 | $email = ''; |
| 440 | $site_name = get_option( 'blogname', '' ); |
| 441 | $subject = ''; |
| 442 | $message = ''; |
| 443 | $name = ''; |
| 444 | |
| 445 | foreach ( $entry_meta as $key => $value ) { |
| 446 | if ( preg_match( '/^first_name_/', $key ) ) { |
| 447 | $first_name = $value; |
| 448 | } |
| 449 | |
| 450 | if ( preg_match( '/^last_name_/', $key ) ) { |
| 451 | $last_name = $value; |
| 452 | } |
| 453 | |
| 454 | if ( preg_match( '/^email/', $key ) ) { |
| 455 | $email = $value; |
| 456 | } |
| 457 | |
| 458 | if ( '' === $name ) { |
| 459 | if ( ! empty( $first_name ) && ! empty( $last_name ) ) { |
| 460 | $name = $first_name . ' ' . $last_name; |
| 461 | } elseif ( ! empty( $first_name ) ) { |
| 462 | $name = $first_name; |
| 463 | } else { |
| 464 | $name = $last_name; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | $subject = apply_filters( 'everest_forms_entry_submission_approval_subject', esc_html__( 'Form Entry Approved', 'everest-forms' ) ); |
| 469 | /* translators:%s: User name of form entry */ |
| 470 | $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>'; |
| 471 | /* translators:%s: Form Entry Date */ |
| 472 | $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/>'; |
| 473 | $message .= '<br/>' . __( 'Thank you for giving us your precious time.', 'everest-forms' ) . '<br/>'; |
| 474 | /* translators:%s: Site Name*/ |
| 475 | $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name ); |
| 476 | $message = apply_filters( 'everest_forms_entry_approval_message', $message, $name, $entry_date, $site_name ); |
| 477 | } |
| 478 | |
| 479 | if ( ! $is_bulk_action ) { |
| 480 | $email_obj = new EVF_Emails(); |
| 481 | $email_obj->send( $email, $subject, $message ); |
| 482 | } |
| 483 | } elseif ( 'denied' === $status ) { |
| 484 | $update = $wpdb->update( |
| 485 | $wpdb->prefix . 'evf_entries', |
| 486 | array( |
| 487 | 'status' => $status, |
| 488 | ), |
| 489 | array( 'entry_id' => $entry_id ), |
| 490 | array( '%s' ), |
| 491 | array( '%d' ) |
| 492 | ); |
| 493 | |
| 494 | $entry = evf_get_entry( $entry_id ); |
| 495 | $entry_meta = $entry->meta; |
| 496 | $entry_date = $entry->date_created; |
| 497 | $first_name = ''; |
| 498 | $last_name = ''; |
| 499 | $email = ''; |
| 500 | $site_name = get_option( 'blogname', '' ); |
| 501 | $name = ''; |
| 502 | |
| 503 | foreach ( $entry_meta as $key => $value ) { |
| 504 | if ( preg_match( '/^first_name/', $key ) ) { |
| 505 | $first_name = $value; |
| 506 | } |
| 507 | |
| 508 | if ( preg_match( '/^last_name/', $key ) ) { |
| 509 | $last_name = $value; |
| 510 | } |
| 511 | |
| 512 | if ( preg_match( '/^email/', $key ) ) { |
| 513 | $email = $value; |
| 514 | } |
| 515 | |
| 516 | if ( '' === $name ) { |
| 517 | if ( ! empty( $first_name ) && ! empty( $last_name ) ) { |
| 518 | $name = $first_name . ' ' . $last_name; |
| 519 | } elseif ( ! empty( $first_name ) ) { |
| 520 | $name = $first_name; |
| 521 | } else { |
| 522 | $name = $last_name; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | $subject = apply_filters( 'everest_forms_entry_submission_denial_subject', esc_html__( 'Entry Submission Denied', 'everest-forms' ) ); |
| 527 | /* translators:%s: User name of form entry */ |
| 528 | $message = sprintf( __( 'Hey, %s', 'everest-forms' ), $name ) . '<br/>'; |
| 529 | /* translators:%s: Form Entry Date */ |
| 530 | $message .= '<br/>' . sprintf( __( 'We regret to inform you that your form entry submitted on %s has been denied.', 'everest-forms' ), $entry_date ) . '<br/>'; |
| 531 | $message .= '<br/>' . __( 'Thank you for giving us your precious time.', 'everest-forms' ) . '<br/>'; |
| 532 | /* translator: %s: Site Name */ |
| 533 | $message .= '<br/>' . sprintf( __( 'From %s', 'everest-forms' ), $site_name ); |
| 534 | $message = apply_filters( 'everest_forms_entry_denial_message', $message, $name, $entry_date, $site_name ); |
| 535 | } |
| 536 | |
| 537 | if ( ! $is_bulk_action ) { |
| 538 | $email_obj = new EVF_Emails(); |
| 539 | $email_obj->send( $email, $subject, $message ); |
| 540 | } |
| 541 | } elseif ( 'unspam' === $status ) { |
| 542 | $update = $wpdb->update( |
| 543 | $wpdb->prefix . 'evf_entries', |
| 544 | array( |
| 545 | 'status' => 'publish', |
| 546 | ), |
| 547 | array( 'entry_id' => $entry_id ), |
| 548 | array( '%s' ), |
| 549 | array( '%d' ) |
| 550 | ); |
| 551 | } else { |
| 552 | $entry = evf_get_entry( $entry_id ); |
| 553 | |
| 554 | // Preserve entry status. |
| 555 | if ( 'trash' === $status ) { |
| 556 | $wpdb->insert( |
| 557 | $wpdb->prefix . 'evf_entrymeta', |
| 558 | array( |
| 559 | 'entry_id' => $entry_id, |
| 560 | 'meta_key' => '_evf_trash_entry_status', |
| 561 | 'meta_value' => sanitize_text_field( $entry->status ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value |
| 562 | ) |
| 563 | ); |
| 564 | } elseif ( 'publish' === $status ) { |
| 565 | $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 ) ); |
| 566 | $wpdb->delete( |
| 567 | $wpdb->prefix . 'evf_entrymeta', |
| 568 | array( |
| 569 | 'entry_id' => $entry_id, |
| 570 | 'meta_key' => '_evf_trash_entry_status', |
| 571 | ) |
| 572 | ); |
| 573 | } |
| 574 | |
| 575 | $update = $wpdb->update( |
| 576 | $wpdb->prefix . 'evf_entries', |
| 577 | array( 'status' => $status ), |
| 578 | array( 'entry_id' => $entry_id ), |
| 579 | array( '%s' ), |
| 580 | array( '%d' ) |
| 581 | ); |
| 582 | } |
| 583 | |
| 584 | if ( false !== $update && $update > 0 ) { |
| 585 | do_action( 'everest_forms_entry_status_updated', $entry_id, $status ); |
| 586 | } |
| 587 | |
| 588 | return $update; |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * Check new entries with heartbeat API. |
| 593 | * |
| 594 | * @since 1.5.0 |
| 595 | * |
| 596 | * @param array $response The Heartbeat response. |
| 597 | * @param array $data The $_POST data sent. |
| 598 | * @param string $screen_id The screen id. |
| 599 | * @return array The Heartbeat response. |
| 600 | */ |
| 601 | public function check_new_entries( $response, $data, $screen_id ) { |
| 602 | if ( 'everest-forms_page_evf-entries' === $screen_id ) { |
| 603 | $form_id = ! empty( $data['evf_new_entries_form_id'] ) ? absint( $data['evf_new_entries_form_id'] ) : 0; |
| 604 | $last_entry_id = ! empty( $data['evf_new_entries_last_entry_id'] ) ? absint( $data['evf_new_entries_last_entry_id'] ) : 0; |
| 605 | |
| 606 | // Count new entries. |
| 607 | $entries_count = evf_get_count_entries_by_last_entry( $form_id, $last_entry_id ); |
| 608 | |
| 609 | if ( ! empty( $entries_count ) ) { |
| 610 | /* translators: %d - New form entries count. */ |
| 611 | $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 ) ); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | return $response; |
| 616 | } |
| 617 | |
| 618 | /** |
| 619 | * Delete booked slot after deleting the entries. |
| 620 | * |
| 621 | * @param int $form_id Form ID. |
| 622 | * @param int $entry_id Entry ID. |
| 623 | */ |
| 624 | public function evf_delete_booked_slot( $form_id, $entry_id ) { |
| 625 | $form_data = get_post( $form_id ); |
| 626 | $form_content = json_decode( $form_data->post_content, true ); |
| 627 | $form_fields = $form_content['form_fields']; |
| 628 | foreach ( $form_fields as $field_name => $field ) { |
| 629 | if ( 'date-time' === $field['type'] && isset( $field['slot_booking_advanced'] ) && evf_string_to_bool( $field['slot_booking_advanced'] ) ) { |
| 630 | $booked_slot = evf_maybe_unserialize( get_option( 'evf_booked_slot', '' ) ); |
| 631 | if ( ! empty( $booked_slot ) && array_key_exists( $form_id, $booked_slot ) ) { |
| 632 | $form_booked_slot = $booked_slot[ $form_id ]; |
| 633 | if ( array_key_exists( $entry_id, $form_booked_slot ) ) { |
| 634 | unset( $form_booked_slot[ $entry_id ] ); |
| 635 | $booked_slot[ $form_id ] = $form_booked_slot; |
| 636 | |
| 637 | $booked_slot = maybe_serialize( $booked_slot ); |
| 638 | update_option( 'evf_booked_slot', $booked_slot ); |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | new EVF_Admin_Entries(); |
| 647 |