core/image: only output <figure> rather than complete html document

This commit is contained in:
2026-02-05 20:45:54 +00:00
parent 755b38c8cf
commit 8b0d40f13a

View File

@@ -268,14 +268,19 @@ function core_details_modified($content, $block)
function core_image_modified($content, $block) function core_image_modified($content, $block)
{ {
$imageID = @$block['attrs']['id'];
$lazy = wp_get_attachment_image_src($imageID, 'lazy');
$large = wp_get_attachment_image_src($imageID, '2048x2048');
$dom = new \DomDocument(); $dom = new \DomDocument();
$dom->strictErrorChecking = false; $dom->strictErrorChecking = false;
@$dom->loadHTML($content); @$dom->loadHTML($content);
@$images = $dom->getElementsByTagName('img');
$images = @$dom->getElementsByTagName('img');
$figures = @$dom->getElementsByTagName('figure');
if(!$figures) return $content;
// get image data
$imageID = @$block['attrs']['id'];
$lazy = wp_get_attachment_image_src($imageID, 'lazy');
$large = wp_get_attachment_image_src($imageID, '2048x2048');
// create lightbox link node // create lightbox link node
$link = $dom->createElement('a'); $link = $dom->createElement('a');
@@ -311,5 +316,6 @@ function core_image_modified($content, $block)
$linkClone->appendChild($image); $linkClone->appendChild($image);
} }
return $dom->saveHTML(); return $dom->saveHTML($figures[0]);
} }