| 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; ?> |