'Accès refusé']); } $settings = mah2_get_settings(); $batch_size = isset($settings['batch_size']) ? intval($settings['batch_size']) : 10; $state = mah2_get_batch_state('remove'); if (empty($state) || !empty($state['done'])) { wp_send_json_success([ 'done' => true, 'message' => 'Aucun batch actif.', 'progress' => 100, 'stats' => [ 'posts_processed' => 0, 'posts_updated' => 0, 'total' => 0, ], 'debug' => [], ]); } if (!empty($state['stopped'])) { wp_send_json_success([ 'done' => true, 'stopped' => true, 'message' => 'Suppression arrêtée.', 'progress' => 0, 'stats' => [ 'posts_processed' => intval($state['posts_processed']), 'posts_updated' => intval($state['posts_updated']), 'total' => intval($state['total']), ], 'debug' => !empty($state['debug']) ? $state['debug'] : [], ]); } $offset = isset($state['offset']) ? intval($state['offset']) : 0; $total = isset($state['total']) ? intval($state['total']) : 0; $ids = isset($state['ids']) ? (array) $state['ids'] : []; $batch_ids = array_slice($ids, $offset, $batch_size); $debug_messages = []; foreach ($batch_ids as $post_id) { $post_id = intval($post_id); $before = get_post_field('post_content', $post_id); if (!$before) { $state['posts_processed']++; continue; } mah2_remove_links_for_post($post_id); $after = get_post_field('post_content', $post_id); $updated = ($before !== $after); $state['posts_processed']++; if ($updated) { $state['posts_updated']++; } if (mah2_debug_enabled()) { $debug_messages[] = "Post {$post_id} cleaned: " . ($updated ? 'YES' : 'NO'); } } $state['offset'] += count($batch_ids); if ($state['offset'] >= $total || empty($batch_ids)) { $state['done'] = true; } if (mah2_debug_enabled()) { $existing_debug = isset($state['debug']) ? $state['debug'] : []; $state['debug'] = array_slice( array_merge($existing_debug, $debug_messages), -200 ); } mah2_save_batch_state($state, 'remove'); $progress = $total > 0 ? round(($state['offset'] / $total) * 100) : 100; if ($progress > 100) $progress = 100; wp_send_json_success([ 'done' => !empty($state['done']), 'progress' => $progress, 'message' => !empty($state['done']) ? 'Suppression terminée.' : 'Batch suppression traité.', 'stats' => [ 'posts_processed' => intval($state['posts_processed']), 'posts_updated' => intval($state['posts_updated']), 'total' => $total, ], 'debug' => !empty($state['debug']) ? $state['debug'] : [], ]);}add_action('wp_ajax_mah2_run_remove_batch', 'mah2_ajax_run_remove_batch'); Plan de site

Plan de site

administrateur

Posts