// TEMP: Background chunk runner to delete all WooCommerce draft products
if (!function_exists('gea_queue_delete_draft_products_runner')) {
function gea_queue_delete_draft_products_runner($batch_size = 50, $delay_seconds = 2) {
$runner_state = get_option('gea_delete_draft_products_runner_state', array());
if (!empty($runner_state['in_progress'])) {
return array('status' => 'already_running', 'message' => 'Draft product deletion already running.');
}
$runner_state = array(
'in_progress' => true,
'last_run' => current_time('mysql'),
'batch_size' => $batch_size,
'delay_seconds' => $delay_seconds,
'offset' => 0,
'deleted_total' => 0,
);
update_option('gea_delete_draft_products_runner_state', $runner_state, false);
wp_schedule_single_event(time() + 5, 'gea_run_delete_draft_products_chunk');
return array('status' => 'queued', 'message' => 'Draft product deletion queued.');
}
}
if (!function_exists('gea_run_delete_draft_products_chunk')) {
add_action('gea_run_delete_draft_products_chunk', 'gea_run_delete_draft_products_chunk');
function gea_run_delete_draft_products_chunk() {
$runner_state = get_option('gea_delete_draft_products_runner_state', array());
if (empty($runner_state['in_progress'])) {
return;
}
$batch_size = isset($runner_state['batch_size']) ? (int)$runner_state['batch_size'] : 50;
$offset = isset($runner_state['offset']) ? (int)$runner_state['offset'] : 0;
$deleted_total = isset($runner_state['deleted_total']) ? (int)$runner_state['deleted_total'] : 0;
$args = array(
'post_type' => 'product',
'post_status' => 'draft',
'posts_per_page' => $batch_size,
'fields' => 'ids',
'offset' => $offset,
'orderby' => 'ID',
'order' => 'ASC',
'suppress_filters' => false,
);
$query = new WP_Query($args);
$ids = $query->posts;
if (empty($ids)) {
// Done
$runner_state['in_progress'] = false;
update_option('gea_delete_draft_products_runner_state', $runner_state, false);
return;
}
foreach ($ids as $id) {
wp_delete_post($id, true);
$deleted_total++;
}
$runner_state['offset'] = $offset + $batch_size;
$runner_state['deleted_total'] = $deleted_total;
update_option('gea_delete_draft_products_runner_state', $runner_state, false);
// Schedule next chunk if more remain
if (count($ids) === $batch_size) {
wp_schedule_single_event(time() + (int)$runner_state['delay_seconds'], 'gea_run_delete_draft_products_chunk');
} else {
$runner_state['in_progress'] = false;
update_option('gea_delete_draft_products_runner_state', $runner_state, false);
}
}
}
Page not found - GEA Jewelers
404
We Can’t Find the Page You’re Looking for
You may be lost, but you'll never lose track of your field resources
with us!
The page you are looking for might have been removed, had its name
changed, or is temporarily unavailable
Back To Home