Skip to content

Instantly share code, notes, and snippets.

@WPsites
Created September 6, 2012 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WPsites/3656189 to your computer and use it in GitHub Desktop.
Save WPsites/3656189 to your computer and use it in GitHub Desktop.
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