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) {

View File

@@ -169,7 +169,11 @@ class PostContentManagerTest extends \MailPoetTest {
expect($this->post_content->getContent($post, ''))->equals('some text in content');
}
function _after() {
function testItRemovesImageCaptionsFromClassicEditorPosts() {
$post = (object)[
'post_content' => 'Text [caption id="attachment_23" align="alignnone" width="300"]<img class="size-medium wp-image-23" src="i.png" alt="Alt" width="300" height="300" />Caption[/caption] Text [caption id="attachment_23" align="alignnone" width="300"]<img class="size-medium wp-image-23" src="i.png" alt="Alt" width="300" height="300" />Caption[/caption] Text',
];
expect($this->post_content->getContent($post, 'excerpt'))->equals('Text Text Text');
}
function testItRemovesImageCaptionsFromGutenbergPosts() {