Ticket #34561: 34561.5.diff
File 34561.5.diff, 15.7 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 e4ac939..75ca351 100644
add_action( 'embed_head', 'wp_no_robots' ); 458 458 add_action( 'embed_head', 'rel_canonical' ); 459 459 add_action( 'embed_head', 'locale_stylesheet' ); 460 460 461 add_action( 'embed_content_meta', 'print_embed_comments_button' ); 462 add_action( 'embed_content_meta', 'print_embed_sharing_button' ); 463 464 add_action( 'embed_footer', 'print_embed_sharing_dialog' ); 461 465 add_action( 'embed_footer', 'print_embed_scripts' ); 462 466 add_action( 'embed_footer', 'wp_print_footer_scripts', 20 ); 463 467 -
src/wp-includes/embed-functions.php
diff --git src/wp-includes/embed-functions.php src/wp-includes/embed-functions.php index 4bd142a..fa87399 100644
function print_embed_scripts() { 958 958 function _oembed_filter_feed_content( $content ) { 959 959 return str_replace( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="display:none;"', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $content ); 960 960 } 961 962 /** 963 * Prints the heading area of the embed template. 964 * 965 * This includes the post's title and the featured image 966 * if available. On 404, it only displays a 'Not found' heading. 967 * 968 * @since 4.4.0 969 */ 970 function the_embed_header() { 971 if ( is_404() ) { 972 ?> 973 <p class="wp-embed-heading"><?php _e( 'Oops! That embed can’t be found.' ); ?></p> 974 <?php 975 return; 976 } 977 978 // Add post thumbnail to response if available. 979 $thumbnail_id = $shape = $image_size = false; 980 981 if ( has_post_thumbnail() ) { 982 $thumbnail_id = get_post_thumbnail_id(); 983 } 984 985 if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) { 986 $thumbnail_id = get_the_ID(); 987 } 988 989 if ( $thumbnail_id ) { 990 $aspect_ratio = 1; 991 $measurements = array( 1, 1 ); 992 $image_size = 'full'; // Fallback. 993 994 $meta = wp_get_attachment_metadata( $thumbnail_id ); 995 if ( is_array( $meta ) ) { 996 foreach ( $meta['sizes'] as $size => $data ) { 997 if ( $data['width'] / $data['height'] > $aspect_ratio ) { 998 $aspect_ratio = $data['width'] / $data['height']; 999 $measurements = array( $data['width'], $data['height'] ); 1000 $image_size = $size; 1001 } 1002 } 1003 } 1004 1005 /** 1006 * Filter the thumbnail image size for use in the embed template. 1007 * 1008 * @since 4.4.0 1009 * 1010 * @param string $image_size Thumbnail image size. 1011 */ 1012 $image_size = apply_filters( 'embed_thumbnail_image_size', $image_size ); 1013 1014 $shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square'; 1015 1016 /** 1017 * Filter the thumbnail shape for use in the embed template. 1018 * 1019 * Rectangular images are shown above the title 1020 * while square images are shown next to the content. 1021 * 1022 * @since 4.4.0 1023 * 1024 * @param string $shape Thumbnail image shape. Either 'rectangular' or 'square'. 1025 */ 1026 $shape = apply_filters( 'embed_thumbnail_image_shape', $shape ); 1027 } 1028 1029 if ( $thumbnail_id && 'rectangular' === $shape ) { 1030 ?> 1031 <div class="wp-embed-featured-image rectangular"> 1032 <a href="<?php the_permalink(); ?>" target="_top"> 1033 <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?> 1034 </a> 1035 </div> 1036 <?php } ?> 1037 1038 <p class="wp-embed-heading"><a href="<?php the_permalink(); ?>" target="_top"><?php the_title(); ?></a></p> 1039 1040 <?php if ( $thumbnail_id && 'square' === $shape ) { ?> 1041 <div class="wp-embed-featured-image square"> 1042 <a href="<?php the_permalink(); ?>" target="_top"> 1043 <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?> 1044 </a> 1045 </div> 1046 <?php } 1047 } 1048 1049 /** 1050 * Prints the footer area of the embed template. 1051 * 1052 * This includes the site's title and 1053 * sharing options if available. 1054 * 1055 * @since 4.4.0 1056 */ 1057 function the_embed_footer() { 1058 $site_title = sprintf( 1059 '<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>', 1060 esc_url( home_url() ), 1061 esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ), 1062 esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ), 1063 esc_html( get_bloginfo( 'name' ) ) 1064 ); 1065 1066 /** 1067 * Filter the site title in the embed footer. 1068 * 1069 * @since 4.4.0 1070 * 1071 * @param string $site_title The site title markup. 1072 */ 1073 $site_title = apply_filters( 'embed_site_title', $site_title ); 1074 ?> 1075 <div class="wp-embed-footer"> 1076 <div class="wp-embed-site-title"> 1077 <?php echo $site_title; ?> 1078 </div> 1079 <div class="wp-embed-meta"> 1080 <?php 1081 /** 1082 * Print additional meta content in the embed template. 1083 * 1084 * @since 4.4.0 1085 */ 1086 do_action( 'embed_content_meta' ); 1087 ?> 1088 </div> 1089 </div> 1090 <?php 1091 } 1092 1093 /** 1094 * Prints the necessary markup for the embed comments button. 1095 * 1096 * @since 4.4.0 1097 */ 1098 function print_embed_comments_button() { 1099 if ( is_404() || ! ( get_comments_number() || comments_open() ) ) { 1100 return; 1101 } 1102 ?> 1103 <div class="wp-embed-comments"> 1104 <a href="<?php comments_link(); ?>" target="_top"> 1105 <span class="dashicons dashicons-admin-comments"></span> 1106 <?php 1107 printf( 1108 _n( 1109 '%s <span class="screen-reader-text">Comment</span>', 1110 '%s <span class="screen-reader-text">Comments</span>', 1111 get_comments_number() 1112 ), 1113 number_format_i18n( get_comments_number() ) 1114 ); 1115 ?> 1116 </a> 1117 </div> 1118 <?php 1119 } 1120 1121 /** 1122 * Prints the necessary markup for the embed sharing button. 1123 * 1124 * @since 4.4.0 1125 */ 1126 function print_embed_sharing_button() { 1127 if ( is_404() ) { 1128 return; 1129 } 1130 ?> 1131 <div class="wp-embed-share"> 1132 <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>"> 1133 <span class="dashicons dashicons-share"></span> 1134 </button> 1135 </div> 1136 <?php 1137 } 1138 1139 /** 1140 * Prints the necessary markup for the embed sharing dialog. 1141 * 1142 * @since 4.4.0 1143 */ 1144 function print_embed_sharing_dialog() { 1145 if ( is_404() ) { 1146 return; 1147 } 1148 ?> 1149 <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e( 'Sharing options' ); ?>"> 1150 <div class="wp-embed-share-dialog-content"> 1151 <div class="wp-embed-share-dialog-text"> 1152 <ul class="wp-embed-share-tabs" role="tablist"> 1153 <li class="wp-embed-share-tab-button wp-embed-share-tab-button-wordpress" role="presentation"> 1154 <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e( 'WordPress Embed' ); ?></button> 1155 </li> 1156 <li class="wp-embed-share-tab-button wp-embed-share-tab-button-html" role="presentation"> 1157 <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e( 'HTML Embed' ); ?></button> 1158 </li> 1159 </ul> 1160 <div id="wp-embed-share-tab-wordpress" class="wp-embed-share-tab" role="tabpanel" aria-hidden="false"> 1161 <input type="text" value="<?php the_permalink(); ?>" class="wp-embed-share-input" aria-describedby="wp-embed-share-description-wordpress" tabindex="0" readonly/> 1162 1163 <p class="wp-embed-share-description" id="wp-embed-share-description-wordpress"> 1164 <?php _e( 'Copy and paste this URL into your WordPress site to embed' ); ?> 1165 </p> 1166 </div> 1167 <div id="wp-embed-share-tab-html" class="wp-embed-share-tab" role="tabpanel" aria-hidden="true"> 1168 <textarea class="wp-embed-share-input" aria-describedby="wp-embed-share-description-html" tabindex="0" readonly><?php echo esc_textarea( get_post_embed_html( 600, 400 ) ); ?></textarea> 1169 1170 <p class="wp-embed-share-description" id="wp-embed-share-description-html"> 1171 <?php _e( 'Copy and paste this code into your site to embed' ); ?> 1172 </p> 1173 </div> 1174 </div> 1175 1176 <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e( 'Close sharing dialog' ); ?>"> 1177 <span class="dashicons dashicons-no"></span> 1178 </button> 1179 </div> 1180 </div> 1181 <?php 1182 } -
src/wp-includes/embed-template.php
diff --git src/wp-includes/embed-template.php src/wp-includes/embed-template.php index d1166e5..e9e9853 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.067 *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 74 /**75 * Filter the thumbnail shape for use in the embed template.76 *77 * Rectangular images are shown above the title78 * while square images are shown next to the content.79 *80 * @since 4.4.081 *82 * @param string $shape Thumbnail image shape. Either 'rectangular' or 'square'.83 */84 $shape = apply_filters( 'embed_thumbnail_image_shape', $shape );85 }86 36 ?> 87 37 <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; ?> 38 <?php the_embed_header(); ?> 95 39 96 <p class="wp-embed-heading"> 97 <a href="<?php the_permalink(); ?>" target="_top"> 98 <?php the_title(); ?> 99 </a> 100 </p> 101 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; ?> 109 110 <div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div> 40 <div class="wp-embed-excerpt"> 41 <?php the_excerpt_embed(); ?> 42 </div> 111 43 112 44 <?php 113 45 /** … … if ( have_posts() ) : 116 48 * @since 4.4.0 117 49 */ 118 50 do_action( 'embed_content' ); 119 ?>120 121 <div class="wp-embed-footer">122 <div class="wp-embed-site-title">123 <?php124 $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.0136 *137 * @param string $site_title The site title HTML.138 */139 echo apply_filters( 'embed_site_title_html', $site_title );140 ?>141 </div>142 143 <div class="wp-embed-meta">144 <?php145 /**146 * Print additional meta content in the embed template.147 *148 * @since 4.4.0149 */150 do_action( 'embed_content_meta');151 ?>152 <?php if ( get_comments_number() || comments_open() ) : ?>153 <div class="wp-embed-comments">154 <a href="<?php comments_link(); ?>" target="_top">155 <span class="dashicons dashicons-admin-comments"></span>156 <?php157 printf(158 _n(159 '%s <span class="screen-reader-text">Comment</span>',160 '%s <span class="screen-reader-text">Comments</span>',161 get_comments_number()162 ),163 number_format_i18n( get_comments_number() )164 );165 ?>166 </a>167 </div>168 <?php endif; ?>169 <div class="wp-embed-share">170 <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>">171 <span class="dashicons dashicons-share"></span>172 </button>173 </div>174 </div>175 </div>176 <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e( 'Sharing options' ); ?>">177 <div class="wp-embed-share-dialog-content">178 <div class="wp-embed-share-dialog-text">179 <ul class="wp-embed-share-tabs" role="tablist">180 <li class="wp-embed-share-tab-button wp-embed-share-tab-button-wordpress" role="presentation">181 <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e( 'WordPress Embed' ); ?></button>182 </li>183 <li class="wp-embed-share-tab-button wp-embed-share-tab-button-html" role="presentation">184 <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e( 'HTML Embed' ); ?></button>185 </li>186 </ul>187 <div id="wp-embed-share-tab-wordpress" class="wp-embed-share-tab" role="tabpanel" aria-hidden="false">188 <input type="text" value="<?php the_permalink(); ?>" class="wp-embed-share-input" aria-describedby="wp-embed-share-description-wordpress" tabindex="0" readonly />189 190 <p class="wp-embed-share-description" id="wp-embed-share-description-wordpress">191 <?php _e( 'Copy and paste this URL into your WordPress site to embed' ); ?>192 </p>193 </div>194 <div id="wp-embed-share-tab-html" class="wp-embed-share-tab" role="tabpanel" aria-hidden="true">195 <textarea class="wp-embed-share-input" aria-describedby="wp-embed-share-description-html" tabindex="0" readonly><?php echo esc_textarea( get_post_embed_html( 600, 400 ) ); ?></textarea>196 51 197 <p class="wp-embed-share-description" id="wp-embed-share-description-html"> 198 <?php _e( 'Copy and paste this code into your site to embed' ); ?> 199 </p> 200 </div> 201 </div> 202 203 <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e( 'Close sharing dialog' ); ?>"> 204 <span class="dashicons dashicons-no"></span> 205 </button> 206 </div> 207 </div> 208 </div> 209 <?php 52 the_embed_footer(); 210 53 endwhile; 211 54 else : 212 55 ?> 213 56 <div class="wp-embed"> 214 < p class="wp-embed-heading"><?php _e( 'Oops! That embed can’t be found.' ); ?></p>57 <?php the_embed_header(); ?> 215 58 216 59 <div class="wp-embed-excerpt"> 217 60 <p> … … else : 225 68 </p> 226 69 </div> 227 70 228 <div class="wp-embed-footer"> 229 <div class="wp-embed-site-title"> 230 <?php 231 $site_title = sprintf( 232 '<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>', 233 esc_url( home_url() ), 234 esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ), 235 esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ), 236 esc_html( get_bloginfo( 'name' ) ) 237 ); 238 239 /** This filter is documented in wp-includes/embed-template.php */ 240 echo apply_filters( 'embed_site_title_html', $site_title ); 241 ?> 242 </div> 243 </div> 71 <?php the_embed_footer(); ?> 244 72 </div> 245 73 <?php 246 74 endif;