Skip to content

Instantly share code, notes, and snippets.

@bikedorkjon
Created October 10, 2017 16:33
Show Gist options
  • Select an option

  • Save bikedorkjon/abb6b1bdc235aff2ba2a50ef0dce60a7 to your computer and use it in GitHub Desktop.

Select an option

Save bikedorkjon/abb6b1bdc235aff2ba2a50ef0dce60a7 to your computer and use it in GitHub Desktop.
WPJM alerts reschedule alert cron jobs
if ( ! has_action('job-manager-alert-check-reschedule') ) {
function wpjm_alerts_check_reschedule_events() {
$alert_posts = new WP_Query( array(
'post_type' => 'job_alert',
'posts_per_page' => -1,
'post_status' => 'publish'
) );
$schedules = WP_Job_Manager_Alerts_Notifier::get_alert_schedules();
foreach ( $alert_posts->posts as $post ) {
if ( false === wp_next_scheduled( 'job-manager-alert', array( $post->ID ) ) ) {$alert_frequency = get_post_meta( $post->ID, 'alert_frequency', true );
$next = strtotime( '+1 day' );
if ( ! empty( $schedules[ $alert_frequency ] ) ) {
$next = strtotime( '+' . $schedules[ $alert_frequency ]['interval'] . ' seconds' );
}
wp_schedule_event( $next, $alert_frequency, 'job-manager-alert', array( $post->ID ) );
}
}
}
add_action( 'job-manager-alert-check-reschedule', 'wpjm_alerts_check_reschedule_events' );
if ( false === wp_next_scheduled( 'job-manager-alert-check-reschedule' ) ) {
wp_schedule_event( time(), 'daily', 'job-manager-alert-check-reschedule' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment