PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 2.0.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v2.0.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 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 3 years ago class-evf-admin-entries.php 4 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 3 years ago
class-evf-admin-entries.php
394 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 }
23
24 /**
25 * Check if is entries page.
26 *
27 * @return bool
28 */
29 private function is_entries_page() {
30 return isset( $_GET['page'] ) && 'evf-entries' === $_GET['page']; // phpcs:ignore WordPress.Security.NonceVerification
31 }
32
33 /**
34 * Page output.
35 */
36 public static function page_output() {
37 if ( apply_filters( 'everest_forms_entries_list_actions', false ) ) {
38 do_action( 'everest_forms_entries_list_actions_execute' );
39 } elseif ( isset( $_GET['view-entry'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
40 include 'views/html-admin-page-entries-view.php';
41 } else {
42 self::table_list_output();
43 }
44 }
45
46 /**
47 * Table list output.
48 */
49 private static function table_list_output() {
50 global $entries_table_list;
51
52 // Get the entries IDs.
53 $entry_ids = evf_get_entries_ids( $entries_table_list->form_id );
54
55 $entries_table_list->process_bulk_action();
56 $entries_table_list->prepare_items();
57 ?>
58 <div id="everest-forms-entries-list" class="wrap">
59 <h1 class="wp-heading-inline"><?php esc_html_e( 'Entries', 'everest-forms' ); ?></h1>
60 <hr class="wp-header-end">
61
62 <?php settings_errors(); ?>
63 <?php do_action( 'everest_forms_before_entry_list', $entries_table_list ); ?>
64
65 <?php if ( 0 < count( $entry_ids ) ) : ?>
66 <?php $entries_table_list->views(); ?>
67 <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 ) ); ?>">
68 <input type="hidden" name="page" value="evf-entries" />
69 <?php if ( ! empty( $_REQUEST['form_id'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification ?>
70 <input type="hidden" name="form_id" value="<?php echo absint( $_REQUEST['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification ?>" />
71 <?php endif; ?>
72 <?php if ( ! empty( $_REQUEST['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification ?>
73 <input type="hidden" name="status" value="<?php echo esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification ?>" />
74 <?php endif; ?>
75 <?php
76 $entries_table_list->search_box( esc_html__( 'Search Entries', 'everest-forms' ), 'everest-forms' );
77 $entries_table_list->display();
78 ?>
79 </form>
80 <?php else : ?>
81 <div class="everest-forms-BlankState">
82 <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>
83 <h2 class="everest-forms-BlankState-message"><?php esc_html_e( 'Whoops, it appears you do not have any form entries yet.', 'everest-forms' ); ?></h2>
84 <?php if ( ! empty( $entries_table_list->forms ) ) : ?>
85 <form id="entries-list" method="get">
86 <input type="hidden" name="page" value="evf-entries" />
87 <?php
88 $entries_table_list->forms_dropdown();
89 submit_button( __( 'Filter', 'everest-forms' ), '', '', false, array( 'id' => 'post-query-submit' ) );
90 ?>
91 </form>
92 <?php else : ?>
93 <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>
94 <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>
95 <?php endif; ?>
96 <style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display: none; }</style>
97 </div>
98 <?php endif; ?>
99 </div>
100 <?php
101 }
102
103 /**
104 * Entries admin actions.
105 */
106 public function actions() {
107 if ( $this->is_entries_page() ) {
108 // Trash entry.
109 if ( isset( $_GET['trash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
110 $this->trash_entry();
111 }
112
113 // Untrash entry.
114 if ( isset( $_GET['untrash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
115 $this->untrash_entry();
116 }
117
118 // Delete entry.
119 if ( isset( $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
120 $this->delete_entry();
121 }
122
123 // Export CSV.
124 if ( isset( $_REQUEST['export_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
125 $this->export_csv();
126 }
127
128 // Empty Trash.
129 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
130 $this->empty_trash();
131 }
132 }
133 }
134
135 /**
136 * Trash entry.
137 */
138 private function trash_entry() {
139 check_admin_referer( 'trash-entry' );
140
141 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
142
143 if ( isset( $_GET['trash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
144 $entry_id = absint( $_GET['trash'] ); // phpcs:ignore WordPress.Security.NonceVerification
145
146 if ( $entry_id ) {
147 self::update_status( $entry_id, 'trash' );
148 }
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 );
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 ) ) {
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 * @return bool
285 */
286 public static function remove_entry( $entry_id ) {
287 global $wpdb;
288
289 do_action( 'everest_forms_before_delete_entries', $entry_id );
290
291 $delete = $wpdb->delete( $wpdb->prefix . 'evf_entries', array( 'entry_id' => $entry_id ), array( '%d' ) );
292
293 if ( apply_filters( 'everest_forms_delete_entrymeta', true ) ) {
294 $wpdb->delete( $wpdb->prefix . 'evf_entrymeta', array( 'entry_id' => $entry_id ), array( '%d' ) );
295 }
296
297 return $delete;
298 }
299
300 /**
301 * Set entry status.
302 *
303 * @param int $entry_id Entry ID.
304 * @param string $status Entry status.
305 */
306 public static function update_status( $entry_id, $status = 'publish' ) {
307 global $wpdb;
308
309 if ( in_array( $status, array( 'star', 'unstar' ), true ) ) {
310 $update = $wpdb->update(
311 $wpdb->prefix . 'evf_entries',
312 array(
313 'starred' => 'star' === $status ? 1 : 0,
314 ),
315 array( 'entry_id' => $entry_id ),
316 array( '%d' ),
317 array( '%d' )
318 );
319 } elseif ( in_array( $status, array( 'read', 'unread' ), true ) ) {
320 $update = $wpdb->update(
321 $wpdb->prefix . 'evf_entries',
322 array(
323 'viewed' => 'read' === $status ? 1 : 0,
324 ),
325 array( 'entry_id' => $entry_id ),
326 array( '%d' ),
327 array( '%d' )
328 );
329 } else {
330 $entry = evf_get_entry( $entry_id );
331
332 // Preseve entry status.
333 if ( 'trash' === $status ) {
334 $wpdb->insert(
335 $wpdb->prefix . 'evf_entrymeta',
336 array(
337 'entry_id' => $entry_id,
338 'meta_key' => '_evf_trash_entry_status',
339 'meta_value' => sanitize_text_field( $entry->status ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
340 )
341 );
342 } elseif ( 'publish' === $status ) {
343 $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 ) );
344 $wpdb->delete(
345 $wpdb->prefix . 'evf_entrymeta',
346 array(
347 'entry_id' => $entry_id,
348 'meta_key' => '_evf_trash_entry_status',
349 )
350 );
351 }
352
353 $update = $wpdb->update(
354 $wpdb->prefix . 'evf_entries',
355 array( 'status' => $status ),
356 array( 'entry_id' => $entry_id ),
357 array( '%s' ),
358 array( '%d' )
359 );
360 }
361
362 return $update;
363 }
364
365 /**
366 * Check new entries with heartbeat API.
367 *
368 * @since 1.5.0
369 *
370 * @param array $response The Heartbeat response.
371 * @param array $data The $_POST data sent.
372 * @param string $screen_id The screen id.
373 * @return array The Heartbeat response.
374 */
375 public function check_new_entries( $response, $data, $screen_id ) {
376 if ( 'everest-forms_page_evf-entries' === $screen_id ) {
377 $form_id = ! empty( $data['evf_new_entries_form_id'] ) ? absint( $data['evf_new_entries_form_id'] ) : 0;
378 $last_entry_id = ! empty( $data['evf_new_entries_last_entry_id'] ) ? absint( $data['evf_new_entries_last_entry_id'] ) : 0;
379
380 // Count new entries.
381 $entries_count = evf_get_count_entries_by_last_entry( $form_id, $last_entry_id );
382
383 if ( ! empty( $entries_count ) ) {
384 /* translators: %d - New form entries count. */
385 $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 ) );
386 }
387 }
388
389 return $response;
390 }
391 }
392
393 new EVF_Admin_Entries();
394