Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jul 29, 2016

Conversation

Projects
None yet
3 participants
@rinatkhaziev
Copy link
Contributor

commented Jul 25, 2016

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.

Don't call wpautop directly when trying to prepare content for transf…
…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

This comment has been minimized.

Copy link
Collaborator

commented Jul 26, 2016

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

@rinatkhaziev

This comment has been minimized.

Copy link
Contributor Author

commented Jul 26, 2016

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 join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.