Ticket #5063 (new defect)

Opened 1 year ago

Last modified 1 year ago

Potential type mismatch in post cron hooks

Reported by: tellyworth Assigned to: anonymous
Priority: normal Milestone: 2.9
Component: General Version:
Severity: normal Keywords:
Cc:

Description

The wp cron functions are very picky about argument types. For example, if I do this:

$post_id = '123';
wp_schedule_single_event($time, 'foo', array($post_id));
wp_clear_scheduled_hook('foo', (int)$post_id);

..the hook won't get cleared as expected, because the type of the post_id argument doesn't match (string vs int) even though its value is the same. That's an easy mistake to make: in wp-includes/post.php, post ID's are passed around that are variously strings or ints at different places in the code. I'm not aware of any code that currently breaks, but it's a bug waiting to happen.

To add to the confusion, Wordpress and Wordpress-mu store cron hooks with different post ID types: Wordpress uses a string, Wordpress-mu uses an int.

I'm not sure what the solution is, but it's probably worth noting somewhere.

Change History

09/24/07 15:22:29 changed by Otto42

The specific-ness of the args requirement can indeed be somewhat annoying at times.

Suggest making a function that will allow somebody to clear a hook without knowing the args at all. Given only the hook name, remove all scheduled references to it, period. It would help with cleanup functions, such as those when deactivating a plugin.