PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 2.0.4
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v2.0.4
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 2 years ago plugin-updates 8 years ago settings 2 years ago views 2 years ago class-evf-admin-addons.php 4 years ago class-evf-admin-assets.php 2 years ago class-evf-admin-builder.php 7 years ago class-evf-admin-deactivation-feedback.php 3 years ago class-evf-admin-editor.php 4 years ago class-evf-admin-entries-table-list.php 2 years ago class-evf-admin-entries.php 2 years ago class-evf-admin-form-templates.php 3 years ago class-evf-admin-forms-table-list.php 3 years ago class-evf-admin-forms.php 3 years ago class-evf-admin-import-export.php 4 years ago class-evf-admin-menus.php 2 years ago class-evf-admin-notices.php 3 years ago class-evf-admin-settings.php 2 years ago class-evf-admin-tools.php 4 years ago class-evf-admin-welcome.php 2 years ago class-evf-admin.php 2 years ago evf-admin-functions.php 2 years ago
class-evf-admin-entries.php
423 lines
1 <?php
2 /**
3 * EverestForms Admin Entries Class
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;
52
53 // Get the entries IDs.
54 $entry_ids = evf_get_entries_ids( $entries_table_list->form_id );
55
56 $entries_table_list->process_bulk_action();
57 $entries_table_list->prepare_items();
58 ?>
59 <div id="everest-forms-entries-list" class="wrap">
60 <h1 class="wp-heading-inline"><?php esc_html_e( 'Entries', 'everest-forms' ); ?></h1>
61 <hr class="wp-header-end">
62
63 <?php settings_errors(); ?>
64 <?php do_action( 'everest_forms_before_entry_list', $entries_table_list ); ?>
65
66 <?php if ( 0 < count( $entry_ids ) ) : ?>
67 <?php $entries_table_list->views(); ?>
68 <form id="entries-list" method="get" data-form-id="<?php echo absint( $entries_table_list->form_id ); ?>" data-last-entry-id="<?php echo absint( end( $entry_ids ) ); ?>">
69 <input type="hidden" name="page" value="evf-entries" />
70 <?php if ( ! empty( $_REQUEST['form_id'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification ?>
71 <input type="hidden" name="form_id" value="<?php echo absint( $_REQUEST['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification ?>" />
72 <?php endif; ?>
73 <?php if ( ! empty( $_REQUEST['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification ?>
74 <input type="hidden" name="status" value="<?php echo esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification ?>" />
75 <?php endif; ?>
76 <?php
77 $entries_table_list->search_box( esc_html__( 'Search Entries', 'everest-forms' ), 'everest-forms' );
78 $entries_table_list->display();
79 ?>
80 </form>
81 <?php else : ?>
82 <div class="everest-forms-BlankState">
83 <svg aria-hidden="true" class="octicon octicon-graph everest-forms-BlankState-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M16 14v1H0V0h1v14h15zM5 13H3V8h2v5zm4 0H7V3h2v10zm4 0h-2V6h2v7z"/></svg>
84 <h2 class="everest-forms-BlankState-message"><?php esc_html_e( 'Whoops, it appears you do not have any form entries yet.', 'everest-forms' ); ?></h2>
85 <?php if ( ! empty( $entries_table_list->forms ) ) : ?>
86 <form id="entries-list" method="get">
87 <input type="hidden" name="page" value="evf-entries" />
88 <?php
89 $entries_table_list->forms_dropdown();
90 submit_button( __( 'Filter', 'everest-forms' ), '', '', false, array( 'id' => 'post-query-submit' ) );
91 ?>
92 </form>
93 <?php else : ?>
94 <a class="everest-forms-BlankState-cta button-primary button" target="_blank" href="https://docs.wpeverest.com/docs/everest-forms/entry-management/?utm_source=blankslate&utm_medium=entry&utm_content=entriesdoc&utm_campaign=everestformplugin"><?php esc_html_e( 'Learn more about entries', 'everest-forms' ); ?></a>
95 <a class="everest-forms-BlankState-cta button" href="<?php echo esc_url( admin_url( 'admin.php?page=evf-builder&create-form=1' ) ); ?>"><?php esc_html_e( 'Create your first form!', 'everest-forms' ); ?></a>
96 <?php endif; ?>
97 <style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display: none; }</style>
98 </div>
99 <?php endif; ?>
100 </div>
101 <?php
102 }
103
104 /**
105 * Entries admin actions.
106 */
107 public function actions() {
108 if ( $this->is_entries_page() ) {
109 // Trash entry.
110 if ( isset( $_GET['trash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
111 $this->trash_entry();
112 }
113
114 // Untrash entry.
115 if ( isset( $_GET['untrash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
116 $this->untrash_entry();
117 }
118
119 // Delete entry.
120 if ( isset( $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
121 $this->delete_entry();
122 }
123
124 // Export CSV.
125 if ( isset( $_REQUEST['export_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
126 $this->export_csv();
127 }
128
129 // Empty Trash.
130 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
131 $this->empty_trash();
132 }
133 }
134 }
135
136 /**
137 * Trash entry.
138 */
139 private function trash_entry() {
140 check_admin_referer( 'trash-entry' );
141
142 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
143
144 if ( isset( $_GET['trash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
145 $entry_id = absint( $_GET['trash'] ); // phpcs:ignore WordPress.Security.NonceVerification
146
147 if ( $entry_id ) {
148 self::update_status( $entry_id, 'trash' );
149 }
150 }
151 wp_safe_redirect(
152 esc_url_raw(
153 add_query_arg(
154 array(
155 'form_id' => $form_id,
156 'trashed' => 1,
157 ),
158 admin_url( 'admin.php?page=evf-entries' )
159 )
160 )
161 );
162 exit();
163 }
164
165 /**
166 * Trash entry.
167 */
168 private function untrash_entry() {
169 check_admin_referer( 'untrash-entry' );
170
171 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
172
173 if ( isset( $_GET['untrash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
174 $entry_id = absint( $_GET['untrash'] ); // phpcs:ignore WordPress.Security.NonceVerification
175
176 if ( $entry_id ) {
177 self::update_status( $entry_id, 'publish' );
178 }
179 }
180
181 wp_safe_redirect(
182 esc_url_raw(
183 add_query_arg(
184 array(
185 'form_id' => $form_id,
186 'untrashed' => 1,
187 ),
188 admin_url( 'admin.php?page=evf-entries' )
189 )
190 )
191 );
192 exit();
193 }
194
195 /**
196 * Delete entry.
197 */
198 private function delete_entry() {
199 check_admin_referer( 'delete-entry' );
200
201 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
202
203 if ( isset( $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
204 $entry_id = absint( $_GET['delete'] ); // phpcs:ignore WordPress.Security.NonceVerification
205
206 if ( $entry_id ) {
207 self::remove_entry( $entry_id, $form_id );
208 }
209 }
210
211 wp_safe_redirect(
212 esc_url_raw(
213 add_query_arg(
214 array(
215 'form_id' => $form_id,
216 'deleted' => 1,
217 ),
218 admin_url( 'admin.php?page=evf-entries' )
219 )
220 )
221 );
222 exit();
223 }
224
225 /**
226 * Empty Trash.
227 */
228 public function empty_trash() {
229 global $wpdb;
230
231 check_admin_referer( 'bulk-entries' );
232
233 if ( isset( $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
234 $form_id = absint( $_GET['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification
235
236 if ( $form_id ) {
237 $count = 0;
238 $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.
239 $entry_ids = array_map( 'intval', wp_list_pluck( $results, 'entry_id' ) );
240
241 foreach ( $entry_ids as $entry_id ) {
242 if ( self::remove_entry( $entry_id, $form_id ) ) {
243 ++$count;
244 }
245 }
246
247 add_settings_error(
248 'empty_trash',
249 'empty_trash',
250 /* translators: %d: number of entries */
251 sprintf( _n( '%d entry permanently deleted.', '%d entries permanently deleted.', $count, 'everest-forms' ), $count ),
252 'updated'
253 );
254 }
255 }
256 }
257
258 /**
259 * Do the entries export.
260 *
261 * @since 1.3.0
262 */
263 public function export_csv() {
264 check_admin_referer( 'bulk-entries' );
265
266 if ( isset( $_REQUEST['form_id'] ) && current_user_can( 'export' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
267 include_once EVF_ABSPATH . 'includes/export/class-evf-entry-csv-exporter.php';
268 $form_id = absint( $_REQUEST['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification
269 $form_name = strtolower( get_the_title( $form_id ) );
270
271 if ( $form_name ) {
272 $exporter = new EVF_Entry_CSV_Exporter( $form_id );
273 $exporter->set_filename( evf_get_entry_export_file_name( $form_name ) );
274 }
275
276 $exporter->export();
277 }
278 }
279
280 /**
281 * Remove entry.
282 *
283 * @param int $entry_id Entry ID.
284 * @param int $form_id Form ID.
285 * @return bool
286 */
287 public static function remove_entry( $entry_id, $form_id = 0 ) {
288 global $wpdb;
289
290 do_action( 'everest_forms_before_delete_entries', $entry_id );
291
292 $delete = $wpdb->delete( $wpdb->prefix . 'evf_entries', array( 'entry_id' => $entry_id ), array( '%d' ) );
293
294 if ( apply_filters( 'everest_forms_delete_entrymeta', true ) ) {
295 $wpdb->delete( $wpdb->prefix . 'evf_entrymeta', array( 'entry_id' => $entry_id ), array( '%d' ) );
296 }
297
298 do_action( 'everest_forms_after_delete_entries', $form_id, $entry_id );
299
300 return $delete;
301 }
302
303 /**
304 * Set entry status.
305 *
306 * @param int $entry_id Entry ID.
307 * @param string $status Entry status.
308 */
309 public static function update_status( $entry_id, $status = 'publish' ) {
310 global $wpdb;
311
312 if ( in_array( $status, array( 'star', 'unstar' ), true ) ) {
313 $update = $wpdb->update(
314 $wpdb->prefix . 'evf_entries',
315 array(
316 'starred' => 'star' === $status ? 1 : 0,
317 ),
318 array( 'entry_id' => $entry_id ),
319 array( '%d' ),
320 array( '%d' )
321 );
322 } elseif ( in_array( $status, array( 'read', 'unread' ), true ) ) {
323 $update = $wpdb->update(
324 $wpdb->prefix . 'evf_entries',
325 array(
326 'viewed' => 'read' === $status ? 1 : 0,
327 ),
328 array( 'entry_id' => $entry_id ),
329 array( '%d' ),
330 array( '%d' )
331 );
332 } else {
333 $entry = evf_get_entry( $entry_id );
334
335 // Preseve entry status.
336 if ( 'trash' === $status ) {
337 $wpdb->insert(
338 $wpdb->prefix . 'evf_entrymeta',
339 array(
340 'entry_id' => $entry_id,
341 'meta_key' => '_evf_trash_entry_status',
342 'meta_value' => sanitize_text_field( $entry->status ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
343 )
344 );
345 } elseif ( 'publish' === $status ) {
346 $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 ) );
347 $wpdb->delete(
348 $wpdb->prefix . 'evf_entrymeta',
349 array(
350 'entry_id' => $entry_id,
351 'meta_key' => '_evf_trash_entry_status',
352 )
353 );
354 }
355
356 $update = $wpdb->update(
357 $wpdb->prefix . 'evf_entries',
358 array( 'status' => $status ),
359 array( 'entry_id' => $entry_id ),
360 array( '%s' ),
361 array( '%d' )
362 );
363 }
364
365 return $update;
366 }
367
368 /**
369 * Check new entries with heartbeat API.
370 *
371 * @since 1.5.0
372 *
373 * @param array $response The Heartbeat response.
374 * @param array $data The $_POST data sent.
375 * @param string $screen_id The screen id.
376 * @return array The Heartbeat response.
377 */
378 public function check_new_entries( $response, $data, $screen_id ) {
379 if ( 'everest-forms_page_evf-entries' === $screen_id ) {
380 $form_id = ! empty( $data['evf_new_entries_form_id'] ) ? absint( $data['evf_new_entries_form_id'] ) : 0;
381 $last_entry_id = ! empty( $data['evf_new_entries_last_entry_id'] ) ? absint( $data['evf_new_entries_last_entry_id'] ) : 0;
382
383 // Count new entries.
384 $entries_count = evf_get_count_entries_by_last_entry( $form_id, $last_entry_id );
385
386 if ( ! empty( $entries_count ) ) {
387 /* translators: %d - New form entries count. */
388 $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 ) );
389 }
390 }
391
392 return $response;
393 }
394 /**
395 * Delete booked slot after deleting the entries.
396 *
397 * @param int $form_id form id.
398 * @param int $entry_id entry id.
399 */
400 public function evf_delete_booked_slot( $form_id, $entry_id ) {
401 $form_data = get_post( $form_id );
402 $form_content = json_decode( $form_data->post_content, true );
403 $form_fields = $form_content['form_fields'];
404 foreach ( $form_fields as $field_name => $field ) {
405 if ( 'date-time' === $field['type'] && isset( $field['slot_booking_advanced'] ) && evf_string_to_bool( $field['slot_booking_advanced'] ) ) {
406 $booked_slot = maybe_unserialize( get_option( 'evf_booked_slot', '' ) );
407 if ( ! empty( $booked_slot ) && array_key_exists( $form_id, $booked_slot ) ) {
408 $form_booked_slot = $booked_slot[ $form_id ];
409 if ( array_key_exists( $entry_id, $form_booked_slot ) ) {
410 unset( $form_booked_slot[ $entry_id ] );
411 $booked_slot[ $form_id ] = $form_booked_slot;
412
413 $booked_slot = maybe_serialize( $booked_slot );
414 update_option( 'evf_booked_slot', $booked_slot );
415 }
416 }
417 }
418 }
419 }
420 }
421
422 new EVF_Admin_Entries();
423