WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.56k stars 4.22k forks source link

Template part - inconsistent / unwanted removal of `<p>` tag by `shortcode_unautop()` #33345

Open bobbingwide opened 3 years ago

bobbingwide commented 3 years ago

Description

While attempting to build a metadates block template part to display the Published and Last updated dates in a grid layout I noticed some styling problems and determined that in some instances the shortcode_unautop() call in template-part.php was responsible. Its continued use in Gutenberg was questioned in #26809.

I wrote a post to demonstrate the problem. The fix is simple. Remove the call to shortcode_unautop().

Step-by-step reproduction instructions

See the video.

Expected behaviour

<p> tags from paragraph blocks should not be removed programmatically by shortcode_unautop().

Actual behaviour

When a template part is used from a custom template some <p> tags are removed programmatically by shortcode_unautop().

Screenshots or screen recording (optional)

image image image

Code snippet (optional)

Commenting out the call to shortcode_unautop() resolves the issue.

C:\apache\htdocs\hm\wp-content\plugins\gutenberg>git diff -w build/block-library/blocks/template-part.php
diff --git a/build/block-library/blocks/template-part.php b/build/block-library/blocks/template-part.php
index 2e020f3e..900f8f00 100644
--- a/build/block-library/blocks/template-part.php
+++ b/build/block-library/blocks/template-part.php
@@ -90,14 +90,13 @@ function gutenberg_render_block_core_template_part( $attributes ) {
        unset( $seen_ids[ $template_part_id ] );
        $content = wptexturize( $content );
        $content = convert_smilies( $content );
-       $content = shortcode_unautop( $content );
+       //$content = shortcode_unautop( $content );
        if ( function_exists( 'wp_filter_content_tags' ) ) {
                $content = wp_filter_content_tags( $content );
        } else {
                $content = wp_make_content_images_responsive( $content );
        }
        $content = do_shortcode( $content );
-
        // Handle embeds for block template parts.
        global $wp_embed;
        $content = $wp_embed->autoembed( $content );

image

WordPress information

Device information

bobbingwide commented 3 years ago

https://user-images.githubusercontent.com/2474435/125204327-97745780-e274-11eb-9cd9-771526de5c49.mp4