Make WordPress Core


Ignore:
Timestamp:
10/13/2017 02:38:19 AM (7 years ago)
Author:
westonruter
Message:

File Editors: Display list of theme/plugin files in scrollable directory tree.

Props WraithKenny, afercia, melchoyce, westonruter.
Amends [41721].
Fixes #24048.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/theme-editor.php

    r41806 r41851  
    8888            break;
    8989    }
     90}
     91
     92// Move functions.php and style.css to the top.
     93if ( isset( $allowed_files['functions.php'] ) ) {
     94    $allowed_files = array( 'functions.php' => $allowed_files['functions.php'] ) + $allowed_files;
     95}
     96if ( isset( $allowed_files['style.css'] ) ) {
     97    $allowed_files = array( 'style.css' => $allowed_files['style.css'] ) + $allowed_files;
    9098}
    9199
     
    206214    echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>';
    207215?>
    208     <div id="templateside">
    209 <?php
    210 if ( $allowed_files ) :
    211     $previous_file_type = '';
    212 
    213     foreach ( $allowed_files as $filename => $absolute_filename ) :
    214         $file_type = substr( $filename, strrpos( $filename, '.' ) );
    215 
    216         if ( $file_type !== $previous_file_type ) {
    217             if ( '' !== $previous_file_type ) {
    218                 echo "\t</ul>\n";
    219             }
    220 
    221             switch ( $file_type ) {
    222                 case '.php':
    223                     if ( $has_templates || $theme->parent() ) :
    224                         echo "\t<h2>" . __( 'Templates' ) . "</h2>\n";
    225                         if ( $theme->parent() ) {
    226                             echo '<p class="howto">' . sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ),
    227                                 sprintf( '<a href="%s">%s</a>',
    228                                     self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ),
    229                                     $theme->parent()->display( 'Name' )
    230                                 )
    231                             ) . "</p>\n";
    232                         }
    233                     endif;
    234                     break;
    235                 case '.css':
    236                     echo "\t<h2>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h2>\n";
    237                     break;
    238                 default:
    239                     /* translators: %s: file extension */
    240                     echo "\t<h2>" . sprintf( __( '%s files' ), $file_type ) . "</h2>\n";
    241                     break;
    242             }
    243 
    244             echo "\t<ul>\n";
     216<div id="templateside">
     217    <h2 id="theme-files-label"><?php _e( 'Theme Files' ); ?></h2>
     218    <?php
     219    if ( $has_templates || $theme->parent() ) :
     220        if ( $theme->parent() ) {
     221            /* translators: %s: link to edit parent theme */
     222            echo '<p class="howto">' . sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ),
     223                sprintf( '<a href="%s">%s</a>',
     224                    self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ),
     225                    $theme->parent()->display( 'Name' )
     226                )
     227            ) . "</p>\n";
    245228        }
    246 
    247         $file_description = esc_html( get_file_description( $filename ) );
    248         if ( $filename !== basename( $absolute_filename ) || $file_description !== $filename ) {
    249             $file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>';
    250         }
    251 
    252         if ( $absolute_filename === $file ) {
    253             $file_description = '<span class="notice notice-info">' . $file_description . '</span>';
    254         }
    255 
    256         $previous_file_type = $file_type;
    257 ?>
    258         <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&amp;theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li>
    259 <?php
    260     endforeach;
    261 ?>
    262 </ul>
    263 <?php endif; ?>
    264 </div>
     229    endif;
     230    ?>
     231    <ul role="tree" aria-labelledby="theme-files-label">
     232        <li role="treeitem" tabindex="-1" aria-expanded="true"
     233            aria-level="1"
     234            aria-posinset="1"
     235            aria-setsize="1">
     236            <ul role="group" style="padding-left: 0;">
     237                <?php wp_print_theme_file_tree( wp_make_theme_file_tree( $allowed_files ) ); ?>
     238            </ul>
     239        </li>
     240    </ul>
     241</div>
     242
    265243<?php if ( $error ) :
    266244    echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
Note: See TracChangeset for help on using the changeset viewer.