Skip to content

Commit 5eddc8f

Browse files
committed
Shortcodes: Revert recent apply_shortcodes and do_shortcode changes.
[54248] reversed the wrapping of `do_shortcode` and `apply_shortcodes` and updated all direct internal calls of `do_shortcode` to `apply_shortcodes` after [47004]. After further consideration, the long history of `do_shortcodes` should be favored over any subjective semantic improvements. This change reverts the remaining changes from #55883 not already reverted in [54278]. Follow-up to [47004], [54248], and [54278]. Props azaozz, jorbin. See #55883. git-svn-id: https://develop.svn.wordpress.org/trunk@54319 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2ae8079 commit 5eddc8f

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

src/wp-admin/includes/ajax-actions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,7 +3788,7 @@ function wp_ajax_parse_embed() {
37883788
$styles .= sprintf( '<link rel="stylesheet" href="%s" />', $style );
37893789
}
37903790

3791-
$html = apply_shortcodes( $parsed );
3791+
$html = do_shortcode( $parsed );
37923792

37933793
global $wp_scripts;
37943794

@@ -3861,7 +3861,7 @@ function wp_ajax_parse_media_shortcode() {
38613861
setup_postdata( $post );
38623862
}
38633863

3864-
$parsed = apply_shortcodes( $shortcode );
3864+
$parsed = do_shortcode( $shortcode );
38653865

