Make WordPress Core

Ticket #35657: 35657-poc.diff

File 35657-poc.diff, 2.4 KB (added by peterwilsoncc, 9 years ago)

Proof of concept

  • src/wp-includes/css/wp-embed-template.css

    diff --git a/src/wp-includes/css/wp-embed-template.css b/src/wp-includes/css/wp-embed-template.css
    index 3397396..9a968b3 100644
    a b body { 
    8686        margin-bottom: 20px;
    8787}
    8888
     89.wp-embed-featured-image > a {
     90        /*
     91        Use intrinsic ratio so the height prior to the image loading.
     92        The value of padding-top is calculated based on the size of the image.
     93        */
     94        display: block;
     95        width: 100%;
     96        position: relative;
     97        height: 0;
     98}
     99
    89100.wp-embed-featured-image img {
    90101        width: 100%;
    91102        height: auto;
    92103        border: none;
     104        display: block;
     105        position: absolute;
     106        top: 0;
     107        right: 0;
     108        bottom: 0;
     109        left: 0;
    93110}
    94111
    95112.wp-embed-featured-image.square {
  • src/wp-includes/embed.php

    diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php
    index 79b0503..a27982e 100644
    a b function print_embed_styles() { 
    914914                        include "css/wp-embed-template.min.css"
    915915                        <?php
    916916                }
    917         ?>
     917
     918                $thumbnail_id = 0;
     919
     920                if ( has_post_thumbnail() ) {
     921                        $thumbnail_id = get_post_thumbnail_id();
     922                }
     923
     924                if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) {
     925                        $thumbnail_id = get_the_ID();
     926                }
     927
     928                $aspect_ratio = 1;
     929                $measurements = array( 1, 1 );
     930                $image_size   = 'full'; // Fallback.
     931
     932                $meta = wp_get_attachment_metadata( $thumbnail_id );
     933                if ( ! empty( $meta['sizes'] ) ) {
     934                        foreach ( $meta['sizes'] as $size => $data ) {
     935                                if ( $data['width'] / $data['height'] > $aspect_ratio ) {
     936                                        $aspect_ratio = $data['width'] / $data['height'];
     937                                        $measurements = array( $data['width'], $data['height'] );
     938                                        $image_size   = $size;
     939                                }
     940                        }
     941                }
     942
     943                /** This filter is documented in wp-includes/theme-compat/embed-content.php */
     944                $image_size = apply_filters( 'embed_thumbnail_image_size', $image_size, $thumbnail_id );
     945                $shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square';
     946
     947                $padding_top = ( 100 * $measurements[1] ) / $measurements[0];
     948                $image_display_width = $measurements[0] < 160 ? $measurements[0] : 160;
     949
     950                ?>
     951                .wp-embed-featured-image > a {
     952                        <?php echo safecss_filter_attr( 'padding-top:' . $padding_top . '%;' ) ?>;
     953                }
     954
     955                <?php if ( 'square' === $shape ) : ?>
     956                        .wp-embed-featured-image.square {
     957                                <?php echo safecss_filter_attr( 'width:' . $image_display_width . 'px;' ) ?>;
     958                        }
     959                <?php endif; ?>
    918960        </style>
    919961        <?php
    920962}