[wp-hackers] wp_cron - odd behavior

Otto otto at ottodestruct.com
Sat Feb 19 21:05:19 UTC 2011


On Sat, Feb 19, 2011 at 2:13 PM, Jeremy Clarke <jer at simianuprising.com> wrote:
> This makes me think of another idea: If you are scheduling multiple similar
> events it might work better to only schedule the earlier one at first, then
> add the later events during your hooked function on the first one. I don't
> have experience with the complicated situation Otto is talking about, but it
> sounds like only scheduling one event at a time might be a workaround that
> isn't too hacky. It would also protect you from other types of bug since you
> could make sure the latter event is still valid before scheduling it when
> the first one fires.

Or change the arguments.

Events fire action hooks with arguments. Both the hook name and the
arguments make up the specific details of the event. Realistically,
you shouldn't be making identical events anyway.

Example:
If you need to fire off a function to, say, add a post, then the
function should take the post detail as inputs.


add_action('my_event_action','post_something',10,1);
function post_something($post) {
// do something with $post
}

function schedule_the_event() {
 $when = time();
 $post['title'] = 'whatever';
 $post['content'] = 'something';
 wp_schedule_single_event ( $when, 'my_event_action', $post );
}

If the args array is different for each event ($post in this case),
then you don't have have the 10 minute limitation either. So put your
changing data into that.

-Otto


More information about the wp-hackers mailing list