-
-
Save bikedorkjon/abb6b1bdc235aff2ba2a50ef0dce60a7 to your computer and use it in GitHub Desktop.
WPJM alerts reschedule alert cron jobs
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
| 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