"Delete expired events" – any way to decrease from 24 hours?

WordPress Event Management, Calendars & Registration Forums General Question "Delete expired events" – any way to decrease from 24 hours?

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 5 years, 4 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35641

    Hello,

    Is there any way to set a shorter time for events to auto-delete after they’ve expired – say, 2 hours, instead of 24 hours?

    (Sorry if this is documented somewhere, but I couldn’t find it.)

    Shaun Woods
    #35648

    Hi Shaun,

    The scheduled event for deleting expired events runs daily:

    wp_schedule_event(time()+60, 'daily', 'eventorganiser_delete_expired');
    

    But you can change that to hourly (see https://codex.wordpress.org/Function_Reference/wp_schedule_event) – note, you’ll only want to run that code once. Most examples in the official documentation use wp_next_scheduled() check to if its already scheduled. In your case you’ll probably want to do:

    if ( wp_next_scheduled('eventorganiser_delete_expired') > time() + 60) {
        wp_schedule_event(time()+10, 'hourly', 'eventorganiser_delete_expired');
    }
    

    probably on the init hook would suffice.

    Secondly, the eventorganiser_delete_expired hook will trigger a function that deletes events that ended over 24 hours ago. You can adjust that to 2 hours as so:

     add_filter( 'eventorganiser_events_expire_time', function() {
      return 2 * 60 * 60;
     });
    

    In this way, the script runs hourly, and deletes any events older than 2 hours. (Please note, I’ve not tested the wp_schedule_event part.).

    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.