[wp-testers] wp_schedule_single_event() acting funny

Otto otto at ottodestruct.com
Mon Jan 5 14:47:21 GMT 2009


If you put your wp_schedule_single_event in the main body like that,
then you're scheduling a new event on every single page load, because
the plugin is included on every WordPress page load.

This includes the loads of the cron job itself, which will fire the
plugin, causing another scheduling to occur, and so on.

Short version: Never, ever, schedule something from the main body of a
plugin. Stick it in a function, then fire that function only when you
need to actually schedule the event.


On Fri, Jan 2, 2009 at 3:56 PM, scribu <scribu at gmail.com> wrote:
> Hello, new to this list.
>
> I was working on a plugin using wp_cron and I noticed some strange
> behaviour when using wp_schedule_single_event().
>
> I've written this test plugin: http://wordpress.pastebin.ca/1298571
>
> If I set it to a time in the past, like
>
>  wp_schedule_single_event(time(), CRON_HOOK);
>
> it fires twice on every page load.
>
> If I set it in the future, say
>
>  wp_schedule_single_event(time()+15, CRON_HOOK);
>
> it just fires once, even if I clear the hook first.
>
> Any ideas?
>
> I'm using WP 2.7.1-alpha-10188 on localhost (Ubuntu 8.10 + LAMP).
>
> --
> http://scribu.net
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers
>


More information about the wp-testers mailing list