[wp-hackers] Pseudo-Cron
Martin at Cleaver.org
Martin at Cleaver.org
Fri Sep 21 16:56:31 GMT 2007
Instead of
wp_schedule_event(time(), 'hourly', 'my_hourly_event');
A helpful syntax would be:
wp_schedule_event(0, 'hourly', 'my_hourly_event');
If you use 0 you end up with a stuck event in the table.
I know this because I built a dashboard viewer for cron entries. It'd be
neat if it could become bundled and turned into a cron entry editor.
wp-cron-dashboard-display.php
<?php
// By Martin Cleaver, Blended Perspectives Inc.
// Based on
http://blog.slaven.net.au/archives/2007/02/01/timing-is-everything-scheduling-in-wordpress/
//// MENUs
function wp_cron_add_pages($s) {
add_submenu_page('index.php', 'wp-cron', 'WP-Cron', 1, __FILE__,
'wp_cron_menu');
return $s;
}
add_action('admin_menu', 'wp_cron_add_pages');
function wp_cron_menu() {
$format = "%X %x";
print "<table>";
print "<tr><td>Now<td>".strftime($format,time())."</td></tr>";
print "</table>";
global $wp_filter;
print "<pre>";
print mrjc_show_cron_schedules();
print "</pre>";
}
function mrjc_show_cron_schedules() {
$timeslots = _get_cron_array();
if ( empty($timeslots) )
return $ans+"Nothing scheduled";
$ans = '';
$count = 1;
foreach ( $timeslots as $time => $tasks ) {
$ans .= "Entry #$count: Anytime after ".strftime("%c",$time)." execute
tasks:";
foreach ($tasks as $procname => $task) {
$ans .= $procname." ";
$count++;
}
$ans .= "\n";
}
return $ans;
}
?>
On 9/21/07, Jennifer Hodgdon <yahgrp at poplarware.com> wrote:
>
> Otto --
>
> It looks like (from reading the code) for the unschedule, reschedule,
> and clear functions, you need to know the exact function arguments you
> originally created the schedule with (if any). And for this function:
>
> > function wp_clear_scheduled_hook( $hook ) - Unschedules an event even
> > if you don't know when it's scheduled. This simply kills all events
> > that will trigger the given $hook. This is very useful.
>
> You actually call it with
> wp_clear_scheduled_hook( $hook, $arg1, $arg2, ... )
>
> If you leave out the arguments, or they don't match, it looks to me as
> though the schedule will not be cleared.
>
> Correct?
> Jennifer
>
>
> --
> Jennifer Hodgdon
>
> Poplar ProductivityWare * www.poplarware.com
> Web Databases/Scripts * Modeling/Analysis/Palm OS Software
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
--
Martin at Cleaver.org MSc MBA
More information about the wp-hackers
mailing list