Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#10468 closed defect (bug) (fixed)

wp_clear_scheduled_hook does not work when including an $args parameter

Reported by: johnbillion's profile johnbillion Owned by: westi's profile westi
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.8.1
Component: Cron API Keywords: has-patch needs-testing
Focuses: Cc:


The value for $args that gets passed from wp_clear_scheduled_hook to wp_unschedule_event gets changed and therefore nothing will get unscheduled as no jobs will have that argument.

The problem is that the value of the $args parameter is detected using array_slice( func_get_args(), 1 ) and this actually places the value of $args inside an array with one element with the value of $args.

The value of $args passed by wp_clear_scheduled_hook('my_hook','hello') to wp_unschedule_event will then look like this:

    [0] => hello

instead of this:


The function wp_clear_scheduled_hook is used with the $args parameter in core in three places:

  1. Inside wp_delete_post to clear any job which might try to publish a future post which has been deleted.
  2. Inside check_and_publish_future_post to clear any job which might try to republish a future post which has been published.
  3. Inside _transition_post_status to clear any job which might try to publish a future post which has gone back to draft status.

So according to this bug, these three areas cannot be functioning as expected, as they pass a value in the $args parameter to wp_clear_scheduled_hook.

Attachments (1)

10468.patch (683 bytes) - added by johnbillion 14 years ago.

Download all attachments as: .zip

Change History (8)

14 years ago

#1 @johnbillion
14 years ago

  • Keywords has-patch needs-testing added


wp_clear_scheduled_hook can currently take multiple values for $args. My patch removes this functionality, but breaking backwards compatibility won't be an issue as this never worked anyway.

#2 @scribu
14 years ago

  • Cc scribu@… added
  • Keywords cron wp-cron wp_clear_scheduled_hook removed
  • Milestone changed from Unassigned to 2.9

#3 @westi
14 years ago

  • Owner set to westi
  • Status changed from new to reviewing

#4 @westi
14 years ago

Makes perfect sense for this to take an $args array like the rest of them.

We may break some plugins though that have made it work for single arguments.

I wonder if we should put in some backwards compatibility code for them.

#5 @scribu
14 years ago

  • Keywords changed from has-patch, needs-testing to has-patch needs-testing

Indeed, if a plugin did something like

wp_clear_scheduled_hook('my_hook', 'first_arg', 'second_arg');

it would have worked correctly.

#6 @ryan
14 years ago

  • Milestone changed from 2.9 to 3.0

#7 @westi
14 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

(In [12462]) Fix wp_clear_scheduled_hook() so that it function prototype matches the other cron functions.
Include backwards compatibility code so that plugins that used the old way still work.
Fixes #10468.

Note: See TracTickets for help on using tickets.