Created
April 4, 2019 16:02
-
-
Save wordpress-lab/76d07e0d13a9d970fd46dbcc71e26d24 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// Add a new interval of a week | |
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules | |
add_filter( 'cron_schedules', 'myprefix_add_weekly_cron_schedule' ); | |
function myprefix_add_weekly_cron_schedule( $schedules ) { | |
$schedules['weekly'] = array( | |
'interval' => 604800, // 1 week in seconds | |
'display' => __( 'Once Weekly' ), | |
); | |
return $schedules; | |
} | |
// Schedule an action if it's not already scheduled | |
if ( ! wp_next_scheduled( 'myprefix_my_cron_action' ) ) { | |
wp_schedule_event( time(), 'weekly', 'myprefix_my_cron_action' ); | |
} | |
// Hook into that action that'll fire weekly | |
add_action( 'myprefix_my_cron_action', 'myprefix_function_to_run' ); | |
function myprefix_function_to_run() { | |
// Add some code here | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment