WordPress 4.5
[autoinstalls/wordpress.git] / wp-includes / theme-compat / embed-content.php
1 <?php
2 /**
3  * Contains the post embed content template part
4  *
5  * When a post is embedded in an iframe, this file is used to create the content template part
6  * output if the active theme does not include an embed-content.php template.
7  *
8  * @package WordPress
9  * @subpackage Theme_Compat
10  * @since 4.5.0
11  */
12 ?>
13         <div <?php post_class( 'wp-embed' ); ?>>
14                 <?php
15                 $thumbnail_id = 0;
16
17                 if ( has_post_thumbnail() ) {
18                         $thumbnail_id = get_post_thumbnail_id();
19                 }
20
21                 if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) {
22                         $thumbnail_id = get_the_ID();
23                 }
24
25                 $aspect_ratio = 1;
26                 $measurements = array( 1, 1 );
27                 $image_size   = 'full'; // Fallback.
28
29                 $meta = wp_get_attachment_metadata( $thumbnail_id );
30                 if ( is_array( $meta ) ) {
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;
36                                 }
37                         }
38                 }
39
40                 /**
41                  * Filter 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                  * Filter 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 ) : ?>
68                         <div class="wp-embed-featured-image rectangular">
69                                 <a href="<?php the_permalink(); ?>" target="_top">
70                                         <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?>
71                                 </a>
72                         </div>
73                 <?php endif; ?>
74
75                 <p class="wp-embed-heading">
76                         <a href="<?php the_permalink(); ?>" target="_top">
77                                 <?php the_title(); ?>
78                         </a>
79                 </p>
80
81                 <?php if ( 'square' === $shape ) : ?>
82                         <div class="wp-embed-featured-image square">
83                                 <a href="<?php the_permalink(); ?>" target="_top">
84                                         <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?>
85                                 </a>
86                         </div>
87                 <?php endif; ?>
88
89                 <div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div>
90
91                 <?php
92                 /**
93                  * Print additional content after the embed excerpt.
94                  *
95                  * @since 4.4.0
96                  */
97                 do_action( 'embed_content' );
98                 ?>
99
100                 <div class="wp-embed-footer">
101                         <?php the_embed_site_title() ?>
102
103                         <div class="wp-embed-meta">
104                                 <?php
105                                 /**
106                                  * Print additional meta content in the embed template.
107                                  *
108                                  * @since 4.4.0
109                                  */
110                                 do_action( 'embed_content_meta');
111                                 ?>
112                         </div>
113                 </div>
114         </div>
115 <?php