Recurring scheduled task help

You have to schedule your event in a hook, for example in after_setup_theme or wp actions:

add_filter('cron_schedules','my_cron_definer');
function my_cron_definer($schedules){
    $schedules['twomin'] = array(
        'interval'=> 120,
        'display'=>  __('Once Every 2 Minutes')
    );
    return $schedules;
}

add_action('my_periodic_action','my_periodic_function');
function my_periodic_function(){
    mail('[email protected]','Test!', 'Test Message');
}

add_action( 'wp', 'wpse8170_setup_events' );
// or add_action( 'after_setup_theme', 'wpse8170_setup_events' );
function wpse8170_setup_events() {
    if ( !wp_next_scheduled( 'my_periodic_action' ) ) {
        wp_schedule_event(time(), 'twomin', 'my_periodic_action');
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)