0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Simple Example of How to Use WordPress Cron

I have been meaning to get into WordPress’ wp-cron functionality, and this looks like a good way to get started with it. This code snippet uses wp-cron to schedule an automatic email that will be sent every hour.

// send automatic scheduled email
if (!wp_next_scheduled('my_task_hook')) {
	wp_schedule_event(time(), 'hourly', 'my_task_hook');
}
add_action('my_task_hook', 'my_task_function'); 

function my_task_function() {
	wp_mail('you@yoursite.com', 'Automatic email', 'Hello, this is an automatically scheduled email from WordPress.');
}

Of course, this is meant only as an example. The key here is to schedule and event and then hook into it with some specific function.

Source: slaven.net (404 link removed 2013/02/04)




0