From 85cb9e49637dc77e1acf66c459044f599a41846e Mon Sep 17 00:00:00 2001 From: audrasjb Date: Tue, 20 Sep 2022 10:31:14 +0000 Subject: [PATCH] Shortcodes: Reverse wrapping of `apply_shortcodes()` and `do_shortcode()`. This changeset reverses the wrapping of `apply_shortcodes()` and `do_shortcode()` such that `apply_shortcodes()` is now the recommended function. In addition: - Calls to `do_shortcode()` have been changed to `apply_shortcodes()`. - Some default filter callbacks have been changed from `'do_shortcode'` to `'apply_shortcodes'`. - Applicable documentation has been updated to refer to `apply_shortcodes()` instead. Follow-up to [47004]. Props SergeyBiryukov, rafiahmedd, namithjawahar, peterwilsoncc, costdev. Fixes #55883. Built from https://develop.svn.wordpress.org/trunk@54248 git-svn-id: http://core.svn.wordpress.org/trunk@53807 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/default-filters.php | 4 +- wp-includes/media.php | 4 +- wp-includes/shortcodes.php | 44 ++++++++++---------- wp-includes/version.php | 2 +- wp-includes/widgets/class-wp-widget-text.php | 10 ++--- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 9d8752caea..f60f8b222b 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 = do_shortcode( $parsed ); + $html = apply_shortcodes( $parsed ); global $wp_scripts; @@ -3861,7 +3861,7 @@ function wp_ajax_parse_media_shortcode() { setup_postdata( $post ); } - $parsed = do_shortcode( $shortcode ); + $parsed = apply_shortcodes( $shortcode ); if ( empty( $parsed ) ) { wp_send_json_error( diff --git a/wp-includes/block-template.php b/wp-includes/block-template.php index 0aa571117e..6f23ddbf83 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 = do_shortcode( $content ); + $content = apply_shortcodes( $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 8ce3483228..c0146b883d 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 do_shortcode(), and then re-registers the old shortcodes. + * calls apply_shortcodes(), 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 = do_shortcode( $content, true ); + $content = apply_shortcodes( $content, true ); // Put the original shortcodes back. $shortcode_tags = $orig_shortcode_tags; @@ -177,7 +177,7 @@ class WP_Embed { } /** - * The do_shortcode() callback function. + * The apply_shortcodes() 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/default-filters.php b/wp-includes/default-filters.php index 126d276417..f23872de30 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -228,7 +228,7 @@ add_filter( 'widget_text_content', 'do_shortcode', 11 ); // Runs after wpautop() add_filter( 'widget_block_content', 'do_blocks', 9 ); add_filter( 'widget_block_content', 'wp_filter_content_tags' ); -add_filter( 'widget_block_content', 'do_shortcode', 11 ); +add_filter( 'widget_block_content', 'apply_shortcodes', 11 ); add_filter( 'block_type_metadata', 'wp_migrate_old_typography_shape' ); @@ -605,7 +605,7 @@ add_action( 'template_redirect', 'redirect_canonical' ); add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 ); // Shortcodes. -add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop(). +add_filter( 'the_content', 'apply_shortcodes', 11 ); // AFTER wpautop(). // Media. add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' ); diff --git a/wp-includes/media.php b/wp-includes/media.php index 065efde579..a23a67381a 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 ), - do_shortcode( $content ), + apply_shortcodes( $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 938e796fa7..3d5efcab33 100644 --- a/wp-includes/shortcodes.php +++ b/wp-includes/shortcodes.php @@ -21,7 +21,7 @@ * * To apply shortcode tags to content: * - * $out = do_shortcode( $content ); + * $out = apply_shortcodes( $content ); * * @link https://developer.wordpress.org/plugins/shortcodes/ * @@ -168,24 +168,6 @@ 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. * @@ -193,7 +175,7 @@ function apply_shortcodes( $content, $ignore_html = false ) { * without any filtering. This might cause issues when plugins are disabled but * the shortcode will still show up in the post or content. * - * @since 2.5.0 + * @since 5.4.0 * * @global array $shortcode_tags List of shortcode tags and their callback hooks. * @@ -202,7 +184,7 @@ function apply_shortcodes( $content, $ignore_html = false ) { * Default false. * @return string Content with shortcodes filtered out. */ -function do_shortcode( $content, $ignore_html = false ) { +function apply_shortcodes( $content, $ignore_html = false ) { global $shortcode_tags; if ( false === strpos( $content, '[' ) ) { @@ -232,6 +214,24 @@ function do_shortcode( $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 do_shortcode() for calling shortcode hook. + * Regular Expression callable for apply_shortcodes() 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 f8ba31a87c..7bd1312ec9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54247'; +$wp_version = '6.1-alpha-54248'; /** * 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 7f28205c45..1a66ff8e17 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 do_shortcode() is added to the 'widget_text_content' filter in core itself + * shortcodes being processed twice. Now apply_shortcodes() 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 do_shortcode() will be manually called when in legacy mode as well. + * added to 'widget_text_content' then apply_shortcodes() 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 do_shortcode() to the 'widget_text_content' filter to apply after wpautop(). + * in core by adding apply_shortcodes() 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 do_shortcode() on the content unless the default + * legacy mode here manually applies apply_shortcodes() 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 = do_shortcode( $text ); + $text = apply_shortcodes( $text ); } }