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

WordPress Trac noreply at wordpress.org
Sat Feb 13 05:23:24 UTC 2016

#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:  3.0
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:

Comment (by jrf):

 Updated the patch based on feedback from the bug scrub Slack chat. /cc
 @chriscct7 @stevenkword

 > I think the patch should also throw a `_doing_it_wrong()` specifically
 where the plugin authors are doing it wrong

 There is already a `_deprecated_argument()` in place in the
 `wp_clear_scheduled_hook()` function which was added when the function
 signature was changed.

 I could add `_doing_it_wrong()` for all instances where the cron arguments
 are not passed in as an array. That would effectively mean adding it in
 six (!) places in the cron file.
 See the alternative patch (2-b).

 Also note: `_doing_it_wrong()` expects the WP version to be the version in
 which the message was added (4.5 (?)), however, the actual change in the
 function signature occurred in WP 2.1.0 as far as I can see, so IMHO it
 would make more sense to have 2.1.0 as the version number in the
 `_doing_it_wrong()` call.

 > also it'd be nice to get the related ticket (` *another* (ancient)
 bug`), so that ticket can also be updated.

 AFAIK this was never reported before and there is no trac ticket for this
 bug. I discovered it while working on this issue.

 As the last time the version nr of the cron array was changed - and
 therefore the last time the `_upgrade_cron_array()` function was called -,
 was in 2006, I doubt you will find any reported issues.

 The bug, however, becomes relevant for this patch as the cron array
 version nr will be upped and therefore `_upgrade_cron_array()` will now
 once again be called (once for each install).

 Aside from the error notice, the net effect of this bug is cron events
 disappearing or no longer functioning correctly as the cron array would be
 mangled after being run through the upgrade function.

 In more detail:
 The cron array is a nested array with:
 (array) timestamps -> (array) hooks -> (array) events -> (array)
 arguments, where events are saved with as a key the md5-ed serialization
 of the event arguments and as a value the actual event arguments.

 The `_upgrade_cron_array()` function however treated the events array as
 if it were the arguments array. So if there were two events on a hook,
 there would only be one event after the upgrade routine and the arguments
 of that one event would be the previous two events.

 > and the new `_cron_cast_to_array_helper` needs a docbloc

 Done - see updated patch.

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

More information about the wp-trac mailing list