Make WordPress Core

Ticket #34561: 34561.9.diff

File 34561.9.diff, 15.8 KB (added by swissspidy, 9 years ago)
  • src/wp-includes/embed-template.php

    diff --git src/wp-includes/embed-template.php src/wp-includes/embed-template.php
    index fab8c84..54608df 100644
     
    1010 * @since 4.4.0
    1111 */
    1212
    13 if ( ! headers_sent() ) {
    14         header( 'X-WP-embed: true' );
    15 }
     13get_header( 'embed' );
    1614
    17 ?>
    18 <!DOCTYPE html>
    19 <html <?php language_attributes(); ?> class="no-js">
    20 <head>
    21         <title><?php echo wp_get_document_title(); ?></title>
    22         <meta http-equiv="X-UA-Compatible" content="IE=edge">
    23         <?php
    24         /**
    25          * Print scripts or data in the embed template <head> tag.
    26          *
    27          * @since 4.4.0
    28          */
    29         do_action( 'embed_head' );
    30         ?>
    31 </head>
    32 <body <?php body_class(); ?>>
    33 <?php
    3415if ( have_posts() ) :
    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 ( ! empty( $meta['sizes'] ) ) {
    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 
    74                         /**
    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
    81                          *
    82                          * @param string $shape Thumbnail image shape. Either 'rectangular' or 'square'.
    83                          */
    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; ?>
    95 
    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; ?>
    10916
    110                         <div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div>
    111 
    112                         <?php
    113                         /**
    114                          * Print additional content after the embed excerpt.
    115                          *
    116                          * @since 4.4.0
    117                          */
    118                         do_action( 'embed_content' );
    119                         ?>
    120 
    121                         <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>
    142 
    143                                 <div class="wp-embed-meta">
    144                                         <?php
    145                                         /**
    146                                          * Print additional meta content in the embed template.
    147                                          *
    148                                          * @since 4.4.0
    149                                          */
    150                                         do_action( 'embed_content_meta');
    151                                         ?>
    152                                 </div>
    153                         </div>
    154                 </div>
    155                 <?php
     17        while ( have_posts() ) : the_post();
     18                get_template_part( 'embed', 'content' );
    15619        endwhile;
    157 else :
    158         ?>
    159         <div class="wp-embed">
    160                 <p class="wp-embed-heading"><?php _e( 'Oops! That embed can&#8217;t be found.' ); ?></p>
    16120
    162                 <div class="wp-embed-excerpt">
    163                         <p>
    164                                 <?php
    165                                 printf(
    166                                         /* translators: %s: a link to the embedded site */
    167                                         __( 'It looks like nothing was found at this location. Maybe try visiting %s directly?' ),
    168                                         '<strong><a href="' . esc_url( home_url() ) . '">' . esc_html( get_bloginfo( 'name' ) ) . '</a></strong>'
    169                                 );
    170                                 ?>
    171                         </p>
    172                 </div>
     21else :
    17322
    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                                 );
     23        get_template_part( 'embed', '404' );
    18424
    185                                 /** This filter is documented in wp-includes/embed-template.php */
    186                                 echo apply_filters( 'embed_site_title_html', $site_title );
    187                                 ?>
    188                         </div>
    189                 </div>
    190         </div>
    191         <?php
    19225endif;
    19326
    194 /**
    195  * Print scripts or data before the closing body tag in the embed template.
    196  *
    197  * @since 4.4.0
    198  */
    199 do_action( 'embed_footer' );
    200 ?>
    201 </body>
    202 </html>
     27get_footer( 'embed' );
  • src/wp-includes/embed.php

    diff --git src/wp-includes/embed.php src/wp-includes/embed.php
    index cdeaf79..59b3b88 100644
    function print_embed_sharing_dialog() { 
    10461046        </div>
    10471047        <?php
    10481048}
     1049
     1050/**
     1051 * Prints the necessary markup for the embed thumbnail.
     1052 *
     1053 * @since 4.5.0
     1054 *
     1055 * @param string $type Optional. Thumbnail shape. Either 'rectangular' or 'square'.
     1056 *                     Default 'rectangular'.
     1057 */
     1058function print_embed_thumbnail( $type = 'rectangular' ) {
     1059        $thumbnail_id = false;
     1060
     1061        if ( has_post_thumbnail() ) {
     1062                $thumbnail_id = get_post_thumbnail_id();
     1063        }
     1064
     1065        if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) {
     1066                $thumbnail_id = get_the_ID();
     1067        }
     1068
     1069        if ( ! $thumbnail_id ) {
     1070                return;
     1071        }
     1072
     1073        $aspect_ratio = 1;
     1074        $measurements = array( 1, 1 );
     1075        $image_size   = 'full'; // Fallback.
     1076
     1077        $meta = wp_get_attachment_metadata( $thumbnail_id );
     1078        if ( is_array( $meta ) ) {
     1079                foreach ( $meta['sizes'] as $size => $data ) {
     1080                        if ( $data['width'] / $data['height'] > $aspect_ratio ) {
     1081                                $aspect_ratio = $data['width'] / $data['height'];
     1082                                $measurements = array( $data['width'], $data['height'] );
     1083                                $image_size   = $size;
     1084                        }
     1085                }
     1086        }
     1087
     1088        /**
     1089         * Filter the thumbnail image size for use in the embed template.
     1090         *
     1091         * @since 4.4.0
     1092         * @since 4.5.0 Added `$thumbnail_id` parameter.
     1093         *
     1094         * @param string $image_size   Thumbnail image size.
     1095         * @param int    $thumbnail_id Attachment ID.
     1096         */
     1097        $image_size = apply_filters( 'embed_thumbnail_image_size', $image_size, $thumbnail_id );
     1098
     1099        $shape = $measurements[0] / $measurements[1] >= 1.75 ? 'rectangular' : 'square';
     1100
     1101        /**
     1102         * Filter the thumbnail shape for use in the embed template.
     1103         *
     1104         * Rectangular images are shown above the title while square images
     1105         * are shown next to the content.
     1106         *
     1107         * @since 4.4.0
     1108         * @since 4.5.0 Added `$thumbnail_id` parameter.
     1109         *
     1110         * @param string $shape        Thumbnail image shape. Either 'rectangular' or 'square'.
     1111         * @param int    $thumbnail_id Attachment ID.
     1112         */
     1113        $shape = apply_filters( 'embed_thumbnail_image_shape', $shape, $thumbnail_id );
     1114
     1115        if ( 'rectangular' === $type && $shape === $type ) : ?>
     1116                <div class="wp-embed-featured-image rectangular">
     1117                        <a href="<?php the_permalink(); ?>" target="_top">
     1118                                <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?>
     1119                        </a>
     1120                </div>
     1121        <?php endif;
     1122
     1123        if ( 'square' === $type && $shape === $type ) : ?>
     1124                <div class="wp-embed-featured-image square">
     1125                        <a href="<?php the_permalink(); ?>" target="_top">
     1126                                <?php echo wp_get_attachment_image( $thumbnail_id, $image_size ); ?>
     1127                        </a>
     1128                </div>
     1129        <?php endif;
     1130}
     1131
     1132/**
     1133 * Prints the necessary markup for the site title.
     1134 *
     1135 * @since 4.5.0
     1136 */
     1137function the_embed_site_title() {
     1138        $site_title = sprintf(
     1139                '<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>',
     1140                esc_url( home_url() ),
     1141                esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ),
     1142                esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ),
     1143                esc_html( get_bloginfo( 'name' ) )
     1144        );
     1145
     1146        $site_title = '<div class="wp-embed-site-title">' . $site_title . '</div>';
     1147
     1148        /**
     1149         * Filter the site title HTML in the embed footer.
     1150         *
     1151         * @since 4.4.0
     1152         *
     1153         * @param string $site_title The site title HTML.
     1154         */
     1155        echo apply_filters( 'embed_site_title_html', $site_title );
     1156}
  • src/wp-includes/general-template.php

    diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
    index 1669ae3..d2624b8 100644
    function get_header( $name = null ) { 
    3636
    3737        $templates = array();
    3838        $name = (string) $name;
    39         if ( '' !== $name )
     39        if ( '' !== $name ) {
    4040                $templates[] = "header-{$name}.php";
     41        }
    4142
    4243        $templates[] = 'header.php';
    4344
    44         // Backward compat code will be removed in a future release
    45         if ('' == locate_template($templates, true))
    46                 load_template( ABSPATH . WPINC . '/theme-compat/header.php');
     45        locate_template( $templates, true );
    4746}
    4847
    4948/**
    function get_footer( $name = null ) { 
    7675
    7776        $templates = array();
    7877        $name = (string) $name;
    79         if ( '' !== $name )
     78        if ( '' !== $name ) {
    8079                $templates[] = "footer-{$name}.php";
     80        }
    8181
    82         $templates[] = 'footer.php';
     82        $templates[]    = 'footer.php';
    8383
    84         // Backward compat code will be removed in a future release
    85         if ('' == locate_template($templates, true))
    86                 load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
     84        locate_template( $templates, true );
    8785}
    8886
    8987/**
    function get_sidebar( $name = null ) { 
    121119
    122120        $templates[] = 'sidebar.php';
    123121
    124         // Backward compat code will be removed in a future release
    125         if ('' == locate_template($templates, true))
    126                 load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
     122        locate_template( $templates, true );
    127123}
    128124
    129125/**
  • src/wp-includes/template.php

    diff --git src/wp-includes/template.php src/wp-includes/template.php
    index b304e31..315f2e8 100644
    function get_attachment_template() { 
    468468/**
    469469 * Retrieve the name of the highest priority template file that exists.
    470470 *
    471  * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
    472  * inherit from a parent theme can just overload one file.
     471 * Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat
     472 * so that themes which inherit from a parent theme can just overload one file.
    473473 *
    474474 * @since 2.7.0
    475475 *
    function locate_template($template_names, $load = false, $require_once = true ) 
    489489                } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
    490490                        $located = TEMPLATEPATH . '/' . $template_name;
    491491                        break;
     492                } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
     493                        $located = ABSPATH . WPINC . '/theme-compat/' . $template_name;
     494                        break;
    492495                }
    493496        }
    494497
  • new file src/wp-includes/theme-compat/embed-404.php

    diff --git src/wp-includes/theme-compat/embed-404.php src/wp-includes/theme-compat/embed-404.php
    new file mode 100644
    index 0000000..9516727
    - +  
     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
     6 * create the content template part output if the active theme does not include
     7 * a content-embed.php template.
     8 *
     9 * @package WordPress
     10 * @subpackage Theme_Compat
     11 * @since 4.5.0
     12 */
     13?>
     14<div class="wp-embed">
     15        <p class="wp-embed-heading"><?php _e( 'Oops! That embed can&#8217;t be found.' ); ?></p>
     16
     17        <div class="wp-embed-excerpt">
     18                <p>
     19                        <?php
     20                        printf(
     21                                /* translators: %s: a link to the embedded site */
     22                                __( 'It looks like nothing was found at this location. Maybe try visiting %s directly?' ),
     23                                '<strong><a href="' . esc_url( home_url() ) . '">' . esc_html( get_bloginfo( 'name' ) ) . '</a></strong>'
     24                        );
     25                        ?>
     26                </p>
     27        </div>
     28
     29        <?php
     30        /** This filter is documented in wp-includes/theme-compat/embed-content.php */
     31        do_action( 'embed_content' );
     32        ?>
     33
     34        <div class="wp-embed-footer">
     35                <?php the_embed_site_title() ?>
     36        </div>
     37</div>
  • new file src/wp-includes/theme-compat/embed-content.php

    diff --git src/wp-includes/theme-compat/embed-content.php src/wp-includes/theme-compat/embed-content.php
    new file mode 100644
    index 0000000..7d9eecc
    - +  
     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
     6 * create the content template part output if the active theme does not include
     7 * a content-embed.php template.
     8 *
     9 * @package WordPress
     10 * @subpackage Theme_Compat
     11 * @since 4.5.0
     12 */
     13?>
     14<div <?php post_class( 'wp-embed' ); ?>>
     15        <?php
     16        /*
     17         * Display rectangular thumbnail above the post embed title.
     18         */
     19        print_embed_thumbnail( 'rectangular' );
     20        ?>
     21
     22        <p class="wp-embed-heading">
     23                <a href="<?php the_permalink(); ?>" target="_top">
     24                        <?php the_title(); ?>
     25                </a>
     26        </p>
     27
     28        <?php
     29        /*
     30         * Display square thumbnail after the post embed title.
     31         */
     32        print_embed_thumbnail( 'square' );
     33        ?>
     34
     35        <div class="wp-embed-excerpt"><?php the_excerpt_embed(); ?></div>
     36
     37        <?php
     38        /**
     39         * Print additional content after the embed excerpt.
     40         *
     41         * @since 4.4.0
     42         */
     43        do_action( 'embed_content' );
     44        ?>
     45
     46        <div class="wp-embed-footer">
     47                <?php the_embed_site_title() ?>
     48
     49                <div class="wp-embed-meta">
     50                        <?php
     51                        /**
     52                         * Print additional meta content in the embed template.
     53                         *
     54                         * @since 4.4.0
     55                         */
     56                        do_action( 'embed_content_meta');
     57                        ?>
     58                </div>
     59        </div>
     60</div>
     61<?php
  • new file src/wp-includes/theme-compat/footer-embed.php

    diff --git src/wp-includes/theme-compat/footer-embed.php src/wp-includes/theme-compat/footer-embed.php
    new file mode 100644
    index 0000000..05e9f4f
    - +  
     1<?php
     2/**
     3 * Contains the post embed footer template.
     4 *
     5 * When a post is embedded in an iframe, this file is used to
     6 * create the footer output if the active theme does not include
     7 * a footer-embed.php template.
     8 *
     9 * @package WordPress
     10 * @subpackage Theme_Compat
     11 * @since 4.5.0
     12 */
     13
     14/**
     15 * Print scripts or data before the closing body tag in the embed template.
     16 *
     17 * @since 4.4.0
     18 */
     19do_action( 'embed_footer' );
     20?>
     21</body>
     22</html>
  • new file src/wp-includes/theme-compat/header-embed.php

    diff --git src/wp-includes/theme-compat/header-embed.php src/wp-includes/theme-compat/header-embed.php
    new file mode 100644
    index 0000000..a95bdb3
    - +  
     1<?php
     2/**
     3 * Contains the post embed header template.
     4 *
     5 * When a post is embedded in an iframe, this file is used to
     6 * create the header output if the active theme does not include
     7 * a header-embed.php template.
     8 *
     9 * @package WordPress
     10 * @subpackage Theme_Compat
     11 * @since 4.5.0
     12 */
     13
     14if ( ! headers_sent() ) {
     15        header( 'X-WP-embed: true' );
     16}
     17
     18?>
     19<!DOCTYPE html>
     20<html <?php language_attributes(); ?> class="no-js">
     21<head>
     22        <title><?php echo wp_get_document_title(); ?></title>
     23        <meta http-equiv="X-UA-Compatible" content="IE=edge">
     24        <?php
     25        /**
     26         * Print scripts or data in the embed template <head> tag.
     27         *
     28         * @since 4.4.0
     29         */
     30        do_action( 'embed_head' );
     31        ?>
     32</head>
     33<body <?php body_class(); ?>>