From b266a2d5358dc1168133ea5bf1c02a42dd022d3b Mon Sep 17 00:00:00 2001 From: davidbaumwald Date: Mon, 26 Sep 2022 22:43:10 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@54319 git-svn-id: http://core.svn.wordpress.org/trunk@53878 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 4 +- wp-includes/block-template.php | 2 +- wp-includes/class-wp-embed.php | 6 +-- wp-includes/media.php | 4 +- wp-includes/shortcodes.php | 44 ++++++++++---------- wp-includes/version.php | 2 +- wp-includes/widgets/class-wp-widget-text.php | 10 ++--- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index f60f8b222b..9d8752caea 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -3788,7 +3788,7 @@ function wp_ajax_parse_embed() { $styles .= sprintf( '', $style ); } - $html = apply_shortcodes( $parsed ); + $html = do_shortcode( $parsed ); global $wp_scripts; @@ -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( diff --git a/wp-includes/block-template.php b/wp-includes/block-template.php index 6f23ddbf83..0aa571117e 100644 --- a/wp-includes/block-template.php +++ b/wp-includes/block-template.php @@ -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( ']]>', ']]>', $content ); // Wrap block template in .wp-site-blocks to allow for specific descendant styles diff --git a/wp-includes/class-wp-embed.php b/wp-includes/class-wp-embed.php index c0146b883d..8ce3483228 100644 --- a/wp-includes/class-wp-embed.php +++ b/wp-includes/class-wp-embed.php @@ -52,7 +52,7 @@ class WP_Embed { * * 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 * @@ -69,7 +69,7 @@ class WP_Embed { 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; @@ -177,7 +177,7 @@ class WP_Embed { } /** - * 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 diff --git a/wp-includes/media.php b/wp-includes/media.php index a23a67381a..065efde579 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -2296,7 +2296,7 @@ function img_caption_shortcode( $attr, $content = '' ) { $describedby, $style, esc_attr( $class ), - apply_shortcodes( $content ), + do_shortcode( $content ), sprintf( '
%s
', $caption_id, @@ -2309,7 +2309,7 @@ function img_caption_shortcode( $attr, $content = '' ) { $id, $style, esc_attr( $class ), - str_replace( '%s

', $caption_id, diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php index 3d5efcab33..938e796fa7 100644 --- a/wp-includes/shortcodes.php +++ b/wp-includes/shortcodes.php @@ -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/ * @@ -168,6 +168,24 @@ 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. * @@ -175,7 +193,7 @@ function has_shortcode( $content, $tag ) { * 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. * @@ -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, '[' ) ) { @@ -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. * @@ -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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 0e9bad56d6..0e4ea386d6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta1-54318'; +$wp_version = '6.1-beta1-54319'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/widgets/class-wp-widget-text.php b/wp-includes/widgets/class-wp-widget-text.php index 1a66ff8e17..7f28205c45 100644 --- a/wp-includes/widgets/class-wp-widget-text.php +++ b/wp-includes/widgets/class-wp-widget-text.php @@ -244,9 +244,9 @@ class WP_Widget_Text extends WP_Widget { /* * 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 ); @@ -302,9 +302,9 @@ class WP_Widget_Text extends WP_Widget { /* * 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. */ @@ -312,7 +312,7 @@ class WP_Widget_Text extends WP_Widget { if ( ! empty( $instance['filter'] ) ) { $text = shortcode_unautop( $text ); } - $text = apply_shortcodes( $text ); + $text = do_shortcode( $text ); } }