cron_schedules
Hook in WPFTS
The cron_schedules
hook is a standard WordPress hook that allows adding custom intervals for scheduled tasks. WPFTS uses this hook to add two new intervals: wpfts_each_minute
(every minute) and wpfts_each_hour
(every hour).
What WPFTS does when cron_schedules
is called:
-
Adding the
wpfts_each_minute
interval: The plugin adds a newwpfts_each_minute
interval with a 60-second (1-minute) execution interval. -
Adding the
wpfts_each_hour
interval: The plugin adds a newwpfts_each_hour
interval with a 3600-second (1-hour) execution interval.
Important functions involved in processing cron_schedules
:
- No specific WPFTS functions are used; the standard WordPress mechanism for adding cron schedules is employed.
How to use this in addon development:
Addon developers can use these new intervals for their scheduled tasks. For example, you can use the wpfts_each_minute
interval for frequent data updates in an index, or the wpfts_each_hour
interval for less frequent tasks such as cache clearing or sending notifications.
Example (using the wpfts_each_minute
interval in an addon):
// Register a new cron task.
if (!wp_next_scheduled('my_addon_cron_task')) {
wp_schedule_event(time(), 'wpfts_each_minute', 'my_addon_cron_task');
}
// Task handler.
add_action('my_addon_cron_task', 'my_addon_cron_function');
function my_addon_cron_function() {
// Code that will be executed every minute.
}
Additional notes:
-
New cron intervals are added only when the WPFTS plugin is activated.
-
To disable tasks scheduled using the new intervals, use the
wp_clear_scheduled_hook()
function.
This hook demonstrates how WPFTS adds new cron intervals that can be used by the plugin itself and by addon developers.