You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Widgets: Add shortcode support inside Text widgets.
* Used now in core to facilitate displaying inserted media. See #40854.
* The `[embed]` shortcode is not supported because there is no post context for caching oEmbed responses. This depends on #34115.
* Add `do_shortcode()` to the `widget_text_content` filter in the same way it is added for `the_content` at priority 11, with `shortcode_unautop()` called at priority 10 after `wpautop()`.
* For Text widget in legacy mode, manually apply `do_shortcode()` (and `shortcode_unautop()` if auto-paragraph checked) if the core-added `widget_text_content` filter remains, unless a plugin added `do_shortcode()` to `widget_text` to prevent applying shortcodes twice.
* Ensure that global `$post` is `null` while filters apply in the Text widget so shortcode handlers won't run with unexpected contexts.
Props westonruter, nacin, aaroncampbell.
See #40854, #34115.
FixesWordPress#10457.
git-svn-id: https://develop.svn.wordpress.org/trunk@41361 602fd350-edb4-49c9-b593-d223f7449a82
protected$example_shortcode_content = "<p class='sortcodep'>One\nTwo\n\nThree\n\nThis is testing the <code>[example note='This will not get processed since it is part of shortcode output itself.']</code> shortcode.</p>\n<script>\ndocument.write('Test1');\n\ndocument.write('Test2');\n</script>";
226
+
227
+
/**
228
+
* The captured global post during shortcode rendering.
229
+
*
230
+
* @var WP_Post|null
231
+
*/
232
+
protected$post_during_shortcode = null;
233
+
234
+
/**
235
+
* Number of times the shortcode was rendered.
236
+
*
237
+
* @var int
238
+
*/
239
+
protected$shortcode_render_count = 0;
226
240
227
241
/**
228
242
* Do example shortcode.
229
243
*
230
244
* @return string Shortcode content.
231
245
*/
232
246
functiondo_example_shortcode() {
247
+
$this->post_during_shortcode = get_post();
248
+
$this->shortcode_render_count++;
233
249
return$this->example_shortcode_content;
234
250
}
235
251
236
252
/**
237
-
* Test widget method when a plugin has added shortcode support.
$this->assertNotContains( '[example]', $output, 'Expected shortcode to be processed in legacy widget with plugin adding filter' );
314
+
$this->assertContains( wpautop( $this->example_shortcode_content ), $output, 'Shortcode was applied *with* wpautop() applying to shortcode output since plugin used legacy filter.' );
$this->assertEquals( 11, has_filter( 'widget_text_content', 'do_shortcode' ), 'Expected core to have set do_shortcode as widget_text_content filter.' );
0 commit comments