WordPress.org

Make WordPress Core

Ticket #12106: attachment_fix.diff

File attachment_fix.diff, 1.8 KB (added by ptahdunbar, 5 years ago)
  • wp-includes/theme.php

     
    909909/** 
    910910 * Retrieve path of attachment template in current or parent template. 
    911911 * 
    912  * The attachment path first checks if the first part of the mime type exists. 
    913  * The second check is for the second part of the mime type. The last check is 
    914  * for both types separated by an underscore. If neither are found then the file 
    915  * 'attachment.php' is checked and returned. 
     912 * Will first look for 'attachment-{mime_type[0]}.php', 
     913 * The second check is for 'attachment-{mime_type[1]}.php', The third check 
     914 * is for 'attachment-{mime_type[0]}_{mime_type[1]}.php'. The last check is 
     915 * for 'attachment.php'. 
    916916 * 
    917  * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and 
    918  * finally 'text_plain.php'. 
     917 * Some examples for the 'text/plain' mime type are 'attachment-text_plain.php',  
     918 * 'attachment-text.php', 'attachment-plain.php', and finally 'attachment.php' 
    919919 * 
    920920 * @since 2.0.0 
    921921 * 
     
    924924function get_attachment_template() { 
    925925        global $posts; 
    926926        $type = explode('/', $posts[0]->post_mime_type); 
    927         if ( $template = get_query_template($type[0]) ) 
    928                 return $template; 
    929         elseif ( $template = get_query_template($type[1]) ) 
    930                 return $template; 
    931         elseif ( $template = get_query_template("$type[0]_$type[1]") ) 
    932                 return $template; 
    933         else 
    934                 return get_query_template('attachment'); 
     927         
     928        $template = array(); 
     929        $templates[] = "attachment-{$type[0]}_{$type[1]}.php"; 
     930        $templates[] = "attachment-{$type[1]}.php"; 
     931        $templates[] = "attachment-{$type[0]}.php"; 
     932        $templates[] = "attachment.php"; 
     933         
     934        return apply_filters('attachment_template', locate_template($templates)); 
    935935} 
    936936 
    937937/**