[wp-trac] [WordPress Trac] #35491: Add a function to check whether a hook is scheduled

WordPress Trac noreply at wordpress.org
Sun Feb 28 01:14:55 UTC 2016


#35491: Add a function to check whether a hook is scheduled
--------------------------------------+-----------------------------
 Reporter:  dlh                       |       Owner:
     Type:  enhancement               |      Status:  new
 Priority:  normal                    |   Milestone:  Future Release
Component:  Cron API                  |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------

Comment (by jrf):

 @swissspidy @dlh I've been thinking about the conflict with ticket #34913.
 I believe the conflict can quite easily be avoided by adding a new
 parameter to the `wp_next_scheduled()` function to indicate whether to
 check the arguments or not, like so:

 {{{
 function wp_next_scheduled( $hook, $args = array(), $ignore_args = false )
 }}}


 The reasons why I'm suggesting this are as follows:
 1. IMHO a clear bug trumps an enhancement.
 2. As the bug from #34913 has been in WP since v3.0 without any `doing it
 wrong` notices, there is no telling how often devs '''''have''''' been
 doing it wrong without realizing. (and yes, I ran into it as cron jobs of
 deactivated plugins weren't being unscheduled.)
 3. If a `doing it wrong` had been added in WP 3.0 and the scheduling had
 been prevented from that point in time with a `return false`, then
 @swissspidy suggestion in
 [https://core.trac.wordpress.org/ticket/34913#comment:8 #34913:8] would
 have been fine. However, 14 WP versions have been released since. Suddenly
 starting to `return false` now would break backward compatibility for all
 plugins which have been doing it wrong in the mean time and AFAIK breaking
 backward compatibility is a big no-no...
 4. The current patch in #34913 solves this cleanly without breaking
 backward compatibility and with my above suggestion for this patch, both
 could be merged without conflict.

 The code for checking next scheduled events would become something like
 this and would maintain backward compatibility for both patches:

 {{{
 // Event with specific arguments:
 `if ( false === wp_next_scheduled( $hook, $args ) ) {}`

 // Event without arguments:
 `if ( false === wp_next_scheduled( $hook ) ) {}`

 // Any event independently of arguments:
 `if ( false === wp_next_scheduled( $hook, null, true ) ) {}`
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35491#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list