| | 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 | <?php if ( ! is_404() ) : ?> |
| | 1080 | <div class="wp-embed-meta"> |
| | 1081 | <?php |
| | 1082 | /** |
| | 1083 | * Print additional meta content in the embed template. |
| | 1084 | * |
| | 1085 | * @since 4.4.0 |
| | 1086 | */ |
| | 1087 | do_action( 'embed_content_meta' ); |
| | 1088 | ?> |
| | 1089 | <?php if ( get_comments_number() || comments_open() ) : ?> |
| | 1090 | <div class="wp-embed-comments"> |
| | 1091 | <a href="<?php comments_link(); ?>" target="_top"> |
| | 1092 | <span class="dashicons dashicons-admin-comments"></span> |
| | 1093 | <?php |
| | 1094 | printf( |
| | 1095 | _n( |
| | 1096 | '%s <span class="screen-reader-text">Comment</span>', |
| | 1097 | '%s <span class="screen-reader-text">Comments</span>', |
| | 1098 | get_comments_number() |
| | 1099 | ), |
| | 1100 | number_format_i18n( get_comments_number() ) |
| | 1101 | ); |
| | 1102 | ?> |
| | 1103 | </a> |
| | 1104 | </div> |
| | 1105 | <?php |
| | 1106 | endif; |
| | 1107 | do_action( 'embed_content_share' ); |
| | 1108 | ?> |
| | 1109 | </div> |
| | 1110 | <?php endif; ?> |
| | 1111 | </div> |
| | 1112 | <?php |
| | 1113 | } |
| | 1114 | |
| | 1115 | /** |
| | 1116 | * Prints the necessary markup for the embed sharing buttons. |
| | 1117 | * |
| | 1118 | * @since 4.4.0 |
| | 1119 | */ |
| | 1120 | function print_embed_sharing_buttons() { |
| | 1121 | if ( is_404() ) { |
| | 1122 | return; |
| | 1123 | } ?> |
| | 1124 | <div class="wp-embed-share"> |
| | 1125 | <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>"> |
| | 1126 | <span class="dashicons dashicons-share"></span> |
| | 1127 | </button> |
| | 1128 | </div> |
| | 1129 | <?php |
| | 1130 | } |
| | 1131 | |
| | 1132 | /** |
| | 1133 | * Prints the necessary markup for the embed sharing dialog. |
| | 1134 | * |
| | 1135 | * @since 4.4.0 |
| | 1136 | */ |
| | 1137 | function print_embed_sharing_dialog() { |
| | 1138 | if ( is_404() ) { |
| | 1139 | return; |
| | 1140 | } |
| | 1141 | ?> |
| | 1142 | <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e( 'Sharing options' ); ?>"> |
| | 1143 | <div class="wp-embed-share-dialog-content"> |
| | 1144 | <div class="wp-embed-share-dialog-text"> |
| | 1145 | <ul class="wp-embed-share-tabs" role="tablist"> |
| | 1146 | <li class="wp-embed-share-tab-button wp-embed-share-tab-button-wordpress" role="presentation"> |
| | 1147 | <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e( 'WordPress Embed' ); ?></button> |
| | 1148 | </li> |
| | 1149 | <li class="wp-embed-share-tab-button wp-embed-share-tab-button-html" role="presentation"> |
| | 1150 | <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e( 'HTML Embed' ); ?></button> |
| | 1151 | </li> |
| | 1152 | </ul> |
| | 1153 | <div id="wp-embed-share-tab-wordpress" class="wp-embed-share-tab" role="tabpanel" aria-hidden="false"> |
| | 1154 | <input type="text" value="<?php the_permalink(); ?>" class="wp-embed-share-input" aria-describedby="wp-embed-share-description-wordpress" tabindex="0" readonly/> |
| | 1155 | |
| | 1156 | <p class="wp-embed-share-description" id="wp-embed-share-description-wordpress"> |
| | 1157 | <?php _e( 'Copy and paste this URL into your WordPress site to embed' ); ?> |
| | 1158 | </p> |
| | 1159 | </div> |
| | 1160 | <div id="wp-embed-share-tab-html" class="wp-embed-share-tab" role="tabpanel" aria-hidden="true"> |
| | 1161 | <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> |
| | 1162 | |
| | 1163 | <p class="wp-embed-share-description" id="wp-embed-share-description-html"> |
| | 1164 | <?php _e( 'Copy and paste this code into your site to embed' ); ?> |
| | 1165 | </p> |
| | 1166 | </div> |
| | 1167 | </div> |
| | 1168 | |
| | 1169 | <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e( 'Close sharing dialog' ); ?>"> |
| | 1170 | <span class="dashicons dashicons-no"></span> |
| | 1171 | </button> |
| | 1172 | </div> |
| | 1173 | </div> |
| | 1174 | <?php |
| | 1175 | } |