action-scheduler
action-scheduler copied to clipboard
Feature request: 'ready' hook
Action Scheduler documentation is telling me to hook to WordPress's init
to use its functions.
If I do this and then disable Action Scheduler plugin, there will be errors when I call the missing functions.
For now I'll use
if( ! function_exists( 'as_next_scheduled_action' ) ) {
return;
}
but a neater way would be for Action Scheduler to fire its own init, then I can hook to that and be sure the functions will exist.
So something like this inside Action Scheduler:
add_action( 'init', function() { do_action( 'actionshecduler_init' ); }, 1 );
I searched the code for all do_action
s and didn't find any that suited this idea.
It seems this would be implemented in ActionScheduler::init()
with an add_action
in the first part of the conditional calling the function with the do_action
, and a direct call to that new, one line function in the second.
That sounds like a very reasonable suggestion.
Until then, do also note that as an alternative to checking ! function_exists( 'as_next_scheduled_action' )
you could instead do things this way within your callback:
if ( ! ActionScheduler::is_initialized() ) {
return;
}
Both work, this is just the more specific test.