Done !
| Server IP : 212.28.179.223 / Your IP : 216.73.216.169 Web Server : Apache System : Linux host.server-guru-usa.com 5.14.0-687.24.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 9 18:14:06 EDT 2026 x86_64 User : nnoticias ( 1015) PHP Version : 8.3.32 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/nnoticias/www/ |
Upload File : |
<?php
require_once('wp-load.php');
global $wpdb;
echo "Iniciando escaneo y limpieza profunda (Forzando borrado de JPG/PNG)...\n";
// Obtener todas las imágenes
$attachments = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type='attachment' AND post_mime_type IN ('image/jpeg', 'image/png', 'image/webp')");
$count_db_updated = 0;
$count_files_deleted = 0;
$freed_bytes = 0;
$total = count($attachments);
$processed = 0;
$uploads = wp_upload_dir();
$base_dir = trailingslashit($uploads['basedir']);
foreach ($attachments as $id) {
$meta = wp_get_attachment_metadata($id);
$current_file = get_attached_file($id);
if (!$current_file) continue;
// Determinar rutas base asumiendo el patrón archivo.jpg.webp
$orig_jpg_path = str_replace('.webp', '', $current_file);
$webp_path = $orig_jpg_path . '.webp';
// 1. Forzar actualización de Base de Datos si falta
if (file_exists($webp_path) && strpos($current_file, '.webp') === false) {
$wpdb->update($wpdb->posts, ['post_mime_type' => 'image/webp'], ['ID' => $id]);
update_attached_file($id, $webp_path);
if (is_array($meta)) {
$meta['file'] = $meta['file'] . '.webp';
if (!empty($meta['sizes'])) {
foreach ($meta['sizes'] as $size => $data) {
$meta['sizes'][$size]['file'] = str_replace('.webp', '', $data['file']) . '.webp';
$meta['sizes'][$size]['mime-type'] = 'image/webp';
}
}
wp_update_attachment_metadata($id, $meta);
}
$count_db_updated++;
}
// 2. Ejecutar Borrado Físico Implacable
// Borrar imagen principal
if (file_exists($webp_path) && file_exists($orig_jpg_path)) {
$freed_bytes += filesize($orig_jpg_path);
unlink($orig_jpg_path);
$count_files_deleted++;
}
// Borrar miniaturas (thumbnails)
if (is_array($meta) && !empty($meta['sizes'])) {
$rel_dir = dirname(_wp_relative_upload_path($orig_jpg_path));
foreach ($meta['sizes'] as $size => $data) {
$base_thumb_name = str_replace('.webp', '', $data['file']);
$old_thumb_path = $base_dir . $rel_dir . '/' . $base_thumb_name;
$new_thumb_webp = $old_thumb_path . '.webp';
if (file_exists($new_thumb_webp) && file_exists($old_thumb_path)) {
$freed_bytes += filesize($old_thumb_path);
unlink($old_thumb_path);
$count_files_deleted++;
}
}
}
$processed++;
if ($processed % 1000 == 0) {
echo "Procesados $processed de $total archivos...\n";
}
}
$gb = round($freed_bytes / 1024 / 1024 / 1024, 2);
echo "\n¡Limpieza implacable completada!\n";
echo "- Imágenes actualizadas en DB: $count_db_updated\n";
echo "- Archivos físicos .jpg/.png eliminados: $count_files_deleted\n";
echo "- Espacio liberado en disco: $gb GB\n";