Make WordPress Core

Changeset 41070


Ignore:
Timestamp:
07/18/2017 04:16:16 AM (7 years ago)
Author:
westonruter
Message:

Widgets: Discount shortcodes and leading/trailing line breaks for triggering Text widget legacy mode.

Since plugin-added shortcode handling is just-in-time deferred to run after wpautop, there is no need to retain the presence of shortcodes to trigger legacy mode. Also updates Text widget legacy mode notice informing of Custom HTML widget.

Amends [41050].
Props westonruter, melchoyce.
Fixes #40951 for trunk.

Location:
trunk
Files:
2 edited

Legend:

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

    r41050 r41070  
    9696
    9797        $wpautop = ! empty( $instance['filter'] );
    98         $has_line_breaks = ( false !== strpos( $instance['text'], "\n" ) );
     98        $has_line_breaks = ( false !== strpos( trim( $instance['text'] ), "\n" ) );
    9999
    100100        // If auto-paragraphs are not enabled and there are line breaks, then ensure legacy mode.
     
    105105        // If an HTML comment is present, assume legacy mode.
    106106        if ( false !== strpos( $instance['text'], '<!--' ) ) {
    107             return true;
    108         }
    109 
    110         /*
    111          * If a shortcode is present (with support added by a plugin), assume legacy mode
    112          * since shortcodes would apply at the widget_text filter and thus be applied
    113          * before wpautop runs at the widget_text_content filter.
    114          */
    115         if ( preg_match( '/' . get_shortcode_regex() . '/', $instance['text'] ) ) {
    116107            return true;
    117108        }
     
    349340            </p>
    350341            <div class="notice inline notice-info notice-alt">
    351                 <p><?php _e( 'This widget contains code that may work better in the new &#8220;Custom HTML&#8221; widget. How about trying that widget instead?' ); ?></p>
     342                <p><?php _e( 'This widget may contain code that may work better in the new &#8220;Custom HTML&#8221; widget. How about trying that widget instead?' ); ?></p>
    352343            </div>
    353344            <p>
  • trunk/tests/phpunit/tests/widgets/text-widget.php

    r41050 r41070  
    267267
    268268        $instance = array_merge( $base_instance, array(
     269            'text' => "\nOne line",
     270            'filter' => false,
     271        ) );
     272        $this->assertFalse( $widget->is_legacy_instance( $instance ), 'Not legacy when there is leading whitespace.' );
     273
     274        $instance = array_merge( $base_instance, array(
     275            'text' => "\nOne line\n\n",
     276            'filter' => false,
     277        ) );
     278        $this->assertFalse( $widget->is_legacy_instance( $instance ), 'Not legacy when there is trailing whitespace.' );
     279
     280        $instance = array_merge( $base_instance, array(
    269281            'text' => "One\nTwo",
    270282            'filter' => false,
     
    295307        ) );
    296308        $this->assertTrue( $widget->is_legacy_instance( $instance ), 'Legacy when HTML comment is present.' );
    297 
    298         $instance = array_merge( $base_instance, array(
    299             'text' => 'Here is a [gallery]',
    300             'filter' => true,
    301         ) );
    302         $this->assertTrue( $widget->is_legacy_instance( $instance ), 'Legacy mode when a shortcode is present.' );
    303309
    304310        // Check text examples that will not migrate to TinyMCE.
Note: See TracChangeset for help on using the changeset viewer.