Action hooking support added in the reschedule tool.
Updated code on GitHub
I’ve pushed the modified and empowered code to GitHub and added, under the same API, the power to reschedule cron jobs and re-hook into actions.
I’m not going to duplicate the README file contents as that comes with the repository.
A real world example code
I can pull a generalized code example from my daily work; I need to keep a post cache updated if a certain cache plugin is not in place or not active and, in the meanwhile, create the cache for those posts that are added to the database not using the WordPress default Admin UI but with an import script.
The first task I cover with:
tad_reschedule( array('Cache_Builder', 'rebuild_post_cache' ) ) ->each( 'post_updated' ) ->until( !function_exists( 'super_cache_init' ) ) ->with_args( 3 ) // $post_id, $post_after, $post_before ->priority( 999 ); // let's go late
while the second task I handle like
$batch_size = 100; tad_reschedule( 'my_cache_rebuild' ) ->each( 60 ) ->until( array('Cache_Builder', 'has_uncached_posts') ) ->with_args( array($batch_size) );
In plain terms
super_cache_initfunction is not defined (the super caching plugin is not installed or activated) on each
post_updatedaction run the
Cache_Builder::rebuild_post_cachemethod passing it 3 args.
Until there are not cached posts schedule a 60 seconds cron job to do the
my_cache_rebuildaction passing it the batch size.