Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Don't call wpautop directly when trying to prepare content for transformation. #379

Merged
merged 1 commit into from
Jul 29, 2016

Conversation

rinatkhaziev
Copy link
Contributor

Instead check whether wpautop is attached for 'the_content' and if it's not, add it. The reason for this is that we applied the_content filters already, and the shortcodes were rendered. Calling wpautop after shortcodes are rendered will mangle most of them, unless shortcode returns 1 line of code.

…ormation, instead check whether wpautop is attached for 'the_content' and if it's not, add it. The reason for this is that we applied the_content filters already, and the shortcodes were rendered. Calling wpautop after shortcodes are rendered will mangle most of them, unless shortcode returns 1 line of code
@everton-rosario
Copy link
Collaborator

@rinatkhaziev how are the reproducible steps for the problem you've pointed out?

@rinatkhaziev
Copy link
Contributor Author

Hey @everton-rosario, sure thing, here's quick and dirty test

add_action( 'init', function() {
    $test_content = "
    About wpautop
    About wpautop2

    About wpautop3

    About wpautop4

    [test-sc]
        ";

    $filtered = apply_filters( 'the_content', $test_content ) ;
    var_dump( "input string: \n\n" . $test_content );
    var_dump( "Expected output: \n\n" . $filtered, "\n\n", "wpautop'd after shortcode \n\n" . wpautop( $filtered ) );
    exit;

});

add_shortcode( 'test-sc', function( $atts, $content ) {
    return "
    <script>

    console.log('autop');

    console.log('autop');

    console.log('autop');

    </script>
    ";
} );

and the output:

string 'input string: 


About wpautop
About wpautop2

About wpautop3

About wpautop4

[test-sc]
    ' (length=90)
string 'Expected output: 

<p>About wpautop<br />
About wpautop2</p>
<p>About wpautop3</p>
<p>About wpautop4</p>

<script>

console.log('autop');

console.log('autop');

console.log('autop');

</script>

' (length=197)
string '

' (length=2)
string 'wpautop'd after shortcode 

<p>About wpautop<br />
About wpautop2</p>
<p>About wpautop3</p>
<p>About wpautop4</p>
<p><script></p>
<p>console.log('autop');</p>
<p>console.log('autop');</p>
<p>console.log('autop');</p>
<p></script></p>
' (length=234)

@everton-rosario everton-rosario merged commit 9295783 into Automattic:master Jul 29, 2016
@diegoquinteiro diegoquinteiro added this to the 3.1 milestone Aug 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants