- if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
-
- return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
- . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
+ if ( ! empty( $atts['id'] ) )
+ $atts['id'] = 'id="' . esc_attr( $atts['id'] ) . '" ';
+
+ $caption_width = 10 + $atts['width'];
+
+ /**
+ * Filter the width of an image's caption.
+ *
+ * By default, the caption is 10 pixels greater than the width of the image,
+ * to prevent post content from running up against a floated image.
+ *
+ * @since 3.7.0
+ *
+ * @param int $caption_width Width in pixels. To remove this inline style, return zero.
+ * @param array $atts {
+ * The attributes of the caption shortcode.
+ *
+ * @type string 'id' The ID of the div element for the caption.
+ * @type string 'align' The class name that aligns the caption. Default 'alignnone'.
+ * @type int 'width' The width of the image being captioned.
+ * @type string 'caption' The image's caption.
+ * }
+ * @param string $content The image element, possibly wrapped in a hyperlink.
+ */
+ $caption_width = apply_filters( 'img_caption_shortcode_width', $caption_width, $atts, $content );
+
+ $style = '';
+ if ( $caption_width )
+ $style = 'style="width: ' . (int) $caption_width . 'px" ';
+
+ return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr( $atts['align'] ) . '">'
+ . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';