Make WordPress Core

Changeset 32804


Ignore:
Timestamp:
06/16/2015 08:49:44 PM (10 years ago)
Author:
wonderboymusic
Message:

In get_attachment_template(), pass an array of templates to get_query_template( 'attachment', $templates ), instead of bailing on the first found template.

Props willnorris, jfarthing84, SergeyBiryukov, DrewAPicture, wonderboymusic.
Fixes #15337.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/template.php

    r32628 r32804  
    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.
     
    405405 */
    406406function get_attachment_template() {
    407     global $posts;
    408 
    409     if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) {
    410         $type = explode( '/', $posts[0]->post_mime_type );
    411 
    412         if ( ! empty( $type ) ) {
    413             if ( $template = get_query_template( $type[0] ) )
    414                 return $template;
    415             elseif ( ! empty( $type[1] ) ) {
    416                 if ( $template = get_query_template( $type[1] ) )
    417                     return $template;
    418                 elseif ( $template = get_query_template( "$type[0]_$type[1]" ) )
    419                     return $template;
    420             }
     407    $attachment = get_queried_object();
     408
     409    $templates = array();
     410
     411    if ( $attachment ) {
     412        if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
     413            list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
     414        } else {
     415            list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
    421416        }
    422     }
    423 
    424     return get_query_template( 'attachment' );
     417
     418        if ( ! empty( $subtype ) ) {
     419            $templates[] = "{$type}-{$subtype}.php";
     420            $templates[] = "{$subtype}.php";
     421        }
     422        $templates[] = "{$type}.php";
     423    }
     424    $templates[] = 'attachment.php';
     425
     426    return get_query_template( 'attachment', $templates );
    425427}
    426428
Note: See TracChangeset for help on using the changeset viewer.