/**
* Kesin Çözüm: Harici Resim Özgünleştirme
* Beyaz boşluk sorunu olmayan versiyon
*/
function kesin_cozum_harici_resim_ozgunlestir($content) {
// Yalnızca front-end'de ve içerik varsa çalışsın
if (is_admin() || empty($content) || !is_singular()) {
return $content;
}
// Tüm img tag'lerini bul ve işle
$processed_content = preg_replace_callback(
'/]*?)src=(["\'])([^"\']+)\2([^>]*)>/i',
function($matches) {
$attrs_before = $matches[1];
$quote = $matches[2];
$src = $matches[3];
$attrs_after = $matches[4];
// Yerel resimleri değiştirme
if (strpos($src, site_url()) === 0 || strpos($src, '/') === 0) {
return $matches[0];
}
// Geçerli URL kontrolü
if (!filter_var($src, FILTER_VALIDATE_URL)) {
return $matches[0];
}
// Yeni parametreler ekle
$new_src = add_query_arg(array(
'ref' => sanitize_title(get_bloginfo('name')),
'uc' => substr(md5(site_url()), 0, 6)
), $src);
// Yeni img tag'ini oluştur
$new_tag = '
';
return $new_tag;
},
$content
);
// Eğer preg_replace başarısız olursa orijinal içeriği döndür
return ($processed_content !== null) ? $processed_content : $content;
}
// Filtreyi ekle (düşük öncelik)
add_filter('the_content', 'kesin_cozum_harici_resim_ozgunlestir', 20);