tools/wordpress-cron-job-generator
WordPress Cron Job Generator
Generate WordPress cron job code. Cron job is a scheduled task that runs on a specific interval. You can use this tool to generate cron job code for your WordPress plugin.
snippet.php
function wp_skills_my_custom_cron_job() {
// Your code here.
}
add_action( 'my_custom_cron_job', 'wp_skills_my_custom_cron_job' );
/**
* Schedules the cron event if it is not scheduled already.
*
* @return void
*/
function wp_skills_register_my_custom_cron_job(): void {
if ( ! wp_next_scheduled( 'my_custom_cron_job' ) ) {
wp_schedule_event( time(), 'daily', 'my_custom_cron_job' );
}
}
// 'init' rather than 'wp': 'wp' only fires on front-end page loads, so an event
// scheduled there is never created by an admin-only or WP-CLI request.
add_action( 'init', 'wp_skills_register_my_custom_cron_job' );