-
Notifications
You must be signed in to change notification settings - Fork 62
Plugin handbook shortcode example code is incorrect #17
Copy link
Copy link
Closed
Labels
developer documentation (DevHub)Improvements or additions to developer documentationImprovements or additions to developer documentationpluginsIssues for Plugin Developer HandbookIssues for Plugin Developer Handbook
Description
This issue was moved from HelpHub issue #314 reported by oskar-fagerfjall.
Issue Description
In the Shortcodes with Parameters chapter in the plugin handbook, the complete example at the end is incorrect. It works fine for shortcodes without content, but when adding content that content is echoed twice.
Context
The problematic code is the following
if ( ! is_null( $content ) ) {
// secure output by executing the_content filter hook on $content
$o .= apply_filters( 'the_content', $content );
// run shortcode parser recursively
$o .= do_shortcode( $content );
}This code appends the content variable to the output twice, once without running the shortcode parser recursively, and once without properly securing the output.
Steps to reproduce:
- Copy the example code into a plugin
- Activate the plugin
- Make a new post containing
[wporg title="A"][wporg title="B"]test[/wporg][/wporg] - Preview the post
Expected Result:
The shortcode should result in
<div><h2>A</h2><div><h2>B</h2>test</div></div>Actual Result:
The shortcode results in
<div><h2>A</h2><div><h2>B</h2></div>test<div><h2>B</h2></div>test</div>[/wporg]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
developer documentation (DevHub)Improvements or additions to developer documentationImprovements or additions to developer documentationpluginsIssues for Plugin Developer HandbookIssues for Plugin Developer Handbook
Type
Fields
Give feedbackNo fields configured for issues without a type.