]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/theme-compat/embed-content.php
Wordpress 4.6-scripts
[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                 if ( $thumbnail_id ) {
26                         $aspect_ratio = 1;
27                         $measurements = array( 1, 1 );
28                         $image_size   = 'full'; // Fallback.
29
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                                         }
38                                 }
39                         }
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 );
67                 }
68
69                 if ( $thumbnail_id && 'rectangular' === $shape ) : ?>
70                         <div class="wp-embed-featured-image rectangular">
71                                 <a href="<?php the_permalink(); ?>" target="_top">
72                                         <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?>
73                                 </a>
74                         </div>
75                 <?php endif; ?>
76
77                 <p class="wp-embed-heading">
78                         <a href="<?php the_permalink(); ?>" target="_top">
79                                 <?php the_title(); ?>
80                         </a>
81                 </p>
82
83                 <?php if ( $thumbnail_id && 'square' === $shape ) : ?>
84                         <div class="wp-embed-featured-image square">
85                                 <a href="<?php the_permalink(); ?>" target="_top">
86                                         <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?>
87                                 </a>
88                         </div>
89                 <?php endif; ?>
90
91                 <div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div>
92
93                 <?php
94                 /**
95                  * Prints additional content after the embed excerpt.
96                  *
97                  * @since 4.4.0
98                  */
99                 do_action( 'embed_content' );
100                 ?>
101
102                 <div class="wp-embed-footer">
103                         <?php the_embed_site_title() ?>
104
105                         <div class="wp-embed-meta">
106                                 <?php
107                                 /**
108                                  * Prints additional meta content in the embed template.
109                                  *
110                                  * @since 4.4.0
111                                  */
112                                 do_action( 'embed_content_meta');
113                                 ?>
114                         </div>
115                 </div>
116         </div>
117 <?php