Make WordPress Core

Ticket #30201: 30201.patch

File 30201.patch, 1.2 KB (added by polevaultweb, 11 years ago)

This patch adds a right margin of 10px when a percentage width is returned from the filter. This is my first patch/contribution/trac usage so go easy :)

  • src/wp-includes/media.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    875875        $caption_width = apply_filters( 'img_caption_shortcode_width', $caption_width, $atts, $content );
    876876
    877877        $style = '';
    878         if ( $caption_width )
    879                 $style = 'style="width: ' . (int) $caption_width . 'px" ';
     878        if ( $caption_width ) {
     879                $margin = '';
     880                $caption_width_unit = 'px';
     881                if ( '%' == substr( $caption_width, - 1 ) ) {
     882                        $caption_width      = (int) substr( $caption_width, 0, - 1 );
     883                        $caption_width_unit = '%';
     884                        // for widths less than 100% we need to add a right margin of 10 pixels
     885                        // to prevent post content from running up against a floated image
     886                        if ( $caption_width < 100 ) {
     887                                $margin = ' margin-right: 10px;';
     888                        }
     889                }
     890                $style = 'style="width: ' . (int) $caption_width . $caption_width_unit . ';' . $margin . '" ';
     891        }
    880892
    881893        return '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
    882894        . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';