Remove image captions from classic editor posts
[MAILPOET-2194]
This commit is contained in:
@@ -32,7 +32,7 @@ class PostContentManager {
|
|||||||
if (!empty($post->post_excerpt)) {
|
if (!empty($post->post_excerpt)) {
|
||||||
return self::stripShortCodes($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);
|
return self::stripShortCodes($post->post_content);
|
||||||
}
|
}
|
||||||
@@ -78,12 +78,21 @@ class PostContentManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function generateExcerpt($content) {
|
private function generateExcerpt($content) {
|
||||||
// remove image captions
|
// remove image captions in gutenberg
|
||||||
$content = preg_replace(
|
$content = preg_replace(
|
||||||
"/<figcaption.*?>.*?<\/figcaption>/",
|
"/<figcaption.*?>.*?<\/figcaption>/",
|
||||||
'',
|
'',
|
||||||
$content
|
$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
|
// if excerpt is empty then try to find the "more" tag
|
||||||
$excerpts = explode('<!--more-->', $content);
|
$excerpts = explode('<!--more-->', $content);
|
||||||
if (count($excerpts) > 1) {
|
if (count($excerpts) > 1) {
|
||||||
|
@@ -169,7 +169,11 @@ class PostContentManagerTest extends \MailPoetTest {
|
|||||||
expect($this->post_content->getContent($post, ''))->equals('some text in content');
|
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() {
|
function testItRemovesImageCaptionsFromGutenbergPosts() {
|
||||||
|
Reference in New Issue
Block a user