Advertisement
eventsmanager

Trash Past Events

Feb 14th, 2023 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2. class EM_Trash_Past_Events {
  3.    
  4.     public static function init() {
  5.        
  6.         if( !get_option('dbem_cron_trash_past_events') ){
  7.             add_option('dbem_cron_trash_past_events', 1);
  8.         }
  9.        
  10.         if( get_option('dbem_cron_trash_past_events', 1) ) {
  11.             if( !wp_next_scheduled('emp_cron_process_past_events') ){
  12.                 $result = wp_schedule_event( time(),'em_minute','emp_cron_process_past_events');
  13.             }
  14.             add_action('emp_cron_process_past_events', array('EM_Trash_Past_Events','process_past_events') );
  15.         }//END - if( get_option('dbem_cron_trash_past_events', 1) )
  16.        
  17.     }
  18.    
  19.     public static function process_past_events(){
  20.         global $wpdb;
  21.        
  22.         $EM_Events = EM_Events::get( array( 'scope' => 'past', 'status' => 1 ) );
  23.        
  24.         foreach($EM_Events as $EM_Event){
  25.             wp_trash_post($EM_Event->post_id);
  26.         }
  27.        
  28.     }
  29.    
  30. }
  31. add_action('init', array('EM_Trash_Past_Events','init'), 9);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement