WordPress.org

Make WordPress Core

Ticket #15337: template.php.diff

File template.php.diff, 962 bytes (added by jfarthing84, 22 months ago)

Reorder attachment template hierarchy, change underscore to dash in most specific scenario and pass all templates as an array.

  • wp-includes/template.php

     
    302302 * @return string 
    303303 */ 
    304304function get_attachment_template() { 
    305         global $posts; 
    306         $type = explode('/', $posts[0]->post_mime_type); 
    307         if ( $template = get_query_template($type[0]) ) 
    308                 return $template; 
    309         elseif ( $template = get_query_template($type[1]) ) 
    310                 return $template; 
    311         elseif ( $template = get_query_template("$type[0]_$type[1]") ) 
    312                 return $template; 
    313         else 
    314                 return get_query_template('attachment'); 
     305        $object = get_queried_object(); 
     306 
     307        $type = explode( '/', $object->post_mime_type ); 
     308 
     309        $templates = array();  
     310 
     311        $templates[] = "{$type[0]}-{$type[1]}.php"; 
     312        $templates[] = "{$type[1]}.php"; 
     313        $templates[] = "{$type[0]}.php"; 
     314        $templates[] = 'attachment.php'; 
     315 
     316        return get_query_template( 'attachment', $templates );  
    315317} 
    316318 
    317319/**