Opened 10 years ago
Last modified 7 weeks ago
#37672 new defect (bug)
wpautop adds a closing p-tag without an opening p-tag
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 4.5.3 |
| Component: | Formatting | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
Following code result in ill-formed HTML.
<?php $pee = <<<EOT <div> This is a paragraph. This is another paragraph. </div> EOT; echo wpautop($pee);
This is the output:
<div> This is a paragraph.</p> <p>This is another paragraph. </p></div>
As you can see, the first paragraph lacks an opening <p>.
Attachments (1)
Change History (8)
#3
@
9 years ago
@TBarregren
Thank for your report - I can reproduce this with a unit test and I think I've also managed to create a fix in the 'wpautop()' function. Patch and Unit test attached above.
#5
@
7 years ago
- Keywords needs-refresh added
@MattyRob are you able to refresh 37672.diff to apply cleanly to trunk? Having a unit test demonstrating the issue may help others dive in.
This ticket was mentioned in PR #9262 on WordPress/wordpress-develop by @lakshyajeet.
8 months ago
#6
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/37672
Code used in testing:
function wpautop_test_shortcode() {
$text = <<<EOT
<div>
This is a paragraph.
This is another paragraph.
</div>
EOT;
return wpautop($text);
}
add_shortcode('wpautop_test', 'wpautop_test_shortcode');
#7
@
7 weeks ago
- Keywords needs-testing removed
Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/9262
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 144.0.0.0
- OS: macOS
- Theme: Twenty Twenty-One 2.7
- MU Plugins: None activated
- Plugins:
- Classic Editor 1.6.7
- Code Snippets 3.9.4
- Test Reports 1.2.1
Steps taken
- Create a sample shortcode with the following code using Code Snippets plugin or functions.php
function wpautop_test_shortcode() {
$text = <<<EOT
<div>
This is a paragraph.
This is another paragraph.
</div>
EOT;
return wpautop($text);
}
add_shortcode('wpautop_test', 'wpautop_test_shortcode');
- Create a new page / post
- Add the shortcode
[wpautop_test]to the page content and publish - View the post in frontend and check the source code
- Apply the patch
- View the post in frontend and check the source code again
- ✅ Patch is solving the problem
Expected result
- After applying the patch
ptags are correctly added to the shortcode content.
Screenshots/Screencast with results
Note: See
TracTickets for help on using
tickets.


If it is to any help, this is my function.php code to solve this (and related) problem(s).