Showing posts with label cron job. Show all posts
Showing posts with label cron job. Show all posts

Monday, March 30, 2020

Implementing cron job in WordPress

function myplugin_activate()
{

    if (!wp_next_scheduled('pt_my_task_hook')) {
        //wp_schedule_event(time(), 'hourly', 'pt_my_task_hook');
        //wp_schedule_event(time(), 'every_three_minutes', 'pt_my_task_hook');
        wp_schedule_event(strtotime('22:00:00'), 'daily', 'pt_my_task_hook');
    }
}

register_activation_hook(__FILE__, 'myplugin_activate');

/* Deactivate Hook */
register_deactivation_hook(__FILE__, 'my_deactivation');
function my_deactivation()
{
    wp_clear_scheduled_hook('pt_my_task_hook');
}

add_action('pt_my_task_hook2', 'user_email_task_function');
function user_email_task_function()
{
    // code to implement
}