Created
September 6, 2012 13:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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