diff --git a/inc/class-book.php b/inc/class-book.php index 9db70116a1..800356ee4c 100644 --- a/inc/class-book.php +++ b/inc/class-book.php @@ -517,12 +517,14 @@ static function getSubsections( $id ) { if ( empty( $parent ) ) { return false; } - if ( stripos( $parent->post_content, 'post_content, 'heading' ); + if ( stripos( $parent->post_content, ' or [heading] shortcode return false; } $type = $parent->post_type; - $content = strip_tags( $parent->post_content, '

' ); // Strip everything except h1 to speed up load time + $content = ( $has_shortcode ) ? apply_filters( 'the_content', $parent->post_content ) : $parent->post_content; // Only render shortcodes if we have to + $content = strip_tags( $content, '

' ); // Strip everything except h1 to speed up load time $output = []; $s = 1; diff --git a/tests/test-book.php b/tests/test-book.php index cb85a153b2..81424d6f70 100644 --- a/tests/test-book.php +++ b/tests/test-book.php @@ -145,6 +145,7 @@ public function test_wordCount() { public function test_getSubsections() { $this->_book(); + $this->_shortcodes(); $book = \Pressbooks\Book::getInstance(); $result = $book::getSubsections( 0 ); @@ -158,12 +159,17 @@ public function test_getSubsections() { $this->assertEquals( 'Hi there!', $result["front-matter-{$id}-section-1"] ); $test = "

Hi there! Hope you're doing good.

How are you?

"; // ALL CAPS, texturized - $id = $book::getBookStructure()['front-matter'][0]['ID']; $this->factory()->post->update_object( $id, [ 'post_content' => $test ] ); $result = $book::getSubsections( $id ); $this->assertArrayHasKey( "front-matter-{$id}-section-1", $result ); $this->assertEquals( 'Hi there! Hope you’re doing good.', $result["front-matter-{$id}-section-1"] ); + $test = '[heading]Whoa, a shortcode![/heading]

Some other stuff.

'; // A [heading] shortcode + $this->factory()->post->update_object( $id, [ 'post_content' => $test ] ); + $result = $book::getSubsections( $id ); + $this->assertArrayHasKey( "front-matter-{$id}-section-1", $result ); + $this->assertEquals( 'Whoa, a shortcode!', $result["front-matter-{$id}-section-1"] ); + $test = "

Hi there! Hope you're doing good.

How are you?

"; // H2 $this->factory()->post->update_object( $id, [ 'post_content' => $test ] ); $result = $book::getSubsections( $id ); diff --git a/tests/utils-trait.php b/tests/utils-trait.php index 84a480a476..faf5742d5a 100644 --- a/tests/utils-trait.php +++ b/tests/utils-trait.php @@ -124,7 +124,7 @@ private function _createChapter( $post_parent = 0, $with_media = false ) { $content .= " [video]{$video_url}[/video] -{$thumbnail_html} +{$thumbnail_html} "; } @@ -256,4 +256,21 @@ public function _allowIframes( $allowed, $context ) { return $allowed; } + /** + * Set up shortcodes. + * @see hooks.php + */ + public function _shortcodes() { + remove_filter( 'the_content', 'wpautop' ); + add_filter( 'the_content', 'wpautop', 12 ); // execute wpautop after shortcode processing + + \Pressbooks\Shortcodes\Footnotes\Footnotes::init(); + \Pressbooks\Shortcodes\Attributions\Attachments::init(); + \Pressbooks\Shortcodes\Glossary\Glossary::init(); + \Pressbooks\Shortcodes\Complex\Complex::init(); + \Pressbooks\Shortcodes\Generics\Generics::init(); + \Pressbooks\Shortcodes\WikiPublisher\Glyphs::init(); + \Pressbooks\Shortcodes\TablePress::init(); + } + }