[wp-trac] [WordPress Trac] #34913: Unscheduling cron jobs fails when original arguments were not an array.

WordPress Trac noreply at wordpress.org
Tue Dec 8 13:31:41 UTC 2015


#34913: Unscheduling cron jobs fails when original arguments were not an array.
--------------------------+-----------------------------
 Reporter:  jrf           |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Cron API      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The Cron API does not check whether the cron job arguments passed are an
 array when scheduling a cron job. This inadvertently allows for scheduling
 cron jobs with string, integer or other arguments.

 However when unscheduling the cron job using `wp_clear_scheduled_hook()`,
 the arguments are ''always'' cast to an array which leads to cron jobs
 which '''*can*''' be scheduled, but can't be '''''*un*'''''scheduled using
 `wp_clear_scheduled_hook()`.

 The `wp_clear_scheduled_hook()` does throw a `deprecated` notices when
 non-array arguments are passed in, but this will most of the time go
 unnoticed as this function is most often used in a plugin deactivation
 routine.

 The patch which I'm submitting makes sure that cron job arguments are
 always cast to an array.

 The patch is backward compatible in that it:
 * will not break the `schedule_event` filter for plugins (which are
 ''doing it wrong'') which expect their original non-array argument to test
 against.
 * will schedule all newly schedule events with array arguments
 independently of how the arguments were passed.
 * will upgrade the cron array to ensure that all arguments are arrays.

 The patch includes unit tests proving the existence of the bug and the
 fixing of it by this patch.

 As far as I can see, this bug was introduced by the changes in
 https://core.trac.wordpress.org/changeset/12462 and has been in WP since
 3.0.


 The patching of this bug also brought to my attention *another* (ancient)
 bug where in the cron option upgrade routine `_upgrade_cron_array()` the
 array structure wasn't respected properly leading to `Undefined index:
 args` notices and the inadvertent removal of cron events which were
 scheduled on the same hook for the same timestamp with different
 arguments.

 That bug has also been fixed in this patch.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34913>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list