[wp-trac] [WordPress Trac] #35491: Add a function to check whether a hook is scheduled
WordPress Trac
noreply at wordpress.org
Sun Jan 17 16:55:48 UTC 2016
#35491: Add a function to check whether a hook is scheduled
--------------------------------------+------------------
Reporter: dlh | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 4.5
Component: Cron API | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+------------------
Comment (by swissspidy):
> If I scheduled `'my_hook'` twice, one with `'foo'` for `$args` and one
with `false`, and the `'foo'` event was scheduled to occur next, wouldn't
`wp_next_scheduled( 'my_hook', false )` return the wrong timestamp?
`$args` is always an array containing the parameters passed to the
callback (using `call_user_func_array('wp_reschedule_event',
$new_args);`). Anything else isn't supported and leads to errors. That's
why `wp_next_scheduled( 'my_hook', false )` would work, without breaking
BC.
> That aside, to me, passing `false` to `wp_next_scheduled()` adds
ambiguity. How can I tell whether the author wants to know whether the
hook is scheduled at all or whether it was scheduled with `$args = false`?
My idea was to DRY things up because both functions are so similar. I
agree that it may be confusing, but that can be prevented with
documentation.
> I could see how returning the timestamp would help in some cases. As you
noted, though, that makes it tough to distinguish between
`wp_next_scheduled()`. I could also see a developer thinking the function
returned all the hook's timestamps, not just the next one. So I still lean
towards returning `bool`, but I'm open to other ideas.
`wp_next_scheduled()` returns the next scheduled timestamp, that's what
the function name implies.
With my patch, `wp_is_scheduled_hook( $hook )` could basically be a
wrapper for `wp_next_scheduled( $hook, false )`, if that helps prevent
confusion.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35491#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list