diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 4b6d9de25fa11..3b96024394cb4 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -246,6 +246,7 @@ add_filter( 'widget_text_content', 'wp_filter_content_tags', 12 ); // Runs after do_shortcode(). add_filter( 'widget_block_content', 'do_blocks', 9 ); +add_filter( 'widget_block_content', 'shortcode_unautop' ); add_filter( 'widget_block_content', 'do_shortcode', 11 ); add_filter( 'widget_block_content', 'wp_filter_content_tags', 12 ); // Runs after do_shortcode(). diff --git a/tests/phpunit/tests/widgets/wpWidgetBlock.php b/tests/phpunit/tests/widgets/wpWidgetBlock.php new file mode 100644 index 0000000000000..1fcce1aa02a16 --- /dev/null +++ b/tests/phpunit/tests/widgets/wpWidgetBlock.php @@ -0,0 +1,94 @@ +Example shortcode output.'; + + /** + * Number of times the shortcode was rendered. + * + * @var int + */ + protected $shortcode_render_count = 0; + + /** + * Sets up the test fixture. + */ + public function set_up() { + parent::set_up(); + add_shortcode( 'example', array( $this, 'do_example_shortcode' ) ); + } + + /** + * Tears down the test fixture. + */ + public function tear_down() { + remove_shortcode( 'example' ); + parent::tear_down(); + } + + /** + * Do example shortcode. + * + * @return string Shortcode content. + */ + public function do_example_shortcode() { + ++$this->shortcode_render_count; + return $this->example_shortcode_content; + } + + /** + * Tests that the `
` wrapper added during server-side rendering of the shortcode + * block is removed before do_shortcode() processes the shortcode. + * + * @ticket 62694 + * + * @covers WP_Widget_Block::widget + */ + public function test_widget_shortcode_unautop() { + $args = array( + 'before_title' => '
' . $this->example_shortcode_content . '
', + $output, + 'Expected shortcode_unautop() to have run.' + ); + } +}