WordPress.org

Make WordPress Core

Changeset 41779


Ignore:
Timestamp:
10/06/17 00:38:57 (6 weeks ago)
Author:
westonruter
Message:

Widgets: Apply the same container-constraining embed resizing logic from the Video widget to embeds in the Text widget.

See #40854, #39994.

File:
1 edited

Legend:

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

    r41577 r41779  
    291291        } 
    292292 
     293        $text = preg_replace_callback( '#<[^>]*>#', array( $this, 'inject_video_max_width_style' ), $text ); 
     294 
    293295        ?> 
    294296            <div class="textwidget"><?php echo $text; ?></div> 
    295297        <?php 
    296298        echo $args['after_widget']; 
     299    } 
     300 
     301    /** 
     302     * Inject max-width and remove height for videos too constrained to fit inside sidebars on frontend. 
     303     * 
     304     * @since 4.9.0 
     305     * 
     306     * @see WP_Widget_Media_Video::inject_video_max_width_style() 
     307     * @param array $matches Pattern matches from preg_replace_callback. 
     308     * @return string HTML Output. 
     309     */ 
     310    public function inject_video_max_width_style( $matches ) { 
     311        $html = $matches[0]; 
     312        $html = preg_replace( '/\sheight="\d+"/', '', $html ); 
     313        $html = preg_replace( '/\swidth="\d+"/', '', $html ); 
     314        $html = preg_replace( '/(?<=width:)\s*\d+px(?=;?)/', '100%', $html ); 
     315        return $html; 
    297316    } 
    298317 
Note: See TracChangeset for help on using the changeset viewer.