Make WordPress Core

Ticket #27292: 27292.diff

File 27292.diff, 1.9 KB (added by jond3r, 12 years ago)

Suggested patch with a unit test

  • src/wp-includes/media.php

     
    745745
    746746        $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
    747747
    748         return '<div ' . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
    749         . do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
     748        $html5 = current_theme_supports( 'html5', 'caption' );
     749        $itemtag = $html5 ? 'figure' : 'div';
     750        $captiontag = $html5 ? 'figcaption' : 'p';
     751       
     752        return "<$itemtag " . $atts['id'] . $style . 'class="' . esc_attr( $class ) . '">'
     753        . do_shortcode( $content ) . "<$captiontag " . 'class="wp-caption-text">' . $atts['caption'] . "</$captiontag></$itemtag>";
    750754}
    751755
    752756add_shortcode('gallery', 'gallery_shortcode');
  • tests/phpunit/tests/media.php

     
    108108                $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) );
    109109        }
    110110
     111        function test_new_img_caption_shortcode_new_format_html5() {
     112                add_theme_support( 'html5', array( 'caption' ) );
     113                $result = img_caption_shortcode(
     114                        array( 'width' => 20 ),
     115                        $this->img_content . $this->html_content
     116                );
     117                $img_preg = preg_quote( $this->img_content );
     118                $content_preg = preg_quote( $this->html_content );
     119
     120                $this->assertEquals( 1, preg_match( "~^<figure [^>]+>{$img_preg}<figcaption [^>]+>{$content_preg}</figcaption></figure>$~", $result ) );
     121                remove_theme_support( 'html5' );
     122        }
     123
    111124        function test_add_remove_oembed_provider() {
    112125                wp_oembed_add_provider( 'http://foo.bar/*', 'http://foo.bar/oembed' );
    113126                $this->assertTrue( wp_oembed_remove_provider( 'http://foo.bar/*' ) );