PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.6.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.6.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 6 years ago plugin-updates 8 years ago settings 6 years ago views 6 years ago class-evf-admin-addons.php 6 years ago class-evf-admin-assets.php 6 years ago class-evf-admin-builder.php 8 years ago class-evf-admin-editor.php 6 years ago class-evf-admin-entries-table-list.php 6 years ago class-evf-admin-entries.php 6 years ago class-evf-admin-forms-table-list.php 6 years ago class-evf-admin-forms.php 6 years ago class-evf-admin-import-export.php 6 years ago class-evf-admin-menus.php 6 years ago class-evf-admin-notices.php 6 years ago class-evf-admin-settings.php 6 years ago class-evf-admin-tools.php 6 years ago class-evf-admin-welcome.php 6 years ago class-evf-admin.php 6 years ago evf-admin-functions.php 6 years ago
class-evf-admin-entries.php
375 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 sanitize_text_field( wp_unslash( $_REQUEST['status'] ) ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.EscapeOutput ?>" />
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 ob_start();
89 $entries_table_list->forms_dropdown();
90 $output = ob_get_clean();
91
92 if ( ! empty( $output ) ) {
93 echo $output; // @codingStandardsIgnoreLine
94 submit_button( __( 'Filter', 'everest-forms' ), '', '', false, array( 'id' => 'post-query-submit' ) );
95 }
96 ?>
97 </form>
98 <?php else : ?>
99 <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>
100 <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>
101 <?php endif; ?>
102 <style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display: none; }</style>
103 </div>
104 <?php endif; ?>
105 </div>
106 <?php
107 }
108
109 /**
110 * Entries admin actions.
111 */
112 public function actions() {
113 if ( $this->is_entries_page() ) {
114 // Trash entry.
115 if ( isset( $_GET['trash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
116 $this->trash_entry();
117 }
118
119 // Untrash entry.
120 if ( isset( $_GET['untrash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
121 $this->untrash_entry();
122 }
123
124 // Delete entry.
125 if ( isset( $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
126 $this->delete_entry();
127 }
128
129 // Export CSV.
130 if ( isset( $_REQUEST['export_action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
131 $this->export_csv();
132 }
133
134 // Empty Trash.
135 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
136 $this->empty_trash();
137 }
138 }
139 }
140
141 /**
142 * Trash entry.
143 */
144 private function trash_entry() {
145 check_admin_referer( 'trash-entry' );
146
147 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
148
149 if ( isset( $_GET['trash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
150 $entry_id = absint( $_GET['trash'] ); // phpcs:ignore WordPress.Security.NonceVerification
151
152 if ( $entry_id ) {
153 self::update_status( $entry_id, 'trash' );
154 }
155 }
156
157 wp_safe_redirect(
158 esc_url_raw(
159 add_query_arg(
160 array(
161 'form_id' => $form_id,
162 'trashed' => 1,
163 ),
164 admin_url( 'admin.php?page=evf-entries' )
165 )
166 )
167 );
168 exit();
169 }
170
171 /**
172 * Trash entry.
173 */
174 private function untrash_entry() {
175 check_admin_referer( 'untrash-entry' );
176
177 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
178
179 if ( isset( $_GET['untrash'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
180 $entry_id = absint( $_GET['untrash'] ); // phpcs:ignore WordPress.Security.NonceVerification
181
182 if ( $entry_id ) {
183 self::update_status( $entry_id, 'publish' );
184 }
185 }
186
187 wp_safe_redirect(
188 esc_url_raw(
189 add_query_arg(
190 array(
191 'form_id' => $form_id,
192 'untrashed' => 1,
193 ),
194 admin_url( 'admin.php?page=evf-entries' )
195 )
196 )
197 );
198 exit();
199 }
200
201 /**
202 * Delete entry.
203 */
204 private function delete_entry() {
205 check_admin_referer( 'delete-entry' );
206
207 $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '';
208
209 if ( isset( $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
210 $entry_id = absint( $_GET['delete'] ); // phpcs:ignore WordPress.Security.NonceVerification
211
212 if ( $entry_id ) {
213 self::remove_entry( $entry_id );
214 }
215 }
216
217 wp_safe_redirect(
218 esc_url_raw(
219 add_query_arg(
220 array(
221 'form_id' => $form_id,
222 'deleted' => 1,
223 ),
224 admin_url( 'admin.php?page=evf-entries' )
225 )
226 )
227 );
228 exit();
229 }
230
231 /**
232 * Empty Trash.
233 */
234 public function empty_trash() {
235 global $wpdb;
236
237 check_admin_referer( 'bulk-entries' );
238
239 if ( isset( $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
240 $form_id = absint( $_GET['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification
241
242 if ( $form_id ) {
243 $count = 0;
244 $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.
245 $entry_ids = array_map( 'intval', wp_list_pluck( $results, 'entry_id' ) );
246
247 foreach ( $entry_ids as $entry_id ) {
248 if ( self::remove_entry( $entry_id ) ) {
249 $count ++;
250 }
251 }
252
253 add_settings_error(
254 'empty_trash',
255 'empty_trash',
256 /* translators: %d: number of entries */
257 sprintf( _n( '%d entry permanently deleted.', '%d entries permanently deleted.', $count, 'everest-forms' ), $count ),
258 'updated'
259 );
260 }
261 }
262 }
263
264 /**
265 * Do the entries export.
266 *
267 * @since 1.3.0
268 */
269 public function export_csv() {
270 check_admin_referer( 'bulk-entries' );
271
272 if ( isset( $_REQUEST['form_id'] ) && current_user_can( 'export' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
273 include_once EVF_ABSPATH . 'includes/export/class-evf-entry-csv-exporter.php';
274 $form_id = absint( $_REQUEST['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification
275 $form_name = strtolower( get_the_title( $form_id ) );
276
277 if ( $form_name ) {
278 $exporter = new EVF_Entry_CSV_Exporter( $form_id );
279 $exporter->set_filename( evf_get_csv_file_name( $form_name ) );
280 }
281
282 $exporter->export();
283 }
284 }
285
286 /**
287 * Remove entry.
288 *
289 * @param int $entry_id Entry ID.
290 * @return bool
291 */
292 public static function remove_entry( $entry_id ) {
293 global $wpdb;
294
295 $delete = $wpdb->delete( $wpdb->prefix . 'evf_entries', array( 'entry_id' => $entry_id ), array( '%d' ) );
296
297 if ( apply_filters( 'everest_forms_delete_entrymeta', true ) ) {
298 $wpdb->delete( $wpdb->prefix . 'evf_entrymeta', array( 'entry_id' => $entry_id ), array( '%d' ) );
299 }
300
301 return $delete;
302 }
303
304 /**
305 * Set entry status.
306 *
307 * @param int $entry_id Entry ID.
308 * @param string $status Entry status.
309 */
310 public static function update_status( $entry_id, $status = 'publish' ) {
311 global $wpdb;
312
313 if ( in_array( $status, array( 'star', 'unstar' ), true ) ) {
314 $update = $wpdb->update(
315 $wpdb->prefix . 'evf_entries',
316 array(
317 'starred' => 'star' === $status ? 1 : 0,
318 ),
319 array( 'entry_id' => $entry_id ),
320 array( '%d' ),
321 array( '%d' )
322 );
323 } elseif ( in_array( $status, array( 'read', 'unread' ), true ) ) {
324 $update = $wpdb->update(
325 $wpdb->prefix . 'evf_entries',
326 array(
327 'viewed' => 'read' === $status ? 1 : 0,
328 ),
329 array( 'entry_id' => $entry_id ),
330 array( '%d' ),
331 array( '%d' )
332 );
333 } else {
334 $update = $wpdb->update(
335 $wpdb->prefix . 'evf_entries',
336 array( 'status' => $status ),
337 array( 'entry_id' => $entry_id ),
338 array( '%s' ),
339 array( '%d' )
340 );
341 }
342
343 return $update;
344 }
345
346 /**
347 * Check new entries with heartbeat API.
348 *
349 * @since 1.5.0
350 *
351 * @param array $response The Heartbeat response.
352 * @param array $data The $_POST data sent.
353 * @param string $screen_id The screen id.
354 * @return array The Heartbeat response.
355 */
356 public function check_new_entries( $response, $data, $screen_id ) {
357 if ( 'everest-forms_page_evf-entries' === $screen_id ) {
358 $form_id = ! empty( $data['evf_new_entries_form_id'] ) ? absint( $data['evf_new_entries_form_id'] ) : 0;
359 $last_entry_id = ! empty( $data['evf_new_entries_last_entry_id'] ) ? absint( $data['evf_new_entries_last_entry_id'] ) : 0;
360
361 // Count new entries.
362 $entries_count = evf_get_count_entries_by_last_entry( $form_id, $last_entry_id );
363
364 if ( ! empty( $entries_count ) ) {
365 /* translators: %d - New form entries count. */
366 $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 ) );
367 }
368 }
369
370 return $response;
371 }
372 }
373
374 new EVF_Admin_Entries();
375