WordPress.org

Make WordPress Core

Changeset 41117


Ignore:
Timestamp:
07/21/2017 09:16:58 PM (2 years ago)
Author:
westonruter
Message:

Widgets: Improve theme styling compatibility for Custom HTML widget by adding content container with textwidget class and widget_text class on widget wrapper element.

The same styling from the Text widget should apply to the Custom HTML widget since users are expected to copy HTML from the (legacy) Text widget into the latter.

Merges [41115] and partially [41116] onto 4.8 branch.
Amends [40893].
See #40907.
Fixes #41392 for 4.8.1.

Location:
branches/4.8
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

  • branches/4.8/src/wp-includes/default-widgets.php

    r41087 r41117  
    134134        $content = apply_filters( 'widget_custom_html_content', $content, $instance, $this );
    135135
     136        // Inject the Text widget's container class name alongside this widget's class name for theme styling compatibility.
     137        $args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/', 'widget_text ', $args['before_widget'] );
     138
    136139        echo $args['before_widget'];
    137140        if ( ! empty( $title ) ) {
    138141            echo $args['before_title'] . $title . $args['after_title'];
    139142        }
     143        echo '<div class="textwidget custom-html-widget">'; // The textwidget class is for theme styling compatibility.
    140144        echo $content;
     145        echo '</div>';
    141146        echo $args['after_widget'];
    142147    }
  • branches/4.8/tests/phpunit/tests/widgets/custom-html-widget.php

    r41087 r41117  
    5252            'before_title'  => '<h2>',
    5353            'after_title'   => "</h2>\n",
    54             'before_widget' => '<section>',
     54            'before_widget' => '<section id="custom_html-5" class="widget widget_custom_html">',
    5555            'after_widget'  => "</section>\n",
    5656        );
     
    7171        $this->assertNotEmpty( $this->widget_text_args );
    7272        $this->assertContains( '[filter:widget_text][filter:widget_custom_html_content]', $output );
     73        $this->assertContains( '<section id="custom_html-5" class="widget_text widget widget_custom_html">', $output );
     74        $this->assertContains( '<div class="textwidget custom-html-widget">', $output );
    7375        $this->assertNotContains( '<p>', $output );
    7476        $this->assertNotContains( '<br>', $output );
Note: See TracChangeset for help on using the changeset viewer.