Make WordPress Core

Ticket #15337: 15337.4.patch

File 15337.4.patch, 1.7 KB (added by DrewAPicture, 11 years ago)

refresh + list()

  • src/wp-includes/template.php

     
    391391 * 'attachment.php' is checked and returned.
    392392 *
    393393 * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and
    394  * finally 'text_plain.php'.
     394 * finally 'text-plain.php'.
    395395 *
    396396 * The template path is filterable via the 'attachment_template' hook.
    397397 *
     
    402402 * @return string Full path to attachment template file.
    403403 */
    404404function get_attachment_template() {
    405         global $posts;
     405        $attachment = get_queried_object();
    406406
    407         if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) {
    408                 $type = explode( '/', $posts[0]->post_mime_type );
     407        $templates = array();
    409408
    410                 if ( ! empty( $type ) ) {
    411                         if ( $template = get_query_template( $type[0] ) )
    412                                 return $template;
    413                         elseif ( ! empty( $type[1] ) ) {
    414                                 if ( $template = get_query_template( $type[1] ) )
    415                                         return $template;
    416                                 elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
    417                                         return $template;
    418                         }
     409        if ( $attachment ) {
     410                if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
     411                        list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
     412                } else {
     413                        list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
    419414                }
     415
     416                if ( ! empty( $subtype ) ) {
     417                        $templates[] = "{$type}-{$subtype}.php";
     418                        $templates[] = "{$subtype}.php";
     419                } else {
     420                        $templates[] = "{$type}.php";
     421                }
    420422        }
     423        $templates[] = 'attachment.php';
    421424
    422         return get_query_template( 'attachment' );
     425        return get_query_template( 'attachment', $templates );
    423426}
    424427
    425428/**