function esh_cron_schedules($schedules) {
$schedules['1min'] = [
'interval' => 60,
'display' => __('Each 1 min', 'esh')
];
$schedules['2min'] = [
'interval' => 120,
'display' => __('Each 2 min', 'esh')
];
$schedules['5min'] = [
'interval' => 300,
'display' => __('Each 5 min', 'esh')
];
$schedules['weekly'] = [
'interval' => 604800,
'display' => __('Once Weekly', 'esh')
];
$schedules['monthly'] = [
'interval' => 2635200,
'display' => __('Once a Month', 'esh')
];
return $schedules;
}
add_filter('cron_schedules', 'esh_cron_schedules');
wp_schedule_event(time(), '5min', 'esh_rets_import_schedule_' . $schedule_id);
wp_unschedule_event(time(), 'esh_rets_import_schedule_' . $schedule_id);
wp_clear_scheduled_hook('esh_rets_import_schedule_' . $schedule_id);
| Interval | Seconds | Use Case |
|---|---|---|
| 1min | 60 | High-frequency updates |
| 2min | 120 | Fast import cycles |
| 5min | 300 | Regular updates |
| weekly | 604800 | Full data refresh |
add_action('esh_scheduler_after_execute', 'esh_scheduler_after_execute', 10, 1);
function esh_scheduler_after_execute($schedule) {
$update_offset = false;
// Check if import reached end and should reset
if ($schedule instanceof Esh_Schedule &&
$schedule->is_import_latest_properties == 1 &&
$schedule->num_items <= 0 &&
$schedule->num_items < $schedule->offset) {
$update_offset = true;
} elseif ($schedule instanceof Esh_Schedule &&
$schedule->num_items > 0 &&
$schedule->num_items <= $schedule->offset) {
$update_offset = true;
}
// Reset offset and method when cycle complete
if ($update_offset) {
$schedule->save_field_value('offset', 0);
$schedule_id = $schedule->getID();
update_post_meta($schedule_id, 'offset', 0);
$schedule->save_field_value('method', 'skip');
update_post_meta($schedule_id, 'method', 'skip');
}
}
Tracks position in large datasets to resume where previous import left off
Automatically resets to beginning when all records processed
Schedules can run in "non-stop" mode for constant data synchronization
add_action('esh_phrets_import_images_from_queue', 'esh_phrets_import_images_from_queue');
function esh_phrets_import_images_from_queue() {
$queue = get_option('es_phrets_image_queue', []);
if (!empty($queue) && is_array($queue)) {
$queue = array_reverse($queue);
foreach ($queue as $post_key => $post_id) {
$property = esh_get_property($post_id);
$profile_uid = $property->profile_uid;
$esh_rets_connected = esh_phrets_get_connection(true, $profile_uid);
// Process images for this property
if ($property->rets_resource && $property->property_mls_id) {
try {
$objects = $esh_rets_connected->GetObject(
$property->rets_resource,
'Photo',
$property->property_mls_id,
'*',
$use_obj_loc
);
// Process each image...
// Remove from queue when complete
unset($queue[$post_key]);
} catch (Exception $e) {
continue;
}
}
// Update queue and break (one property per execution)
update_option('es_phrets_image_queue', array_reverse($queue));
break;
}
}
}
Uses WordPress options table for persistent queue storage
Last-in-first-out processing with array_reverse()
Skips existing properties, only imports new ones
Updates existing properties with new data
Imports only recently updated properties
| Setting | Purpose |
|---|---|
| Limit | Properties per execution |
| Offset | Starting position in dataset |
| Images Num | Max images per property |
| Non-Stop | Continuous processing mode |
function esh_get_scheduler_start_link($schedule_id) {
return add_query_arg([
'es-action' => 'start-scheduler',
'id' => $schedule_id,
]);
}
function esh_get_scheduler_stop_link($schedule_id) {
return add_query_arg([
'es-action' => 'stop-scheduler',
'id' => $schedule_id,
]);
}
function esh_get_scheduler_edit_link($id) {
return add_query_arg([
'es-action' => 'edit-scheduler',
'id' => $id,
]);
}
Manual schedule activation and deactivation through admin interface
Modify schedule parameters without stopping running imports
Real-time status display for active schedules