How to see files in directories in “Edit Themes” screen

There is not a way to do this without modifying the core.

You should see .php files that are in subdirectories, but you won’t see anything above the root theme directory for .css files, and you won’t see any JavaScript files.

If you take a look at wp-admin/theme-editor.php, the relevant lines are…

<?php
$allowed_files = $theme->get_files( 'php', 1 );
$has_templates = ! empty( $allowed_files );
$style_files = $theme->get_files( 'css' );
$allowed_files['style.css'] = $style_files['style.css'];
$allowed_files += $style_files;

$theme is is a WP_Theme object representing the current theme. It’s create a few lines above.

The get_files method searches a directory by matching the the file extension (first argument) and using the depth (second argument). The first call to get_files fetches all PHP files in the theme directory as well as the any subdirectories one level above the theme directory.

The second fetches all css files in the theme directory but it doesn’t recursively go into subdirectories (notice the lack of the $depth argument).

There’s not much you can do about this; there is a conspicuous lack of any calls to apply_filters and do_action in theme-editor.php and the get_files method lacks them as well. You’re pretty limited.

And when PHP doesn’t work, time to try the ugly JavaScript hacks!

Unfortunately, that’s no good either. I tried exploring adding files to the list via JavaScript and ajax, but clicking on a JS added file results in an error message due to function called validate_file_to_edit which checks the current file to edit against the list of $allowed_files (see the above code that fetches that).

Leave a Comment

tech