-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheme-cleanup.php
More file actions
450 lines (415 loc) · 24.5 KB
/
eme-cleanup.php
File metadata and controls
450 lines (415 loc) · 24.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
function eme_get_cleanup_people() {
global $wpdb;
$bookings_table = EME_DB_PREFIX . EME_BOOKINGS_TBNAME;
$members_table = EME_DB_PREFIX . EME_MEMBERS_TBNAME;
$usergroups_table = EME_DB_PREFIX . EME_USERGROUPS_TBNAME;
$people_table = EME_DB_PREFIX . EME_PEOPLE_TBNAME;
$tasksignup_table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$prepared_sql = $wpdb->prepare( "SELECT $people_table.person_id, $people_table.firstname, $people_table.lastname, $people_table.email, $people_table.creation_date, $people_table.modif_date FROM $people_table WHERE NOT EXISTS (SELECT 1 FROM $bookings_table WHERE $bookings_table.person_id=$people_table.person_id) AND NOT EXISTS (SELECT 1 FROM $members_table WHERE $members_table.person_id=$people_table.person_id) AND NOT EXISTS (SELECT 1 FROM $usergroups_table WHERE $usergroups_table.person_id=$people_table.person_id) AND NOT EXISTS (SELECT 1 FROM $tasksignup_table WHERE $tasksignup_table.person_id=$people_table.person_id) AND status !=%d AND $people_table.wp_id=0 ORDER BY $people_table.modif_date", EME_PEOPLE_STATUS_TRASH );
return $wpdb->get_results( $prepared_sql, ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
function eme_cleanup_people() {
$people = eme_get_cleanup_people();
$count = count( $people );
if ( $count > 0 ) {
$person_ids = array_column( $people, 'person_id' );
$tmp_ids = join( ',', $person_ids );
eme_trash_people( $tmp_ids );
}
return $count;
}
function eme_cleanup_trashed_people( $eme_number, $eme_period ) {
global $wpdb;
$people_table = EME_DB_PREFIX . EME_PEOPLE_TBNAME;
if ( $eme_number < 1 ) {
$eme_number = 1;
}
$eme_date_obj = new emeExpressiveDate( 'now', EME_TIMEZONE );
switch ( $eme_period ) {
case 'day':
$eme_date_obj->minusDays( $eme_number );
break;
case 'week':
$eme_date_obj->minusWeeks( $eme_number );
break;
default:
$eme_date_obj->minusMonths( $eme_number );
break;
}
$datetime = $eme_date_obj->getDateTime();
$prepared_sql = $wpdb->prepare( "SELECT person_id FROM $people_table WHERE modif_date < %s AND status = %d", $datetime, EME_PEOPLE_STATUS_TRASH ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$person_ids = $wpdb->get_col( $prepared_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$count = count( $person_ids );
$tmp_ids = join( ',', $person_ids );
eme_delete_people( $tmp_ids );
return $count;
}
function eme_cleanup_trashed_bookings( $eme_number, $eme_period ) {
global $wpdb;
$bookings_table = EME_DB_PREFIX . EME_BOOKINGS_TBNAME;
if ( $eme_number < 1 ) {
$eme_number = 1;
}
$eme_date_obj = new emeExpressiveDate( 'now', EME_TIMEZONE );
switch ( $eme_period ) {
case 'day':
$eme_date_obj->minusDays( $eme_number );
break;
case 'week':
$eme_date_obj->minusWeeks( $eme_number );
break;
default:
$eme_date_obj->minusMonths( $eme_number );
break;
}
$datetime = $eme_date_obj->getDateTime();
$prepared_sql = $wpdb->prepare("SELECT COUNT(*) FROM $bookings_table WHERE modif_date < %s AND status = %d", $datetime, EME_RSVP_STATUS_TRASH);
$count = $wpdb->get_var( $prepared_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$prepared_sql = $wpdb->prepare("DELETE FROM $bookings_table WHERE modif_date < %s AND status = %d", $datetime, EME_RSVP_STATUS_TRASH);
$wpdb->query( $prepared_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
return $count;
}
function eme_cleanup_unconfirmed( $eme_number ) {
global $wpdb;
$bookings_table = EME_DB_PREFIX . EME_BOOKINGS_TBNAME;
$members_table = EME_DB_PREFIX . EME_MEMBERS_TBNAME;
$events_table = EME_DB_PREFIX . EME_EVENTS_TBNAME;
$eme_date_obj = new emeExpressiveDate( 'now', EME_TIMEZONE );
$today = $eme_date_obj->getDateTime();
// the min is 5 minutes, but if 0 we won't do anything either, to be safe
if ( ! $eme_number ) {
return;
}
if ( $eme_number < 5 ) {
$eme_number = 5;
}
$old_date = $eme_date_obj->minusMinutes( $eme_number )->getDateTime();
$prepared_sql = $wpdb->prepare( "SELECT $bookings_table.booking_id FROM $bookings_table LEFT JOIN $events_table ON $bookings_table.event_id=$events_table.event_id WHERE $bookings_table.status = %d AND $bookings_table.booking_paid = 0 AND $events_table.event_start > %s AND $bookings_table.creation_date < %s", EME_RSVP_STATUS_USERPENDING, $today, $old_date );
$booking_ids = $wpdb->get_col( $prepared_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
foreach ( $booking_ids as $booking_id ) {
$booking = eme_get_booking( $booking_id );
$person = eme_get_person( $booking['person_id'] );
$event = eme_get_event( $booking['event_id'] );
if ( ! empty( $event ) ) {
eme_trash_booking( $booking_id );
eme_manage_waitinglist( $event );
}
$eme_date_obj_booking_created = new emeExpressiveDate( $booking['creation_date'], EME_TIMEZONE );
$eme_date_obj_person_modified = new emeExpressiveDate( $person['modif_date'], EME_TIMEZONE );
$diff = abs( $eme_date_obj_booking_created->getDifferenceInMinutes( $eme_date_obj_person_modified ) );
// if the person was modified at most 2 minutes after booking creation (meaning in fact never), we also delete the person if no other bookings or members match that person
if ( $diff < 2 ) {
$prepared_sql = $wpdb->prepare( "SELECT (SELECT COUNT(*) FROM $bookings_table WHERE person_id=%d AND status != %d) + (SELECT COUNT(*) FROM $members_table WHERE person_id=%d AND status != %d)", $booking['person_id'], EME_RSVP_STATUS_TRASH, $booking['person_id'], EME_MEMBER_STATUS_EXPIRED );
$count = $wpdb->get_var( $prepared_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if ( $count == 0 ) {
eme_trash_people( $booking['person_id'] );
}
}
}
}
function eme_cleanup_unpaid( $eme_number ) {
global $wpdb;
$bookings_table = EME_DB_PREFIX . EME_BOOKINGS_TBNAME;
$events_table = EME_DB_PREFIX . EME_EVENTS_TBNAME;
$eme_date_obj = new emeExpressiveDate( 'now', EME_TIMEZONE );
$today = $eme_date_obj->getDateTime();
// the min is 5 minutes, but if 0 we won't do anything either, to be safe
if ( ! $eme_number ) {
return;
}
if ( $eme_number < 5 ) {
$eme_number = 5;
}
$old_date = $eme_date_obj->minusMinutes( $eme_number )->getDateTime();
$prepared_sql = $wpdb->prepare( "SELECT bookings.booking_id FROM $bookings_table AS bookings LEFT JOIN $events_table AS events ON bookings.event_id=events.event_id WHERE bookings.status = %d AND bookings.booking_paid = 0 AND events.event_start > %s AND bookings.creation_date < %s", EME_RSVP_STATUS_PENDING, $today, $old_date );
$booking_ids = $wpdb->get_col( $prepared_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
foreach ( $booking_ids as $booking_id ) {
$booking = eme_get_booking( $booking_id );
$event = eme_get_event( $booking['event_id'] );
if ( ! empty( $event ) ) {
eme_trash_booking( $booking_id );
eme_manage_waitinglist( $event );
eme_email_booking_action( $booking, 'cancelBooking' );
}
}
}
function eme_cleanup_events( $eme_number, $eme_period ) {
global $wpdb;
$bookings_table = EME_DB_PREFIX . EME_BOOKINGS_TBNAME;
$attendances_table = EME_DB_PREFIX . EME_ATTENDANCES_TBNAME;
$events_table = EME_DB_PREFIX . EME_EVENTS_TBNAME;
$events_cf_table = EME_DB_PREFIX . EME_EVENTS_CF_TBNAME;
$recurrence_table = EME_DB_PREFIX . EME_RECURRENCE_TBNAME;
if ( $eme_number < 1 ) {
$eme_number = 1;
}
$eme_date_obj = new emeExpressiveDate( 'now', EME_TIMEZONE );
switch ( $eme_period ) {
case 'day':
$eme_date_obj->minusDays( $eme_number );
break;
case 'week':
$eme_date_obj->minusWeeks( $eme_number );
break;
default:
$eme_date_obj->minusMonths( $eme_number );
break;
}
$end_datetime = $eme_date_obj->getDateTime();
$end_date = $eme_date_obj->getDate();
$wpdb->query( $wpdb->prepare( "DELETE FROM $bookings_table where event_id in (SELECT event_id from $events_table where event_end<%s)", $end_datetime ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( $wpdb->prepare( "DELETE FROM $events_cf_table where event_id in (SELECT event_id from $events_table where event_end<%s)", $end_datetime ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( $wpdb->prepare( "DELETE FROM $attendances_table where type='event' AND related_id in (SELECT event_id from $events_table where event_end<%s)", $end_datetime ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( $wpdb->prepare( "DELETE FROM $events_table where event_end<%s", $end_datetime ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( $wpdb->prepare( "DELETE FROM $recurrence_table where recurrence_freq <> 'specific' AND recurrence_end_date<%s", $end_date ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}
function eme_cleanup_all_event_related_data( $other_data ) {
global $wpdb;
$tables = [ EME_EVENTS_TBNAME, EME_BOOKINGS_TBNAME, EME_LOCATIONS_TBNAME, EME_RECURRENCE_TBNAME, EME_ANSWERS_TBNAME, EME_PAYMENTS_TBNAME, EME_PEOPLE_TBNAME, EME_GROUPS_TBNAME, EME_MEMBERS_TBNAME, EME_MEMBERSHIPS_TBNAME, EME_ATTENDANCES_TBNAME, EME_TODOS_TBNAME, EME_TASKS_TBNAME, EME_TASK_SIGNUPS_TBNAME ];
if ( $other_data ) {
$tables2 = [ EME_CATEGORIES_TBNAME, EME_HOLIDAYS_TBNAME, EME_TEMPLATES_TBNAME, EME_FORMFIELDS_TBNAME, EME_COUNTRIES_TBNAME, EME_STATES_TBNAME, EME_DISCOUNTS_TBNAME, EME_DISCOUNTGROUPS_TBNAME, EME_MQUEUE_TBNAME, EME_MAILINGS_TBNAME ];
$tables = array_merge( $tables, $tables2 );
}
foreach ( $tables as $table ) {
$wpdb->query( 'DELETE FROM ' . esc_sql( EME_DB_PREFIX . $table ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- table name is a safe variable
}
}
function eme_cleanup_page() {
$message = '';
if ( current_user_can( get_option( 'eme_cap_cleanup' ) ) ) {
// do the actions if required
if ( isset( $_POST['eme_admin_action'] ) ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
if ( $_POST['eme_admin_action'] == 'eme_cleanup_events' && isset( $_POST['eme_number'] ) && isset( $_POST['eme_period'] ) ) {
$eme_number = intval( $_POST['eme_number'] );
$eme_period = eme_sanitize_request( $_POST['eme_period'] );
if ( ! in_array( $eme_period, [ 'day', 'week', 'month' ] ) ) {
$eme_period = 'month';
}
if ( $eme_number > 1 ) {
eme_cleanup_events( $eme_number, $eme_period );
$message = sprintf( __( 'Cleanup done: events (and corresponding booking data) older than %d %s(s) have been removed.', 'events-made-easy' ), $eme_number, $eme_period );
}
} elseif ( $_POST['eme_admin_action'] == 'eme_cleanup_unpaid' ) {
$eme_number = 0;
if ( isset( $_POST['eme_number'] ) ) {
$eme_number = intval( $_POST['eme_number'] );
}
if ( $eme_number >= 5 ) {
eme_cleanup_unpaid( $eme_number );
$message = sprintf( __( 'Cleanup done: unpaid pending bookings older than %d minutes have been removed.', 'events-made-easy' ), $eme_number );
}
} elseif ( $_POST['eme_admin_action'] == 'eme_cleanup_unconfirmed' ) {
$eme_number = 0;
if ( isset( $_POST['eme_number'] ) ) {
$eme_number = intval( $_POST['eme_number'] );
}
if ( $eme_number >= 5 ) {
eme_cleanup_unconfirmed( $eme_number );
$message = sprintf( __( 'Cleanup done: unconfirmed bookings older than %d minutes have been removed.', 'events-made-easy' ), $eme_number );
}
} elseif ( $_POST['eme_admin_action'] == 'eme_cleanup_trashed_people' ) {
$eme_number = intval( $_POST['eme_number'] );
$eme_period = eme_sanitize_request( $_POST['eme_period'] );
if ( ! in_array( $eme_period, [ 'day', 'week', 'month' ] ) ) {
$eme_period = 'month';
}
if ( $eme_number > 0 ) {
$count = eme_cleanup_trashed_people( $eme_number, $eme_period );
$message = sprintf( __( 'Cleanup done: %d people removed from trash.', 'events-made-easy' ), $count );
}
} elseif ( $_POST['eme_admin_action'] == 'eme_cleanup_trashed_bookings' ) {
$eme_number = intval( $_POST['eme_number'] );
$eme_period = eme_sanitize_request( $_POST['eme_period'] );
if ( ! in_array( $eme_period, [ 'day', 'week', 'month' ] ) ) {
$eme_period = 'month';
}
if ( $eme_number > 0 ) {
$count = eme_cleanup_trashed_bookings( $eme_number, $eme_period );
$message = sprintf( __( 'Cleanup done: %d bookings removed from trash.', 'events-made-easy' ), $count );
}
} elseif ( $_POST['eme_admin_action'] == 'eme_cleanup_people_preview' ) {
$preview_people = eme_get_cleanup_people();
$count = count( $preview_people );
if ( $count === 0 ) {
$message = __( 'No people found that would be moved to the trash bin.', 'events-made-easy' );
} else {
eme_cleanup_form( '', $preview_people );
return;
}
} elseif ( $_POST['eme_admin_action'] == 'eme_cleanup_people' ) {
$count = eme_cleanup_people();
$message = sprintf( __( 'Cleanup done: %d people who are no longer referenced in bookings, memberships or groups are now trashed.', 'events-made-easy' ), $count );
} elseif ( $_POST['eme_admin_action'] == 'eme_empty_queue' ) {
eme_cancel_all_queued();
$message = __( 'The mail queue has been cleared.', 'events-made-easy' );
} elseif ( $_POST['eme_admin_action'] == 'eme_cleanup_all_event_related_data' ) {
$other_data = 0;
if ( isset( $_POST['other_data'] ) ) {
$other_data = 1;
}
eme_cleanup_all_event_related_data( $other_data );
$message = __( 'Cleanup done: all data concerning events, locations and bookings have been removed.', 'events-made-easy' );
}
}
}
eme_cleanup_form( $message );
}
function eme_cleanup_form( $message = '', $preview_people = null ) {
$areyousure = esc_html__( 'Are you sure you want to do this?', 'events-made-easy' );
?>
<div class="wrap">
<?php if ( $message != '' ) { ?>
<h1><?php esc_html_e( 'Action info', 'events-made-easy' ); ?></h1>
<div id='message' class='updated eme-message-admin'>
<p><?php echo wp_kses_post( $message ); ?></p>
</div>
<?php } ?>
<?php if ( ! empty( $preview_people ) ) { ?>
<h1><?php esc_html_e( 'Preview: People to be trashed', 'events-made-easy' ); ?></h1>
<div id='message' class='updated eme-message-admin'>
<p><?php echo esc_html( sprintf( __( 'The following %d people are no longer referenced in any bookings, memberships or groups and will be moved to the trash bin:', 'events-made-easy' ), count( $preview_people ) ) ); ?></p>
<table class="widefat striped" style="margin-bottom:1em;">
<thead><tr>
<th><?php esc_html_e( 'ID', 'events-made-easy' ); ?></th>
<th><?php esc_html_e( 'First name', 'events-made-easy' ); ?></th>
<th><?php esc_html_e( 'Last name', 'events-made-easy' ); ?></th>
<th><?php esc_html_e( 'Email', 'events-made-easy' ); ?></th>
<th><?php esc_html_e( 'Created on', 'events-made-easy' ); ?></th>
<th><?php esc_html_e( 'Modified on', 'events-made-easy' ); ?></th>
</tr></thead>
<tbody>
<?php foreach ( $preview_people as $person ) {
$edit_url = esc_url( admin_url( 'admin.php?page=eme-people&eme_admin_action=edit_person&person_id=' . $person['person_id'] ) );
$edit_title = esc_attr__( 'Edit person', 'events-made-easy' );
?>
<tr>
<?php foreach ( [ 'person_id', 'firstname', 'lastname', 'email' ] as $field ) { ?>
<td><a href="<?php echo $edit_url; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped with esc_url() at assignment ?>" title="<?php echo $edit_title; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already escaped with esc_attr__() at assignment ?>"><?php echo esc_html( $person[ $field ] ); ?></a></td>
<?php } ?>
<td> <?php echo esc_html( $person['creation_date'] ); ?></td>
<td> <?php echo esc_html( $person['modif_date'] ); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<form action="" method="post">
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='page' value='eme-cleanup'>
<input type='hidden' name='eme_admin_action' value='eme_cleanup_people'>
<input type="submit" value="<?php esc_attr_e( 'Confirm: Move all to trash', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction_confirm" class="button-primary action" onclick="return confirm('<?php echo esc_attr( $areyousure ); ?>');">
<a href="<?php echo esc_url( admin_url( 'admin.php?page=eme-cleanup' ) ); ?>" class="button"><?php esc_html_e( 'Cancel', 'events-made-easy' ); ?></a>
</form>
</div>
<?php } ?>
<h1><?php esc_html_e( 'Cleanup actions', 'events-made-easy' ); ?></h1>
<form action="" method="post">
<label for="eme_number"><?php esc_html_e( 'Remove events older than', 'events-made-easy' ); ?></label>
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='page' value='eme-cleanup'>
<input type='hidden' name='eme_admin_action' value='eme_cleanup_events'>
<input type="number" id="eme_number" name="eme_number" size="3" maxlength="3" min="1" max="999" step="1" >
<select name="eme_period">
<option value="day" selected="selected"><?php esc_html_e( 'Day(s)', 'events-made-easy' ); ?></option>
<option value="week"><?php esc_html_e( 'Week(s)', 'events-made-easy' ); ?></option>
<option value="month"><?php esc_html_e( 'Month(s)', 'events-made-easy' ); ?></option>
</select>
<input type="submit" value="<?php esc_attr_e( 'Apply', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction" class="button-primary action" onclick="return confirm('<?php echo esc_attr( $areyousure ); ?>');">
</form>
<br><br>
<form action="" method="post">
<label for="eme_number"><?php esc_html_e( 'Remove unpaid pending bookings older than', 'events-made-easy' ); ?></label>
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='page' value='eme-cleanup'>
<input type='hidden' name='eme_admin_action' value='eme_cleanup_unpaid'>
<input type="number" id="eme_number" name="eme_number" size="6" maxlength="6" min="5" max="999999" step="1">
<?php esc_html_e( 'minutes', 'events-made-easy' ); ?>
<input type="submit" value="<?php esc_attr_e( 'Apply', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction" class="button-primary action" onclick="return confirm('<?php echo esc_attr( $areyousure ); ?>');">
</form>
<br><br>
<form action="" method="post">
<label for="eme_number"><?php esc_html_e( 'Remove unconfirmed bookings older than', 'events-made-easy' ); ?></label>
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='page' value='eme-cleanup'>
<input type='hidden' name='eme_admin_action' value='eme_cleanup_unconfirmed'>
<input type="number" id="eme_number" name="eme_number" size="6" maxlength="6" min="5" max="999999" step="1">
<?php esc_html_e( 'minutes', 'events-made-easy' ); ?>
<input type="submit" value="<?php esc_attr_e( 'Apply', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction" class="button-primary action" onclick="return confirm('<?php echo esc_attr( $areyousure ); ?>');">
</form>
<br><br>
<form action="" method="post">
<?php esc_html_e( 'Move people who are no longer referenced in bookings, groups or memberships to the trash bin', 'events-made-easy' ); ?>
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='page' value='eme-cleanup'>
<input type='hidden' name='eme_admin_action' value='eme_cleanup_people_preview'>
<input type="submit" value="<?php esc_attr_e( 'Preview', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction" class="button-primary action">
<br><?php esc_html_e( 'Tip: If you want to avoid certain people from being trashed through automatic cleanup, put them in a group.', 'events-made-easy' ); ?>
</form>
<br><br>
<form action="" method="post">
<label for="eme_number"><?php esc_html_e( 'Remove people in thrash older than', 'events-made-easy' ); ?></label>
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='page' value='eme-cleanup'>
<input type='hidden' name='eme_admin_action' value='eme_cleanup_trashed_people'>
<input type="number" id="eme_number" name="eme_number" size="3" maxlength="3" min="1" max="999" step="1" >
<select name="eme_period">
<option value="day" selected="selected"><?php esc_html_e( 'Day(s)', 'events-made-easy' ); ?></option>
<option value="week"><?php esc_html_e( 'Week(s)', 'events-made-easy' ); ?></option>
<option value="month"><?php esc_html_e( 'Month(s)', 'events-made-easy' ); ?></option>
</select>
<input type="submit" value="<?php esc_attr_e( 'Apply', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction" class="button-primary action" onclick="return confirm('<?php echo esc_attr( $areyousure ); ?>');">
</form>
<br><br>
<form action="" method="post">
<label for="eme_number"><?php esc_html_e( 'Remove bookings in thrash older than', 'events-made-easy' ); ?></label>
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='page' value='eme-cleanup'>
<input type='hidden' name='eme_admin_action' value='eme_cleanup_trashed_bookings'>
<input type="number" id="eme_number" name="eme_number" size="3" maxlength="3" min="1" max="999" step="1" >
<select name="eme_period">
<option value="day" selected="selected"><?php esc_html_e( 'Day(s)', 'events-made-easy' ); ?></option>
<option value="week"><?php esc_html_e( 'Week(s)', 'events-made-easy' ); ?></option>
<option value="month"><?php esc_html_e( 'Month(s)', 'events-made-easy' ); ?></option>
</select>
<input type="submit" value="<?php esc_attr_e( 'Apply', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction" class="button-primary action" onclick="return confirm('<?php echo esc_attr( $areyousure ); ?>');">
</form>
<br><br>
<form action="" method="post">
<?php esc_html_e( 'Remove all data concerning events, locations, memberships, people and bookings', 'events-made-easy' ); ?>
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='page' value='eme-cleanup'>
<input type='hidden' name='eme_admin_action' value='eme_cleanup_all_event_related_data'>
<input id="other_data" type="checkbox" value="1" name="other_data"> <?php esc_html_e( 'Also delete defined categories, templates, holidays, discounts, states, countries and custom form fields', 'events-made-easy' ); ?><br>
<input type="submit" value="<?php esc_attr_e( 'Apply', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction" class="button-primary action" onclick="return confirm('<?php echo esc_attr( $areyousure ); ?>');">
</form>
<br><br>
<?php
$eme_queued_count = eme_get_queued_count();
if ( $eme_queued_count > 1 ) {
printf( esc_html__( 'There are %d messages in the mail queue.', 'events-made-easy' ), intval( $eme_queued_count ) );
} elseif ( $eme_queued_count ) {
printf( esc_html__( 'There is 1 message in the mail queue.', 'events-made-easy' ), intval( $eme_queued_count ) );
} else {
esc_html_e( 'There are no messages in the mail queue.', 'events-made-easy' );
}
if ( $eme_queued_count ) {
?>
<form action="" method="post">
<?php esc_html_e( 'Empty the mail queue', 'events-made-easy' ); ?>
<?php echo wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_nonce_field() returns safe HTML ?>
<input type='hidden' name='eme_admin_action' value='eme_empty_queue'>
<input type="submit" value="<?php esc_attr_e( 'Apply', 'events-made-easy' ); ?>" name="doaction" id="eme_doaction" class="button-primary action" onclick="return confirm('<?php echo esc_attr( $areyousure ); ?>');">
</form>
<br><br>
<?php
}
?>
</div>
<?php
}
?>