Skip to content

Commit

Permalink
added move the past event in trash automatically option
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat1192 committed Nov 23, 2024
1 parent 30f8d23 commit 10aa660
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
53 changes: 53 additions & 0 deletions includes/class-wp-event-aggregator-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function __construct() {

add_action( 'init', array( $this, 'register_scheduled_import_cpt' ) );
add_action( 'init', array( $this, 'register_history_cpt' ) );
add_action( 'admin_init', array( $this, 'wpea_check_delete_pst_event_cron_status' ) );
add_action( 'wpea_delete_past_events_cron', array( $this, 'wpea_delete_past_events' ) );
add_action( 'admin_menu', array( $this, 'add_menu_pages') );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts') );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles') );
Expand Down Expand Up @@ -581,4 +583,55 @@ public function setup_success_messages(){
}
}
}

/**
* Render Delete Past Event in the wp_events post type
* @return void
*/
public function wpea_delete_past_events() {

$current_time = current_time('timestamp');
$args = array(
'post_type' => 'wp_events',
'posts_per_page' => 100,
'post_status' => 'publish',
'fields' => 'ids',
'meta_query' => array(
array(
'key' => 'end_ts',
'value' => current_time( 'timestamp' ) - ( 24 * 3600 ),
'compare' => '<',
'type' => 'NUMERIC',
),
),
);
$events = get_posts( $args );

if ( empty( $events ) ) {
return;
}

foreach ( $events as $event_id ) {
wp_trash_post( $event_id );
}
}

/**
* re-create if the past event cron is delete
*/
public function wpea_check_delete_pst_event_cron_status(){

$wpea_options = get_option( WPEA_OPTIONS );
$move_peit_ieevents = isset( $wpea_options['wpea']['move_peit'] ) ? $wpea_options['wpea']['move_peit'] : 'no';
if ( $move_peit_ieevents == 'yes' ) {
if ( !wp_next_scheduled( 'wpea_delete_past_events_cron' ) ) {
wp_schedule_event( time(), 'daily', 'wpea_delete_past_events_cron' );
}
}else{
if ( wp_next_scheduled( 'wpea_delete_past_events_cron' ) ) {
wp_clear_scheduled_hook( 'wpea_delete_past_events_cron' );
}
}

}
}
15 changes: 15 additions & 0 deletions templates/admin/wp-event-aggregator-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,21 @@
<?php
do_action( 'wpea_admin_settings_start' );
?>

<tr>
<th scope="row">
<?php _e( 'Move past events in trash', 'wp-event-aggregator' ); ?> :
</th>
<td>
<?php
$wpea_move_peit = isset( $aggregator_options['move_peit'] ) ? $aggregator_options['move_peit'] : 'no';
?>
<input type="checkbox" name="wpea[move_peit]" value="yes" <?php if ( $wpea_move_peit == 'yes' ) { echo 'checked="checked"'; } ?> />
<span class="wpea_small">
<?php _e( 'Check to move past events in the trash, Automatically move events to the trash 24 hours after their end date using wp-cron. This runs once daily in the background.', 'wp-event-aggregator' ); ?>
</span>
</td>
</tr>

<tr>
<th scope="row">
Expand Down

0 comments on commit 10aa660

Please sign in to comment.