Skip to content

Instantly share code, notes, and snippets.

@maheshwaghmare
Created June 2, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshwaghmare/3101653fcd3cb5a5a7bc8ce24c2ab572 to your computer and use it in GitHub Desktop.
Save maheshwaghmare/3101653fcd3cb5a5a7bc8ce24c2ab572 to your computer and use it in GitHub Desktop.
Add schedule event OR Cron event with wp_schedule_event(). See https://maheshwaghmare.com/doc/wordpress-cron/
<?php
/**
* Add schedule event or Cron event with wp_schedule_event()
*
* @todo Change the `prefix_` and with your own unique prefix.
*
* @since 1.0.0
*
* @return void
*/
if( ! function_exists( 'prefix_add_scheduled_event' ) ) :
function prefix_add_scheduled_event() {
// Schedule the event if it is not scheduled.
if ( ! wp_next_scheduled( 'prefix_cron_hook' ) ) {
wp_schedule_event( time(), 'every_ten_minutes', 'prefix_cron_hook' );
}
}
add_action( 'admin_init', 'prefix_add_scheduled_event' );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment