Make WordPress Core

Changeset 37988


Ignore:
Timestamp:
07/06/2016 05:07:19 PM (10 years ago)
Author:
ocean90
Message:

Embeds: Don't print the HTML for a featured image if a post has no featured image.

See [36693].
Fixes #37288.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme-compat/embed-content.php

    r37560 r37988  
    2323                }
    2424
    25                 $aspect_ratio = 1;
    26                 $measurements = array( 1, 1 );
    27                 $image_size   = 'full'; // Fallback.
     25                if ( $thumbnail_id ) {
     26                        $aspect_ratio = 1;
     27                        $measurements = array( 1, 1 );
     28                        $image_size   = 'full'; // Fallback.
    2829
    29                 $meta = wp_get_attachment_metadata( $thumbnail_id );
    30                 if ( ! empty( $meta['sizes'] ) ) {
    31                         foreach ( $meta['sizes'] as $size => $data ) {
    32                                 if ( $data['width'] / $data['height'] > $aspect_ratio ) {
    33                                         $aspect_ratio = $data['width'] / $data['height'];
    34                                         $measurements = array( $data['width'], $data['height'] );
    35                                         $image_size   = $size;
     30                        $meta = wp_get_attachment_metadata( $thumbnail_id );
     31                        if ( ! empty( $meta['sizes'] ) ) {
     32                                foreach ( $meta['sizes'] as $size => $data ) {
     33                                        if ( $data['width'] / $data['height'] > $aspect_ratio ) {
     34                                                $aspect_ratio = $data['width'] / $data['height'];
     35                                                $measurements = array( $data['width'], $data['height'] );
     36                                                $image_size   = $size;
     37                                        }
    3638                                }
    3739                        }
     40
     41                        /**
     42                         * Filters the thumbnail image size for use in the embed template.
     43                         *
     44                         * @since 4.4.0
     45                         * @since 4.5.0 Added `$thumbnail_id` parameter.
     46                         *
     47                         * @param string $image_size   Thumbnail image size.
     48                         * @param int    $thumbnail_id Attachment ID.
     49                         */
     50                        $image_size = apply_filters( 'embed_thumbnail_image_size', $image_size, $thumbnail_id );
     51
     52                        $shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square';
     53
     54                        /**
     55                         * Filters the thumbnail shape for use in the embed template.
     56                         *
     57                         * Rectangular images are shown above the title while square images
     58                         * are shown next to the content.
     59                         *
     60                         * @since 4.4.0
     61                         * @since 4.5.0 Added `$thumbnail_id` parameter.
     62                         *
     63                         * @param string $shape        Thumbnail image shape. Either 'rectangular' or 'square'.
     64                         * @param int    $thumbnail_id Attachment ID.
     65                         */
     66                        $shape = apply_filters( 'embed_thumbnail_image_shape', $shape, $thumbnail_id );
    3867                }
    3968
    40                 /**
    41                  * Filters the thumbnail image size for use in the embed template.
    42                  *
    43                  * @since 4.4.0
    44                  * @since 4.5.0 Added `$thumbnail_id` parameter.
    45                  *
    46                  * @param string $image_size   Thumbnail image size.
    47                  * @param int    $thumbnail_id Attachment ID.
    48                  */
    49                 $image_size = apply_filters( 'embed_thumbnail_image_size', $image_size, $thumbnail_id );
    50 
    51                 $shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square';
    52 
    53                 /**
    54                  * Filters the thumbnail shape for use in the embed template.
    55                  *
    56                  * Rectangular images are shown above the title while square images
    57                  * are shown next to the content.
    58                  *
    59                  * @since 4.4.0
    60                  * @since 4.5.0 Added `$thumbnail_id` parameter.
    61                  *
    62                  * @param string $shape        Thumbnail image shape. Either 'rectangular' or 'square'.
    63                  * @param int    $thumbnail_id Attachment ID.
    64                  */
    65                 $shape = apply_filters( 'embed_thumbnail_image_shape', $shape, $thumbnail_id );
    66 
    67                 if ( 'rectangular' === $shape ) : ?>
     69                if ( $thumbnail_id && 'rectangular' === $shape ) : ?>
    6870                        <div class="wp-embed-featured-image rectangular">
    6971                                <a href="<?php the_permalink(); ?>" target="_top">
     
    7981                </p>
    8082
    81                 <?php if ( 'square' === $shape ) : ?>
     83                <?php if ( $thumbnail_id && 'square' === $shape ) : ?>
    8284                        <div class="wp-embed-featured-image square">
    8385                                <a href="<?php the_permalink(); ?>" target="_top">
Note: See TracChangeset for help on using the changeset viewer.