Skip to content

Commit

Permalink
Shortcodes: Revert recent apply_shortcodes and do_shortcode changes.
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
dream-encode committed Sep 26, 2022
1 parent 2ae8079 commit 5eddc8f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3788,7 +3788,7 @@ function wp_ajax_parse_embed() {
$styles .= sprintf( '<link rel="stylesheet" href="%s" />', $style );
}

$html = apply_shortcodes( $parsed );
$html = do_shortcode( $parsed );

global $wp_scripts;

Expand Down Expand Up @@ -3861,7 +3861,7 @@ function wp_ajax_parse_media_shortcode() {
setup_postdata( $post );
}

$parsed = apply_shortcodes( $shortcode );
$parsed = do_shortcode( $shortcode );

if ( empty( $parsed ) ) {
wp_send_json_error(
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function get_the_block_template_html() {
$content = convert_smilies( $content );
$content = shortcode_unautop( $content );
$content = wp_filter_content_tags( $content );
$content = apply_shortcodes( $content );
$content = do_shortcode( $content );
$content = str_replace( ']]>', ']]&gt;', $content );

// Wrap block template in .wp-site-blocks to allow for specific descendant styles
Expand Down
6 changes: 3 additions & 3 deletions src/wp-includes/class-wp-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct() {
*
* Since the [embed] shortcode needs to be run earlier than other shortcodes,
* this function removes all existing shortcodes, registers the [embed] shortcode,
* calls apply_shortcodes(), and then re-registers the old shortcodes.
* calls do_shortcode(), and then re-registers the old shortcodes.
*
* @global array $shortcode_tags
*
Expand All @@ -69,7 +69,7 @@ public function run_shortcode( $content ) {
add_shortcode( 'embed', array( $this, 'shortcode' ) );

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

// Put the original shortcodes back.
$shortcode_tags = $orig_shortcode_tags;
Expand Down Expand Up @@ -177,7 +177,7 @@ public function get_embed_handler_html( $attr, $url ) {
}

/**
* The apply_shortcodes() callback function.
* The do_shortcode() callback function.
*
* Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of
* the registered embed handlers. If none of the regex matches and it's enabled, then the URL
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ function img_caption_shortcode( $attr, $content = '' ) {
$describedby,
$style,
esc_attr( $class ),
apply_shortcodes( $content ),
do_shortcode( $content ),
sprintf(
'<figcaption %sclass="wp-caption-text">%s</figcaption>',
$caption_id,
Expand All @@ -2309,7 +2309,7 @@ function img_caption_shortcode( $attr, $content = '' ) {
$id,
$style,
esc_attr( $class ),
str_replace( '<img ', '<img ' . $describedby, apply_shortcodes( $content ) ),
str_replace( '<img ', '<img ' . $describedby, do_shortcode( $content ) ),
sprintf(
'<p %sclass="wp-caption-text">%s</p>',
$caption_id,
Expand Down
44 changes: 22 additions & 22 deletions src/wp-includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* To apply shortcode tags to content:
*
* $out = apply_shortcodes( $content );
* $out = do_shortcode( $content );
*
* @link https://developer.wordpress.org/plugins/shortcodes/
*
Expand Down Expand Up @@ -168,14 +168,32 @@ function has_shortcode( $content, $tag ) {
return false;
}

/**
* Searches content for shortcodes and filter shortcodes through their hooks.
*
* This function is an alias for do_shortcode().
*
* @since 5.4.0
*
* @see do_shortcode()
*
* @param string $content Content to search for shortcodes.
* @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
* Default false.
* @return string Content with shortcodes filtered out.
*/
function apply_shortcodes( $content, $ignore_html = false ) {
return do_shortcode( $content, $ignore_html );
}

/**
* Searches content for shortcodes and filter shortcodes through their hooks.
*
* If there are no shortcode tags defined, then the content will be returned
* without any filtering. This might cause issues when plugins are disabled but
* the shortcode will still show up in the post or content.
*
* @since 5.4.0
* @since 2.5.0
*
* @global array $shortcode_tags List of shortcode tags and their callback hooks.
*
Expand All @@ -184,7 +202,7 @@ function has_shortcode( $content, $tag ) {
* Default false.
* @return string Content with shortcodes filtered out.
*/
function apply_shortcodes( $content, $ignore_html = false ) {
function do_shortcode( $content, $ignore_html = false ) {
global $shortcode_tags;

if ( false === strpos( $content, '[' ) ) {
Expand Down Expand Up @@ -214,24 +232,6 @@ function apply_shortcodes( $content, $ignore_html = false ) {
return $content;
}

/**
* Searches content for shortcodes and filter shortcodes through their hooks.
*
* This function is an alias for apply_shortcodes().
*
* @since 2.5.0
*
* @see apply_shortcodes()
*
* @param string $content Content to search for shortcodes.
* @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped.
* Default false.
* @return string Content with shortcodes filtered out.
*/
function do_shortcode( $content, $ignore_html = false ) {
return apply_shortcodes( $content, $ignore_html );
}

/**
* Retrieves the shortcode regular expression for searching.
*
Expand Down Expand Up @@ -299,7 +299,7 @@ function get_shortcode_regex( $tagnames = null ) {
}

/**
* Regular Expression callable for apply_shortcodes() for calling shortcode hook.
* Regular Expression callable for do_shortcode() for calling shortcode hook.
*
* @see get_shortcode_regex() for details of the match array contents.
*
Expand Down
10 changes: 5 additions & 5 deletions src/wp-includes/widgets/class-wp-widget-text.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public function widget( $args, $instance ) {

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

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

Expand Down

0 comments on commit 5eddc8f

Please sign in to comment.