Make WordPress Core


Ignore:
Timestamp:
09/20/2022 10:29:55 AM (2 years ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-text.php

    r52978 r54248  
    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 do_shortcode() is added to the 'widget_text_content' filter in core itself
     247         * shortcodes being processed twice. Now apply_shortcodes() 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 do_shortcode() will be manually called when in legacy mode as well.
     249         * added to 'widget_text_content' then apply_shortcodes() will be manually called when in legacy mode as well.
    250250         */
    251251        $widget_text_do_shortcode_priority       = has_filter( 'widget_text', 'do_shortcode' );
     
    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 do_shortcode() to the 'widget_text_content' filter to apply after wpautop().
     305             * in core by adding apply_shortcodes() 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 do_shortcode() on the content unless the default
     307             * legacy mode here manually applies apply_shortcodes() 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.
     
    313313                    $text = shortcode_unautop( $text );
    314314                }
    315                 $text = do_shortcode( $text );
     315                $text = apply_shortcodes( $text );
    316316            }
    317317        }
Note: See TracChangeset for help on using the changeset viewer.