Site icon Hip-Hop Website Design and Development

Scheduled events disappear from events queue

I’m having an issue where events that I have scheduled work for a while then just stop. After looking at the event queue I see that the scheduled events are no longer in the queue.

If I deactivate then reactivate the plugin the schedule is back and works for a period of time.

I don’t know if WordPress has something that removes events if they timeout or anything like that.

Here is my code:

register_activation_hook(__FILE__, 'k2_section_featured_ads_setup');
function k2_section_featured_ads_setup() {
    wp_schedule_event('1395871200', 'minutely', 'k2_section_featured_ads_hook');
}

register_deactivation_hook(__FILE__, 'k2_section_featured_ads_deactivation');
function k2_section_featured_ads_deactivation() {

    $featured_next = wp_next_scheduled('k2_section_featured_ads_hook');
    wp_unschedule_event($featured_next, 'k2_section_featured_ads_hook');
}

add_action('k2_section_featured_ads_hook', 'k2_section_featured_ads_check_time');

function k2_section_featured_ads_check_time() {
    // function here
}

Here is the filter for my extra cron schedules

function k2_cron_add_schedules( $schedules ) {
    $schedules['quarterday'] = array(
        'interval' => 14400,
        'display' => __('Once every 4 hours')
    );
    $schedules['minutely'] = array(
        'interval' => 60,
        'display' => __('Once every 1 minute')
    );
    return $schedules;
}
add_filter('cron_schedules', 'k2_cron_add_schedules');