from pathlib import Path
src = Path("/mnt/data/Pasted text(20260907-153732).txt")
text = src.read_text(encoding="utf-8")
old_featured = """ private static function set_product_image_from_url($product_id, $image_url)
{
if (empty($image_url)) return false;
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
$attachment_id = self::with_filename_shortener(static function () use ($image_url, $product_id) {
return media_sideload_image($image_url, $product_id, null, 'id');
});
if (is_wp_error($attachment_id)) {
error_log(sprintf(
'Symphonya: media_sideload_image failed for product %d, URL "%s" — [%s] %s',
$product_id,
$image_url,
$attachment_id->get_error_code(),
$attachment_id->get_error_message()
));
return false;
}
set_post_thumbnail($product_id, $attachment_id);
return $attachment_id;
}
"""
new_featured = """ /**
* Find an existing Media Library attachment for a Symphonya image URL.
*
* WordPress stores the original sideload URL in _source_url. We also keep
* our own _symphonya_source_url marker for future lookups.
*
* @param string $image_url
* @return int Attachment ID, or 0 when no usable attachment exists.
*/
private static function find_existing_attachment_by_url($image_url)
{
$image_url = esc_url_raw((string) $image_url);
if ($image_url === '') {
return 0;
}
global $wpdb;
$attachment_id = (int) $wpdb->get_var(
$wpdb->prepare(
"
SELECT pm.post_id
FROM {$wpdb->postmeta} pm
INNER JOIN {$wpdb->posts} p
ON p.ID = pm.post_id
WHERE pm.meta_key IN ('_symphonya_source_url', '_source_url')
AND pm.meta_value = %s
AND p.post_type = 'attachment'
AND p.post_status != 'trash'
ORDER BY
CASE WHEN pm.meta_key = '_symphonya_source_url' THEN 0 ELSE 1 END,
p.ID ASC
LIMIT 1
",
$image_url
)
);
if (!$attachment_id) {
return 0;
}
$file = get_attached_file($attachment_id);
if (!$file || !file_exists($file)) {
return 0;
}
// Backfill our own marker on older attachments found via _source_url.
if (get_post_meta($attachment_id, '_symphonya_source_url', true) !== $image_url) {
update_post_meta($attachment_id, '_symphonya_source_url', $image_url);
}
return $attachment_id;
}
private static function set_product_image_from_url($product_id, $image_url)
{
$image_url = esc_url_raw((string) $image_url);
if ($image_url === '') {
return false;
}
// Reuse an attachment that WordPress/Symphonya already downloaded.
$existing_attachment_id = self::find_existing_attachment_by_url($image_url);
if ($existing_attachment_id) {
set_post_thumbnail($product_id, $existing_attachment_id);
return $existing_attachment_id;
}
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
$attachment_id = self::with_filename_shortener(static function () use ($image_url, $product_id) {
return media_sideload_image($image_url, $product_id, null, 'id');
});
if (is_wp_error($attachment_id)) {
error_log(sprintf(
'Symphonya: media_sideload_image failed for product %d, URL "%s" — [%s] %s',
$product_id,
$image_url,
$attachment_id->get_error_code(),
$attachment_id->get_error_message()
));
return false;
}
$attachment_id = (int) $attachment_id;
// Keep a Symphonya-specific source marker for fast, reliable reuse.
update_post_meta($attachment_id, '_symphonya_source_url', $image_url);
set_post_thumbnail($product_id, $attachment_id);
return $attachment_id;
}
"""
if old_featured not in text:
raise RuntimeError("Featured-image function not found exactly; refusing to create a partial patch.")
text = text.replace(old_featured, new_featured, 1)
old_gallery = """ $new_ids = self::with_filename_shortener(static function () use ($urls, $product_id) {
$ids = array();
foreach ($urls as $url) {
$url = esc_url_raw($url);
if (empty($url)) {
continue;
}
$attachment_id = media_sideload_image($url, $product_id, null, 'id');
if (is_wp_error($attachment_id)) {
error_log(sprintf(
'Symphonya: gallery sideload failed for product %d, URL "%s" — [%s] %s',
$product_id,
$url,
$attachment_id->get_error_code(),
$attachment_id->get_error_message()
));
continue;
}
$ids[] = intval($attachment_id);
}
return $ids;
});
"""
new_gallery = """ $new_ids = self::with_filename_shortener(static function () use ($urls, $product_id) {
$ids = array();
foreach ($urls as $url) {
$url = esc_url_raw($url);
if (empty($url)) {
continue;
}
// Reuse an attachment that already exists for this exact source URL.
$existing_attachment_id = self::find_existing_attachment_by_url($url);
if ($existing_attachment_id) {
$ids[] = intval($existing_attachment_id);
continue;
}
$attachment_id = media_sideload_image($url, $product_id, null, 'id');
if (is_wp_error($attachment_id)) {
error_log(sprintf(
'Symphonya: gallery sideload failed for product %d, URL "%s" — [%s] %s',
$product_id,
$url,
$attachment_id->get_error_code(),
$attachment_id->get_error_message()
));
continue;
}
$attachment_id = intval($attachment_id);
// Keep a Symphonya-specific source marker for future reuse.
update_post_meta($attachment_id, '_symphonya_source_url', $url);
$ids[] = $attachment_id;
}
return $ids;
});
"""
if old_gallery not in text:
raise RuntimeError("Gallery sideload block not found exactly; refusing to create a partial patch.")
text = text.replace(old_gallery, new_gallery, 1)
out = Path("/mnt/data/index-symphonya-afbeeldingen-fix.php")
out.write_text(text, encoding="utf-8")
print(f"Bestand gemaakt: {out}")
print("Aanpassingen:")
print("- bestaande attachment wordt hergebruikt op basis van _source_url of _symphonya_source_url")
print("- featured image wordt niet opnieuw gedownload als die al bestaat")
print("- gallery-afbeeldingen worden niet opnieuw gedownload als die al bestaan")
print("- nieuw gedownloade Symphonya-afbeeldingen krijgen _symphonya_source_url als marker")
Rodial, Dragon's Blood, Hyaluron, Hydraterend, Room, Voor gezicht, 10 ml - MVG Haarstudio
Koopavond in de Haarstudio, iedere vrijdag van 9 tot 21 uur op afspraak!!!
"Wist je dat je eenvoudig online onze producten kunt bestellen? Bekijk onze shop!" Negeren
Hoe snel wordt mijn bestelling geleverd? Binnen 1–7 werkdagen na betaling, tenzij anders vermeld
Wat zijn de verzendkosten? De verzendkosten worden altijd duidelijk vermeld bij het afrekenen.
Wat als mijn product niet leverbaar is? Je ontvangt dan een bericht en krijgt een volledige terugbetaling
Kan ik mijn bestelling retourneren? Ja, binnen 14 dagen na ontvangst. Meld je retour via info@mvghaarstudio.com en stuur het product terug in de originele verpakking. Retourkosten zijn voor de klant, behalve bij een fout van ons
Zijn er uitzonderingen op retourneren? Ja, geopende of verzegelde cosmetica/haarproducten en gepersonaliseerde artikelen kunnen om hygiënische redenen niet worden geretourneerd
Beoordelingen
Er zijn nog geen beoordelingen.
Wees de eerste om “Rodial, Dragon’s Blood, Hyaluron, Hydraterend, Room, Voor gezicht, 10 ml” te beoordelen Reactie annuleren
Beoordelingen
Er zijn nog geen beoordelingen.