56 lines
2.2 KiB
PHP
56 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Issue #90 — avatares nuevos de 2 colaboradores nuevos (Mari Paz Lopez, Africa de la Cruz).
|
|
* Reapunta foto_perfil (user_meta) al PNG uploads/avatares/autores/autor-<uid>.png.
|
|
* Si foto_perfil ya apuntaba a ese fichero (caso #62), solo regenera metadata.
|
|
* Backup del foto_perfil anterior en user_meta _foto_perfil_pre81 (revertible).
|
|
*
|
|
* Uso (dentro del contenedor):
|
|
* php import_avatars_75.php -> DRY-RUN
|
|
* APPLY=1 php import_avatars_75.php -> aplica
|
|
*/
|
|
require "/var/www/html/wp-load.php";
|
|
require_once ABSPATH . 'wp-admin/includes/image.php';
|
|
|
|
$apply = getenv('APPLY') === '1';
|
|
$updir = wp_get_upload_dir();
|
|
|
|
$authors = [
|
|
[474, "Mari Paz López Santos"],
|
|
[993, "África de la Cruz Tomé"],
|
|
];
|
|
|
|
$done = $regen = $err = 0;
|
|
foreach ($authors as [$uid, $name]) {
|
|
$rel = "avatares/autores/autor-{$uid}.png";
|
|
$abs = $updir['basedir'] . '/' . $rel;
|
|
if (!file_exists($abs)) { echo "MISSING uid=$uid ($name)\n"; $err++; continue; }
|
|
|
|
$cur = (int) get_user_meta($uid, 'foto_perfil', true);
|
|
|
|
// foto_perfil ya apunta a este fichero -> solo se sobrescribió el PNG
|
|
if ($cur && get_post_meta($cur, '_wp_attached_file', true) === $rel) {
|
|
echo "REGEN #$uid $name (attachment $cur ya apunta al PNG)\n";
|
|
if ($apply) wp_update_attachment_metadata($cur, wp_generate_attachment_metadata($cur, $abs));
|
|
$regen++; continue;
|
|
}
|
|
|
|
echo "NUEVO #$uid $name (foto_perfil actual: " . ($cur ?: 'ninguna') . ")\n";
|
|
if (!$apply) { $done++; continue; }
|
|
|
|
if (get_user_meta($uid, '_foto_perfil_pre81', true) === '') {
|
|
update_user_meta($uid, '_foto_perfil_pre81', $cur);
|
|
}
|
|
$aid = wp_insert_attachment([
|
|
'post_mime_type' => 'image/png',
|
|
'post_title' => "Avatar {$name}",
|
|
'post_status' => 'inherit',
|
|
'guid' => $updir['baseurl'] . '/' . $rel,
|
|
], $abs, 0, true);
|
|
if (is_wp_error($aid)) { echo " ERR: " . $aid->get_error_message() . "\n"; $err++; continue; }
|
|
wp_update_attachment_metadata($aid, wp_generate_attachment_metadata($aid, $abs));
|
|
update_user_meta($uid, 'foto_perfil', $aid);
|
|
$done++;
|
|
}
|
|
echo "\n" . ($apply ? "APLICADO" : "DRY-RUN") . ": nuevos=$done regen=$regen errores=$err\n";
|