otto at ottodestruct.com
Mon Sep 24 15:40:48 GMT 2007
No, you got the two functions confused.
wp_unschedule_event removes one event from the schedule. Whether that
event is recurring or not, it will remove it. If it is recurring, it
will not be recurring any more.
wp_clear_scheduled_hook actually iterates through wp_unschedule_event.
Given a hook and args, it will unschedule everything that matches
So, wp_clear_scheduled_hook is what to use if you accidentally
schedule something a whole lot of times.
Read through wp-includes/cron.php. It's pretty straightforward for most of it.
On 9/23/07, Jacob Santos <dragonwing at dragonu.net> wrote:
> From what I've read of the WP Cron code, you want to use
> wp_clear_scheduled_hook unless you want to remove all instances of the
> scheduled event. wp_unschedule_event is good if you screw up and
> constantly add the same event over and over again. It is better to use
> wp_unschedule_event, than iterating over wp_clear_scheduled_hook. At
> least in my opinion with the very little I've used of it.
> I would agree that it would be useful to know that you have to create a
> hook before using some of the functions. The only way I was finally able
> to get my plugin to work was finding some awesome guy online that wrote
> about the troubles and journey he had with trying to schedule an event.
> Jacob Santos
> Otto wrote:
> > Clearly these need to be documented, since everybody gets them wrong...
> > If you schedule any event, even a recurring one, wp_unschedule_event
> > will get rid of it. Completely. Even recurrances.
> > If you schedule the same event twice, wp_clear_scheduled_hook will get
> > rid of both of them. It's also somewhat simpler to use (no need to get
> > timestamp of next scheduled event).
> > This is because a recurring event only actually exists once: The next
> > time. When it runs, it's rescheduled for the next event just before it
> > actually executes. That's how recurring events work.
> > In short, you probably always want to use wp_clear_scheduled_hook to
> > get rid of an event. The only reason you ever want to use
> > wp_unschedule_event is if you have a complex set of events and want to
> > be certain that you get rid of get the exact one you want to get rid
> > of.
> > On 9/22/07, Matt <speedboxer at gmail.com> wrote:
> >> On 9/22/07, Omry Yadan <omry at yadan.net> wrote:
> >>> without know ANYTHING about the API, I am guessing that you need to use
> >>> wp_unschedule_event, and that
> >>> wp_clear_scheduled_hook is used internally to notify listeners of
> >>> unschedule events.
> >> I tried it out by checking if wp_next_scheduled_event was the cron. It turns
> >> out that you should you wp_clear_scheduled_hook if you want to completely
> >> get rid of a recursive cron. I think wp_unschedule_event just unschedules
> >> the next time it's supposed to run, but it will continue to run after that
> >> one that's been "skipped".
> >> --
> >> Matt (speedboxer at gmail.com)
> >> http://mattsblog.ca/ | http://livemp.net/
> >> _______________________________________________
> >> wp-hackers mailing list
> >> wp-hackers at lists.automattic.com
> >> http://lists.automattic.com/mailman/listinfo/wp-hackers
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers