Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
WP-cron debug test - Add a WordPress cron event to email server variables every 2 minutes
<?php
function my_additional_schedules($schedules) {
// interval in seconds
$schedules['every2min'] = array('interval' => 2*60, 'display' => 'Every two minutes');
return $schedules;
}
add_filter('cron_schedules', 'my_additional_schedules');
// schedule the wp_cron_testing
if( !wp_next_scheduled( 'wp_cron_testing' ) ) {
wp_schedule_event( time(), 'every2min', 'wp_cron_testing' );
}
add_action( 'wp_cron_testing', 'the_wp_cron_test' );
function the_wp_cron_test() {
//mail my email with some debug info
$to = 'your@own-email.co.uk';
$subject = 'the_wp_cron_test';
$message = "Debug info below. \n\n";
foreach ($_SERVER as $name => $value){
$message .= "${name} : ${value} \n";
}
wp_mail( $to, $subject, $message);
}
//to clear the cron event from the site use the bellow line of code
//wp_clear_scheduled_hook('wp_cron_testing');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment