Skip to content

Commit

Permalink
PLANET-7535 Credit is removed when caption is edited (#2306)
Browse files Browse the repository at this point in the history
- Fixed str_replace() method to use updated captions
  • Loading branch information
Osong-Michael committed Jun 12, 2024
1 parent 5122e5c commit 4e1b72a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/MasterSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,12 @@ public function p4_core_image_block_render(array $attributes, string $content):
$image_credit = ' ©' . $image_credit;
}

$caption = wp_get_attachment_caption($image_id) ?? '';
$caption = '';

$pattern = '/<figcaption[^>]*>(.*?)<\/figcaption>/';
if (preg_match($pattern, $content, $matches)) {
$caption = $matches[1];
}

if (empty($credit) || (!empty($caption) && strpos($caption, $image_credit) !== false)) {
return $content;
Expand Down

0 comments on commit 4e1b72a

Please sign in to comment.