WordPress.org

Make WordPress Core

Ticket #15337: 15337.3.patch

File 15337.3.patch, 1.5 KB (added by SergeyBiryukov, 5 years ago)
  • wp-includes/template.php

     
    306306 * 'attachment.php' is checked and returned.
    307307 *
    308308 * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and
    309  * finally 'text_plain.php'.
     309 * finally 'text-plain.php'.
    310310 *
    311311 * @since 2.0.0
    312312 *
    313313 * @return string
    314314 */
    315315function get_attachment_template() {
    316         global $posts;
     316        $attachment = get_queried_object();
    317317
    318         if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) {
    319                 $type = explode( '/', $posts[0]->post_mime_type );
     318        $templates = array();
    320319
     320        if ( $attachment ) {
     321                $type = explode( '/', $attachment->post_mime_type );
     322
    321323                if ( ! empty( $type ) ) {
    322                         if ( $template = get_query_template( $type[0] ) )
    323                                 return $template;
    324                         elseif ( $template = get_query_template( $type[1] ) )
    325                                 return $template;
    326                         elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
    327                                 return $template;
     324                        $templates[] = "{$type[0]}-{$type[1]}.php";
     325                        $templates[] = "{$type[1]}.php";
     326                        $templates[] = "{$type[0]}.php";
    328327                }
    329328        }
     329        $templates[] = 'attachment.php';
    330330
    331         return get_query_template( 'attachment' );
     331        $template = get_query_template( 'attachment', $templates );
     332        $template = apply_filters( "{$type[0]}_template", $template );
     333        $template = apply_filters( "{$type[1]}_template", $template );
     334        $template = apply_filters( "{$type[0]}_{$type[1]}_template", $template );
     335
     336        return $template;
    332337}
    333338
    334339/**