WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/09/2018 08:28:40 AM (3 years ago)
Author:
pento
Message:

Formatting: Ensure wpautop() isn't run on content generated from blocks.

As do_blocks() is run before wpautop() in the_content filter, we can remove in a Just In Time fashion, before that filter is run.

After wpautop()s original priority has passed, we can re-add it in a Just Too Late fashion, to ensure it's available if the_content filter is run multiple times on a page load.

Props pento, nerrad.
Fixes #45290.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/tests/phpunit/tests/blocks/render.php

    r43752 r43879  
    8181    function handle_shortcode( $atts, $content ) {
    8282        return $content;
     83    }
     84
     85    /**
     86     * @ticket 45290
     87     */
     88    public function test_blocks_arent_autopeed() {
     89        $expected_content = 'test';
     90        $test_content     = "<!-- wp:fake/block -->\n$expected_content\n<!-- /wp:fake/block -->";
     91
     92        $current_priority = has_action( 'the_content', 'wpautop' );
     93
     94        $filtered_content = trim( apply_filters( 'the_content', $test_content ) );
     95
     96        $this->assertEquals( $expected_content, $filtered_content );
     97
     98        // Check that wpautop() is still defined in the same place.
     99        $this->assertSame( $current_priority, has_action( 'the_content', 'wpautop' ) );
     100        // ... and that the restore function has removed itself.
     101        $this->assertFalse( has_action( 'the_content', '_restore_wpautop_hook' ) );
     102
     103        $test_content     = 'test';
     104        $expected_content = "<p>$test_content</p>";
     105
     106        $current_priority = has_action( 'the_content', 'wpautop' );
     107
     108        $filtered_content = trim( apply_filters( 'the_content', $test_content ) );
     109
     110        $this->assertEquals( $expected_content, $filtered_content );
     111
     112        $this->assertSame( $current_priority, has_action( 'the_content', 'wpautop' ) );
     113        $this->assertFalse( has_action( 'the_content', '_restore_wpautop_hook' ) );
    83114    }
    84115
Note: See TracChangeset for help on using the changeset viewer.