Remove image captions from classic editor posts

[MAILPOET-2194]
This commit is contained in:
Pavel Dohnal
2019-08-14 15:30:28 +02:00
committed by M. Shull
parent 3721698b67
commit 79d9deb6c4
2 changed files with 16 additions and 3 deletions

View File

@@ -32,7 +32,7 @@ class PostContentManager {
if (!empty($post->post_excerpt)) {
return self::stripShortCodes($post->post_excerpt);
}
return $this->generateExcerpt(self::stripShortCodes($post->post_content));
return $this->generateExcerpt($post->post_content);
}
return self::stripShortCodes($post->post_content);
}
@@ -78,12 +78,21 @@ class PostContentManager {
}
private function generateExcerpt($content) {
// remove image captions
// remove image captions in gutenberg
$content = preg_replace(
"/<figcaption.*?>.*?<\/figcaption>/",
'',
$content
);
// remove image captions in classic posts
$content = preg_replace(
"/\[caption.*?\](.*?)\[\/caption\]/",
'',
$content
);
$content = self::stripShortCodes($content);
// if excerpt is empty then try to find the "more" tag
$excerpts = explode('<!--more-->', $content);
if (count($excerpts) > 1) {