embed-content.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. if ( has_post_thumbnail() ) {
  17. $thumbnail_id = get_post_thumbnail_id();
  18. }
  19. if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) {
  20. $thumbnail_id = get_the_ID();
  21. }
  22. /**
  23. * Filters the thumbnail image ID for use in the embed template.
  24. *
  25. * @since 4.9.0
  26. *
  27. * @param int $thumbnail_id Attachment ID.
  28. */
  29. $thumbnail_id = apply_filters( 'embed_thumbnail_id', $thumbnail_id );
  30. if ( $thumbnail_id ) {
  31. $aspect_ratio = 1;
  32. $measurements = array( 1, 1 );
  33. $image_size = 'full'; // Fallback.
  34. $meta = wp_get_attachment_metadata( $thumbnail_id );
  35. if ( ! empty( $meta['sizes'] ) ) {
  36. foreach ( $meta['sizes'] as $size => $data ) {
  37. if ( $data['height'] > 0 && $data['width'] / $data['height'] > $aspect_ratio ) {
  38. $aspect_ratio = $data['width'] / $data['height'];
  39. $measurements = array( $data['width'], $data['height'] );
  40. $image_size = $size;
  41. }
  42. }
  43. }
  44. /**
  45. * Filters the thumbnail image size for use in the embed template.
  46. *
  47. * @since 4.4.0
  48. * @since 4.5.0 Added `$thumbnail_id` parameter.
  49. *
  50. * @param string $image_size Thumbnail image size.
  51. * @param int $thumbnail_id Attachment ID.
  52. */
  53. $image_size = apply_filters( 'embed_thumbnail_image_size', $image_size, $thumbnail_id );
  54. $shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square';
  55. /**
  56. * Filters the thumbnail shape for use in the embed template.
  57. *
  58. * Rectangular images are shown above the title while square images
  59. * are shown next to the content.
  60. *
  61. * @since 4.4.0
  62. * @since 4.5.0 Added `$thumbnail_id` parameter.
  63. *
  64. * @param string $shape Thumbnail image shape. Either 'rectangular' or 'square'.
  65. * @param int $thumbnail_id Attachment ID.
  66. */
  67. $shape = apply_filters( 'embed_thumbnail_image_shape', $shape, $thumbnail_id );
  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. <p class="wp-embed-heading">
  77. <a href="<?php the_permalink(); ?>" target="_top">
  78. <?php the_title(); ?>
  79. </a>
  80. </p>
  81. <?php if ( $thumbnail_id && '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. <div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div>
  89. <?php
  90. /**
  91. * Prints additional content after the embed excerpt.
  92. *
  93. * @since 4.4.0
  94. */
  95. do_action( 'embed_content' );
  96. ?>
  97. <div class="wp-embed-footer">
  98. <?php the_embed_site_title() ?>
  99. <div class="wp-embed-meta">
  100. <?php
  101. /**
  102. * Prints additional meta content in the embed template.
  103. *
  104. * @since 4.4.0
  105. */
  106. do_action( 'embed_content_meta');
  107. ?>
  108. </div>
  109. </div>
  110. </div>
  111. <?php