louis_simoneau — 2010-07-21T03:14:09-04:00 — #1
Notice: This is a discussion thread for comments about the SitePoint article, Scheduling Tasks in WordPress: a Plugin Developer's Guide.
What experience have you had using WordPress's scheduling API? Any tips you'd add?
mittineague — 2010-07-21T20:41:18-04:00 — #2
I recently added an "auto delete old log files" feature to one of my plugins. It took a little while to get my head around the API, but it wasn't that bad for me.
In my "activate" I added
wp_schedule_event(time(), 'daily', 'er_cron_del_hook')
In my "deactivate"
add an action
and write the function
$cron_del_limiter = get_option('er_do_cron_del');
if ( ($cron_del_limiter == 'month') || ($cron_del_limiter == 'week') )
$curr_time = time();
$cron_file_age = 31536000; // default 1 year should be way more than enough
if ($cron_del_limiter == 'month') $cron_file_age = 2678400;
if ($cron_del_limiter == 'week') $cron_file_age = 604800;
// do file delete stuff if conditional tests pass
zedge — 2010-08-17T12:52:08-04:00 — #3
Great tutorial - Thankyou.
techiekaran — 2010-08-08T10:48:37-04:00 — #4
@Mittineague: Cool hack. Will save my server resources a lot!
marcel — 2010-08-06T18:01:14-04:00 — #5
You could also hack php and use a GET post via Cpanel CRON