Last active
August 26, 2016 11:15
-
-
Save Christian-Roth/df2a67b7886e05ba80b02adf8a9e5760 to your computer and use it in GitHub Desktop.
Functions to add a custom WP cron
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
function your_function(){ | |
// **** Add your function here **** | |
} | |
add_action( 'your_cron_action', 'your_function' ); | |
// Init Cron Job | |
function init_custom_cron() { | |
if( !wp_next_scheduled( 'your_cron_action' ) ){ | |
wp_schedule_event( time(), '20min', 'your_cron_action' ); | |
} | |
} | |
add_action('init', 'init_custom_cron'); | |
// Add custom schedule for Cron Jobs | |
function custom_cron_schedules($schedules){ | |
if( !isset($schedules['20min']) ){ | |
$schedules['20min'] = array( | |
'interval' => 20*60, | |
'display' => __('Once every 20 minutes') | |
); | |
} | |
return $schedules; | |
} | |
add_filter('cron_schedules','custom_cron_schedules'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment