From eb85b2c11b64bb451090bdcc3d9c77c466255595 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 13 Oct 2015 14:13:12 +0000 Subject: [PATCH] Theme Editor: add a filter, `wp_theme_editor_filetypes`, to allow more filetypes to be edited via the Theme Editor. Usage of the Theme Editor is strenuously discouraged, but we should allow you to add whatever filetypes (`.less`, `.scss`) you would like. Props MikeHansenMe, pross. Fixes #22924. git-svn-id: https://develop.svn.wordpress.org/trunk@35134 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/theme-editor.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/theme-editor.php b/src/wp-admin/theme-editor.php index 352deee2ca..ac77d57c8d 100644 --- a/src/wp-admin/theme-editor.php +++ b/src/wp-admin/theme-editor.php @@ -45,24 +45,35 @@ get_current_screen()->set_help_sidebar( wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) ); -if ( $theme ) +if ( $theme ) { $stylesheet = $theme; -else +} else { $stylesheet = get_stylesheet(); +} $theme = wp_get_theme( $stylesheet ); -if ( ! $theme->exists() ) +if ( ! $theme->exists() ) { wp_die( __( 'The requested theme does not exist.' ) ); +} -if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) +if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) { wp_die( __( 'The requested theme does not exist.' ) . ' ' . $theme->errors()->get_error_message() ); +} $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; +/** + * Filter the allowed files. + * + * @since 4.4.0 + * + * @param array $style_files List of style files. + * @param object $theme The current Theme object. + */ +$allowed_files += apply_filters( 'wp_theme_editor_filetypes', $style_files, $theme ); if ( empty( $file ) ) { $relative_file = 'style.css';