wp/wp-includes/theme-compat/embed-content.php
changeset 7 cf61fcea0001
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
       
     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 		/**
       
    26 		 * Filters the thumbnail image ID for use in the embed template.
       
    27 		 *
       
    28 		 * @since 4.9.0
       
    29 		 *
       
    30 		 * @param int $thumbnail_id Attachment ID.
       
    31 		 */
       
    32 		$thumbnail_id = apply_filters( 'embed_thumbnail_id', $thumbnail_id );
       
    33 
       
    34 		if ( $thumbnail_id ) {
       
    35 			$aspect_ratio = 1;
       
    36 			$measurements = array( 1, 1 );
       
    37 			$image_size   = 'full'; // Fallback.
       
    38 
       
    39 			$meta = wp_get_attachment_metadata( $thumbnail_id );
       
    40 			if ( ! empty( $meta['sizes'] ) ) {
       
    41 				foreach ( $meta['sizes'] as $size => $data ) {
       
    42 					if ( $data['height'] > 0 && $data['width'] / $data['height'] > $aspect_ratio ) {
       
    43 						$aspect_ratio = $data['width'] / $data['height'];
       
    44 						$measurements = array( $data['width'], $data['height'] );
       
    45 						$image_size   = $size;
       
    46 					}
       
    47 				}
       
    48 			}
       
    49 
       
    50 			/**
       
    51 			 * Filters the thumbnail image size for use in the embed template.
       
    52 			 *
       
    53 			 * @since 4.4.0
       
    54 			 * @since 4.5.0 Added `$thumbnail_id` parameter.
       
    55 			 *
       
    56 			 * @param string $image_size   Thumbnail image size.
       
    57 			 * @param int    $thumbnail_id Attachment ID.
       
    58 			 */
       
    59 			$image_size = apply_filters( 'embed_thumbnail_image_size', $image_size, $thumbnail_id );
       
    60 
       
    61 			$shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square';
       
    62 
       
    63 			/**
       
    64 			 * Filters the thumbnail shape for use in the embed template.
       
    65 			 *
       
    66 			 * Rectangular images are shown above the title while square images
       
    67 			 * are shown next to the content.
       
    68 			 *
       
    69 			 * @since 4.4.0
       
    70 			 * @since 4.5.0 Added `$thumbnail_id` parameter.
       
    71 			 *
       
    72 			 * @param string $shape        Thumbnail image shape. Either 'rectangular' or 'square'.
       
    73 			 * @param int    $thumbnail_id Attachment ID.
       
    74 			 */
       
    75 			$shape = apply_filters( 'embed_thumbnail_image_shape', $shape, $thumbnail_id );
       
    76 		}
       
    77 
       
    78 		if ( $thumbnail_id && 'rectangular' === $shape ) : ?>
       
    79 			<div class="wp-embed-featured-image rectangular">
       
    80 				<a href="<?php the_permalink(); ?>" target="_top">
       
    81 					<?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?>
       
    82 				</a>
       
    83 			</div>
       
    84 		<?php endif; ?>
       
    85 
       
    86 		<p class="wp-embed-heading">
       
    87 			<a href="<?php the_permalink(); ?>" target="_top">
       
    88 				<?php the_title(); ?>
       
    89 			</a>
       
    90 		</p>
       
    91 
       
    92 		<?php if ( $thumbnail_id && 'square' === $shape ) : ?>
       
    93 			<div class="wp-embed-featured-image square">
       
    94 				<a href="<?php the_permalink(); ?>" target="_top">
       
    95 					<?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?>
       
    96 				</a>
       
    97 			</div>
       
    98 		<?php endif; ?>
       
    99 
       
   100 		<div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div>
       
   101 
       
   102 		<?php
       
   103 		/**
       
   104 		 * Prints additional content after the embed excerpt.
       
   105 		 *
       
   106 		 * @since 4.4.0
       
   107 		 */
       
   108 		do_action( 'embed_content' );
       
   109 		?>
       
   110 
       
   111 		<div class="wp-embed-footer">
       
   112 			<?php the_embed_site_title() ?>
       
   113 
       
   114 			<div class="wp-embed-meta">
       
   115 				<?php
       
   116 				/**
       
   117 				 * Prints additional meta content in the embed template.
       
   118 				 *
       
   119 				 * @since 4.4.0
       
   120 				 */
       
   121 				do_action( 'embed_content_meta');
       
   122 				?>
       
   123 			</div>
       
   124 		</div>
       
   125 	</div>
       
   126 <?php