- $template_mapping = array();
- $template_dir = $themes[$theme]['Template Dir'];
- foreach ( $themes[$theme]['Template Files'] as $template_file ) {
- // Don't show parent templates.
- if ( $is_child_theme && strpos( $template_file, trailingslashit( $template_dir ) ) === 0 )
- continue;
-
- $description = trim( get_file_description($template_file) );
- $template_show = basename($template_file);
- $filedesc = ( $description != $template_file ) ? "$description<br /><span class='nonessential'>($template_show)</span>" : "$description";
- $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description<br /><span class='nonessential'>($template_show)</span></span>" : $filedesc;
- $template_mapping[ $description ] = array( _get_template_edit_filename($template_file, $template_dir), $filedesc );
- }
- ksort( $template_mapping );
- while ( list( $template_sorted_key, list( $template_file, $filedesc ) ) = each( $template_mapping ) ) :
- ?>
- <li><a href="theme-editor.php?file=<?php echo urlencode( $template_file ) ?>&theme=<?php echo urlencode( $theme ) ?>&dir=theme"><?php echo $filedesc ?></a></li>
-<?php endwhile; ?>
- </ul>
- <h3><?php /* translators: Theme stylesheets in theme editor */ _ex('Styles', 'Theme stylesheets in theme editor'); ?></h3>
- <ul>
+if ( $allowed_files ) :
+ $previous_file_type = '';
+
+ foreach ( $allowed_files as $filename => $absolute_filename ) :
+ $file_type = substr( $filename, strrpos( $filename, '.' ) );
+
+ if ( $file_type !== $previous_file_type ) {
+ if ( '' !== $previous_file_type ) {
+ echo "\t</ul>\n";
+ }
+
+ switch ( $file_type ) {
+ case '.php':
+ if ( $has_templates || $theme->parent() ) :
+ echo "\t<h2>" . __( 'Templates' ) . "</h2>\n";
+ if ( $theme->parent() ) {
+ echo '<p class="howto">' . sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ),
+ sprintf( '<a href="%s">%s</a>',
+ self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ),
+ $theme->parent()->display( 'Name' )
+ )
+ ) . "</p>\n";
+ }
+ endif;
+ break;
+ case '.css':
+ echo "\t<h2>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h2>\n";
+ break;
+ default:
+ /* translators: %s: file extension */
+ echo "\t<h2>" . sprintf( __( '%s files' ), $file_type ) . "</h2>\n";
+ break;
+ }
+
+ echo "\t<ul>\n";
+ }
+
+ $file_description = get_file_description( $filename );
+ if ( $filename !== basename( $absolute_filename ) || $file_description !== $filename ) {
+ $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>';
+ }
+
+ if ( $absolute_filename === $file ) {
+ $file_description = '<span class="highlight">' . $file_description . '</span>';
+ }
+
+ $previous_file_type = $file_type;
+?>
+ <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li>