Ticket #34561: 34561.8.diff
File 34561.8.diff, 9.9 KB (added by , 9 years ago) |
---|
-
src/wp-includes/default-filters.php
diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php index 1faa084..f964303 100644
add_action( 'embed_head', 'wp_no_robots' ); 457 457 add_action( 'embed_head', 'rel_canonical' ); 458 458 add_action( 'embed_head', 'locale_stylesheet' ); 459 459 460 add_action( 'embed_content_meta', 'print_embed_comments_button' ); 461 add_action( 'embed_content_meta', 'print_embed_sharing_button' ); 460 add_action( 'embed_head', 'locale_stylesheet' ); 461 add_action( 'embed_head', 'locale_stylesheet' ); 462 463 add_action( 'embed_heading_before', 'print_embed_thumbnail' ); 464 add_action( 'embed_content_before', 'print_embed_thumbnail' ); 465 466 add_action( 'embed_content_footer', 'print_embed_site_title' ); 462 467 463 468 add_action( 'embed_footer', 'print_embed_sharing_dialog' ); 464 469 add_action( 'embed_footer', 'print_embed_scripts' ); -
src/wp-includes/embed-template.php
diff --git src/wp-includes/embed-template.php src/wp-includes/embed-template.php index df2518f..1a5ffa8 100644
if ( ! headers_sent() ) { 33 33 <?php 34 34 if ( have_posts() ) : 35 35 while ( have_posts() ) : the_post(); 36 // Add post thumbnail to response if available. 37 $thumbnail_id = false; 38 39 if ( has_post_thumbnail() ) { 40 $thumbnail_id = get_post_thumbnail_id(); 41 } 42 43 if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) { 44 $thumbnail_id = get_the_ID(); 45 } 46 47 if ( $thumbnail_id ) { 48 $aspect_ratio = 1; 49 $measurements = array( 1, 1 ); 50 $image_size = 'full'; // Fallback. 51 52 $meta = wp_get_attachment_metadata( $thumbnail_id ); 53 if ( is_array( $meta ) ) { 54 foreach ( $meta['sizes'] as $size => $data ) { 55 if ( $data['width'] / $data['height'] > $aspect_ratio ) { 56 $aspect_ratio = $data['width'] / $data['height']; 57 $measurements = array( $data['width'], $data['height'] ); 58 $image_size = $size; 59 } 60 } 61 } 62 63 /** 64 * Filter the thumbnail image size for use in the embed template. 65 * 66 * @since 4.4.0 67 * 68 * @param string $image_size Thumbnail image size. 69 */ 70 $image_size = apply_filters( 'embed_thumbnail_image_size', $image_size ); 71 72 $shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square'; 73 36 ?> 37 <div <?php post_class( 'wp-embed' ); ?>> 38 <?php 74 39 /** 75 * Filter the thumbnail shape for use in the embed template. 76 * 77 * Rectangular images are shown above the title 78 * while square images are shown next to the content. 79 * 80 * @since 4.4.0 40 * Print additional content before the embed heading. 81 41 * 82 * @ param string $shape Thumbnail image shape. Either 'rectangular' or 'square'.42 * @since 4.5.0 83 43 */ 84 $shape = apply_filters( 'embed_thumbnail_image_shape', $shape ); 85 } 86 ?> 87 <div <?php post_class( 'wp-embed' ); ?>> 88 <?php if ( $thumbnail_id && 'rectangular' === $shape ) : ?> 89 <div class="wp-embed-featured-image rectangular"> 90 <a href="<?php the_permalink(); ?>" target="_top"> 91 <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?> 92 </a> 93 </div> 94 <?php endif; ?> 44 do_action( 'embed_heading_before' ); 45 ?> 95 46 96 47 <p class="wp-embed-heading"> 97 48 <a href="<?php the_permalink(); ?>" target="_top"> … … if ( have_posts() ) : 99 50 </a> 100 51 </p> 101 52 102 <?php if ( $thumbnail_id && 'square' === $shape ) : ?> 103 <div class="wp-embed-featured-image square"> 104 <a href="<?php the_permalink(); ?>" target="_top"> 105 <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?> 106 </a> 107 </div> 108 <?php endif; ?> 53 <?php 54 /** 55 * Print additional content before the embed excerpt. 56 * 57 * @since 4.5.0 58 */ 59 do_action( 'embed_content_before' ); 60 ?> 109 61 110 62 <div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div> 111 63 … … if ( have_posts() ) : 119 71 ?> 120 72 121 73 <div class="wp-embed-footer"> 122 <div class="wp-embed-site-title"> 123 <?php 124 $site_title = sprintf( 125 '<a href="%s" target="_top"><img src="%s" srcset="%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon"/><span>%s</span></a>', 126 esc_url( home_url() ), 127 esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ), 128 esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ), 129 esc_html( get_bloginfo( 'name' ) ) 130 ); 131 132 /** 133 * Filter the site title HTML in the embed footer. 134 * 135 * @since 4.4.0 136 * 137 * @param string $site_title The site title HTML. 138 */ 139 echo apply_filters( 'embed_site_title_html', $site_title ); 140 ?> 141 </div> 74 <?php 75 /** 76 * Print additional footer content in the embed template. 77 * 78 * @since 4.5.0 79 */ 80 do_action( 'embed_content_footer'); 81 ?> 142 82 143 83 <div class="wp-embed-meta"> 144 84 <?php … … if ( have_posts() ) : 157 97 else : 158 98 ?> 159 99 <div class="wp-embed"> 100 <?php 101 /** This filter is documented in wp-includes/embed-template.php */ 102 do_action( 'embed_heading_before' ); 103 ?> 104 160 105 <p class="wp-embed-heading"><?php _e( 'Oops! That embed can’t be found.' ); ?></p> 161 106 107 <?php 108 /** This filter is documented in wp-includes/embed-template.php */ 109 do_action( 'embed_content_before' ); 110 ?> 111 162 112 <div class="wp-embed-excerpt"> 163 113 <p> 164 114 <?php … … else : 171 121 </p> 172 122 </div> 173 123 174 <div class="wp-embed-footer"> 175 <div class="wp-embed-site-title"> 176 <?php 177 $site_title = sprintf( 178 '<a href="%s" target="_top"><img src="%s" srcset="%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon"/><span>%s</span></a>', 179 esc_url( home_url() ), 180 esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ), 181 esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ), 182 esc_html( get_bloginfo( 'name' ) ) 183 ); 124 <?php 125 /** This filter is documented in wp-includes/embed-template.php */ 126 do_action( 'embed_content' ); 127 ?> 184 128 185 /** This filter is documented in wp-includes/embed-template.php */ 186 echo apply_filters( 'embed_site_title_html', $site_title ); 187 ?> 188 </div> 129 <div class="wp-embed-footer"> 130 <?php 131 /** This filter is documented in wp-includes/embed-template.php */ 132 do_action( 'embed_content_footer'); 133 ?> 189 134 </div> 190 135 </div> 191 136 <?php -
src/wp-includes/embed.php
diff --git src/wp-includes/embed.php src/wp-includes/embed.php index 2736204..b85b5d6 100644
function print_embed_sharing_dialog() { 1045 1045 </div> 1046 1046 <?php 1047 1047 } 1048 1049 /** 1050 * Prints the necessary markup for the embed thumbnail. 1051 * 1052 * @since 4.5.0 1053 */ 1054 function print_embed_thumbnail() { 1055 $thumbnail_id = false; 1056 1057 if ( has_post_thumbnail() ) { 1058 $thumbnail_id = get_post_thumbnail_id(); 1059 } 1060 1061 if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) { 1062 $thumbnail_id = get_the_ID(); 1063 } 1064 1065 if ( ! $thumbnail_id ) { 1066 return; 1067 } 1068 1069 $aspect_ratio = 1; 1070 $measurements = array( 1, 1 ); 1071 $image_size = 'full'; // Fallback. 1072 1073 $meta = wp_get_attachment_metadata( $thumbnail_id ); 1074 if ( is_array( $meta ) ) { 1075 foreach ( $meta['sizes'] as $size => $data ) { 1076 if ( $data['width'] / $data['height'] > $aspect_ratio ) { 1077 $aspect_ratio = $data['width'] / $data['height']; 1078 $measurements = array( $data['width'], $data['height'] ); 1079 $image_size = $size; 1080 } 1081 } 1082 } 1083 1084 /** 1085 * Filter the thumbnail image size for use in the embed template. 1086 * 1087 * @since 4.4.0 1088 * @since 4.5.0 Added `$thumbnail_id` parameter. 1089 * 1090 * @param string $image_size Thumbnail image size. 1091 * @param int $thumbnail_id Attachment ID. 1092 */ 1093 $image_size = apply_filters( 'embed_thumbnail_image_size', $image_size, $thumbnail_id ); 1094 1095 $shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square'; 1096 1097 /** 1098 * Filter the thumbnail shape for use in the embed template. 1099 * 1100 * Rectangular images are shown above the title while square images 1101 * are shown next to the content. 1102 * 1103 * @since 4.4.0 1104 * @since 4.5.0 Added `$thumbnail_id` parameter. 1105 * 1106 * @param string $shape Thumbnail image shape. Either 'rectangular' or 'square'. 1107 * @param int $thumbnail_id Attachment ID. 1108 */ 1109 $shape = apply_filters( 'embed_thumbnail_image_shape', $shape, $thumbnail_id ); 1110 1111 if ( 'embed_heading_before' === current_action() && 'rectangular' === $shape ) : ?> 1112 <div class="wp-embed-featured-image rectangular"> 1113 <a href="<?php the_permalink(); ?>" target="_top"> 1114 <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?> 1115 </a> 1116 </div> 1117 <?php endif; 1118 1119 if ( 'embed_content_before' === current_action() && 'square' === $shape ) : ?> 1120 <div class="wp-embed-featured-image square"> 1121 <a href="<?php the_permalink(); ?>" target="_top"> 1122 <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?> 1123 </a> 1124 </div> 1125 <?php endif; 1126 } 1127 1128 /** 1129 * Prints the necessary markup for the site title. 1130 * 1131 * @since 4.5.0 1132 */ 1133 function print_embed_site_title() { 1134 $site_title = sprintf( 1135 '<a href="%s" target="_top"><img src="%s" srcset="%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon"/><span>%s</span></a>', 1136 esc_url( home_url() ), 1137 esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ), 1138 esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ), 1139 esc_html( get_bloginfo( 'name' ) ) 1140 ); 1141 1142 $site_title = '<div class="wp-embed-site-title">' . $site_title . '</div>'; 1143 1144 /** 1145 * Filter the site title HTML in the embed footer. 1146 * 1147 * @since 4.4.0 1148 * 1149 * @param string $site_title The site title HTML. 1150 */ 1151 echo apply_filters( 'embed_site_title_html', $site_title ); 1152 }