38663866
if ( empty( $parsed ) ) {
38673867
wp_send_json_error(

src/wp-includes/block-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function get_the_block_template_html() {
242242
$content = convert_smilies( $content );
243243
$content = shortcode_unautop( $content );
244244
$content = wp_filter_content_tags( $content );
245-
$content = apply_shortcodes( $content );
245+
$content = do_shortcode( $content );
246246
$content = str_replace( ']]>', ']]&gt;', $content );
247247

248248
// Wrap block template in .wp-site-blocks to allow for specific descendant styles

src/wp-includes/class-wp-embed.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct() {
5252
*
5353
* Since the [embed] shortcode needs to be run earlier than other shortcodes,
5454
* this function removes all existing shortcodes, registers the [embed] shortcode,
55-
* calls apply_shortcodes(), and then re-registers the old shortcodes.
55+
* calls do_shortcode(), and then re-registers the old shortcodes.
5656
*
5757
* @global array $shortcode_tags
5858
*
@@ -69,7 +69,7 @@ public function run_shortcode( $content ) {
6969
add_shortcode( 'embed', array( $this, 'shortcode' ) );
7070

7171
// Do the shortcode (only the [embed] one is registered).
72-
$content = apply_shortcodes( $content, true );
72+
$content = do_shortcode( $content, true );
7373

7474
// Put the original shortcodes back.
7575
$shortcode_tags = $orig_shortcode_tags;
@@ -177,7 +177,7 @@ public function get_embed_handler_html( $attr, $url ) {
177177
}
178178

179179
/**
180-
* The apply_shortcodes() callback function.
180+
* The do_shortcode() callback function.
181181
*
182182
* Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of
183183
* the registered embed handlers. If none of the regex matches and it's enabled, then the URL

src/wp-includes/media.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,7 @@ function img_caption_shortcode( $attr, $content = '' ) {
22962296
$describedby,
22972297
$style,
22982298
esc_attr( $class ),
2299-
apply_shortcodes( $content ),
2299+
do_shortcode( $content ),
23002300
sprintf(
23012301
'<figcaption %sclass="wp-caption-text">%s</figcaption>',
23022302
$caption_id,
@@ -2309,7 +2309,7 @@ function img_caption_shortcode( $attr, $content = '' ) {
23092309
$id,
23102310
$style,
23112311
esc_attr( $class ),
2312-
str_replace( '<img ', '<img ' . $describedby, apply_shortcodes( $content ) ),
2312+
str_replace( '<img ', '<img ' . $describedby, do_shortcode( $content ) ),
23132313
sprintf(
23142314
'<p %sclass="wp-caption-text">%s</p>',
23152315
$caption_id,

src/wp-includes/shortcodes.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* To apply shortcode tags to content:
2323
*
24-
* $out = apply_shortcodes( $content );
24+
* $out = do_shortcode( $content );
2525
*
2626
* @link https://developer.wordpress.org/plugins/shortcodes/
2727
*
@@ -168,14 +168,32 @@ function has_shortcode( $content, $tag ) {
168168
return false;
169169
}
170170

171+
/**
172+
* Searches content for shortcodes and filter shortcodes through their hooks.
173+
*
174+
* This function is an alias for do_shortcode().
175+
*
176+
* @since 5.4.0
177+
*
178+
* @see do_shortcode()
179+
*
180+
* @param string $content Content to search for shortcodes.
181+
* @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
182+
* Default false.
183+
* @return string Content with shortcodes filtered out.
184+
*/
185+
function apply_shortcodes( $content, $ignore_html = false ) {
186+
return do_shortcode( $content, $ignore_html );
187+
}
188+
171189
/**
172190
* Searches content for shortcodes and filter shortcodes through their hooks.
173191
*
174192
* If there are no shortcode tags defined, then the content will be returned
175193
* without any filtering. This might cause issues when plugins are disabled but
176194
* the shortcode will still show up in the post or content.
177195
*
178-
* @since 5.4.0
196+
* @since 2.5.0
179197
*
180198
* @global array $shortcode_tags List of shortcode tags and their callback hooks.
181199
*
@@ -184,7 +202,7 @@ function has_shortcode( $content, $tag ) {
184202
* Default false.
185203
* @return string Content with shortcodes filtered out.
186204
*/
187-
function apply_shortcodes( $content, $ignore_html = false ) {
205+
function do_shortcode( $content, $ignore_html = false ) {
188206
global $shortcode_tags;
189207

190208
if ( false === strpos( $content, '[' ) ) {
@@ -214,24 +232,6 @@ function apply_shortcodes( $content, $ignore_html = false ) {
214232
return $content;
215233
}
216234

217-
/**
218-
* Searches content for shortcodes and filter shortcodes through their hooks.
219-
*
220-
* This function is an alias for apply_shortcodes().
221-
*
222-
* @since 2.5.0
223-
*
224-
* @see apply_shortcodes()
225-
*
226-
* @param string $content Content to search for shortcodes.
227-
* @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
228-
* Default false.
229-
* @return string Content with shortcodes filtered out.
230-
*/
231-
function do_shortcode( $content, $ignore_html = false ) {
232-
return apply_shortcodes( $content, $ignore_html );
233-
}
234-
235235
/**
236236
* Retrieves the shortcode regular expression for searching.
237237
*
@@ -299,7 +299,7 @@ function get_shortcode_regex( $tagnames = null ) {
299299
}
300300

301301
/**
302-
* Regular Expression callable for apply_shortcodes() for calling shortcode hook.
302+
* Regular Expression callable for do_shortcode() for calling shortcode hook.
303303
*
304304
* @see get_shortcode_regex() for details of the match array contents.
305305
*

src/wp-includes/widgets/class-wp-widget-text.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ public function widget( $args, $instance ) {
244244

245245
/*
246246
* Suspend legacy plugin-supplied do_shortcode() for 'widget_text' filter for the visual Text widget to prevent
247-
* shortcodes being processed twice. Now apply_shortcodes() is added to the 'widget_text_content' filter in core itself
247+
* shortcodes being processed twice. Now do_shortcode() is added to the 'widget_text_content' filter in core itself
248248
* and it applies after wpautop() to prevent corrupting HTML output added by the shortcode. When do_shortcode() is
249-
* added to 'widget_text_content' then apply_shortcodes() will be manually called when in legacy mode as well.
249+
* added to 'widget_text_content' then do_shortcode() will be manually called when in legacy mode as well.
250250
*/
251251
$widget_text_do_shortcode_priority = has_filter( 'widget_text', 'do_shortcode' );
252252
$should_suspend_legacy_shortcode_support = ( $is_visual_text_widget && false !== $widget_text_do_shortcode_priority );
@@ -302,17 +302,17 @@ public function widget( $args, $instance ) {
302302

303303
/*
304304
* Manually do shortcodes on the content when the core-added filter is present. It is added by default
305-
* in core by adding apply_shortcodes() to the 'widget_text_content' filter to apply after wpautop().
305+
* in core by adding do_shortcode() to the 'widget_text_content' filter to apply after wpautop().
306306
* Since the legacy Text widget runs wpautop() after 'widget_text' filters are applied, the widget in
307-
* legacy mode here manually applies apply_shortcodes() on the content unless the default
307+
* legacy mode here manually applies do_shortcode() on the content unless the default
308308
* core filter for 'widget_text_content' has been removed, or if do_shortcode() has already
309309
* been applied via a plugin adding do_shortcode() to 'widget_text' filters.
310310
*/
311311
if ( has_filter( 'widget_text_content', 'do_shortcode' ) && ! $widget_text_do_shortcode_priority ) {
312312
if ( ! empty( $instance['filter'] ) ) {
313313
$text = shortcode_unautop( $text );
314314
}
315-
$text = apply_shortcodes( $text );
315+
$text = do_shortcode( $text );
316316
}
317317
}
318318

0 commit comments

Comments
 (0)