| @@ -45,8 +45,37 @@ | ||
| 45 | 45 | return c_ws_plugin__s2member_cron_jobs_in::extend_cron_schedules($schedules); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | + * Conditionally schedules a single WP-Cron event. | |
| 50 | + * | |
| 51 | + * @package s2Member\Cron_Jobs | |
| 52 | + * @since 260902 | |
| 53 | + * | |
| 54 | + * @param string $hook WP-Cron hook name. | |
| 55 | + * @param int $timestamp Unix timestamp. Defaults to now. | |
| 56 | + * @param array $args Optional event arguments. | |
| 57 | + * | |
| 58 | + * @return bool True if the event already exists or was scheduled successfully. | |
| 59 | + */ | |
| 60 | + public static function maybe_schedule_single_event($hook, $timestamp = 0, $args = array()) | |
| 61 | + { | |
| 62 | + $hook = (string)$hook; | |
| 63 | + $args = (array)$args; | |
| 64 | + $timestamp = (int)$timestamp; | |
| 65 | + | |
| 66 | + if(!$hook) | |
| 67 | + return FALSE; | |
| 68 | + | |
| 69 | + if(wp_next_scheduled($hook, $args)) | |
| 70 | + return TRUE; | |
| 71 | + | |
| 72 | + wp_schedule_single_event($timestamp > 0 ? $timestamp : time(), $hook, $args); | |
| 73 | + | |
| 74 | + return (bool)wp_next_scheduled($hook, $args); //260902 Verify for older supported WordPress versions. | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 49 | 78 | * Allows the Auto-EOT Sytem to be processed through a server-side Cron Job. |
| 50 | 79 | * |
| 51 | 80 | * @package s2Member\Cron_Jobs |
| 52 | 81 | * @since 3.5 |