From 0f944bb5152b940e305e85fb038df0b239814ff9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 15 Oct 2015 02:19:45 +0000 Subject: [PATCH] Theme Editor: Repurpose the `'wp_theme_editor_filetypes'` filter added in [35134] to actually filter file types instead of files. Default types include 'php' and 'css' and cannot be removed, only new types can be added. Props DrewAPicture, SergeyBiryukov. Fixes #22924. git-svn-id: https://develop.svn.wordpress.org/trunk@35180 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/theme-editor.php | 82 +++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 19 deletions(-) diff --git a/src/wp-admin/theme-editor.php b/src/wp-admin/theme-editor.php index ac77d57c8d..6fae2b7535 100644 --- a/src/wp-admin/theme-editor.php +++ b/src/wp-admin/theme-editor.php @@ -61,19 +61,39 @@ if ( $theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_co 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 = array(); +$has_templates = false; +$default_types = array( 'php', 'css' ); + /** - * Filter the allowed files. + * Filter the list of file types allowed for editing in the Theme editor. * * @since 4.4.0 * - * @param array $style_files List of style files. - * @param object $theme The current Theme object. + * @param array $default_types List of file types. Default types include 'php' and 'css'. + * @param WP_Theme $theme The current Theme object. */ -$allowed_files += apply_filters( 'wp_theme_editor_filetypes', $style_files, $theme ); +$file_types = apply_filters( 'wp_theme_editor_filetypes', $default_types, $theme ); + +// Ensure that default types are still there. +$file_types = array_unique( array_merge( $file_types, $default_types ) ); + +foreach ( $file_types as $type ) { + switch ( $type ) { + case 'php': + $allowed_files += $theme->get_files( 'php', 1 ); + $has_templates = ! empty( $allowed_files ); + break; + case 'css': + $style_files = $theme->get_files( 'css' ); + $allowed_files['style.css'] = $style_files['style.css']; + $allowed_files += $style_files; + break; + default: + $allowed_files += $theme->get_files( $type ); + break; + } +} if ( empty( $file ) ) { $relative_file = 'style.css'; @@ -174,20 +194,42 @@ if ( $theme->errors() )
parent() ) : -?> -

- parent() ) : ?> -

get_template() ) ) . '">' . $theme->parent()->display('Name') . '' ); ?>

- - \n\t

" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "

\n\t\n"; + } + + switch ( $file_type ) { + case '.php': + if ( $has_templates || $theme->parent() ) : + echo "\t

" . __( 'Templates' ) . "

\n"; + if ( $theme->parent() ) { + echo '

' . sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ), + sprintf( '%s', + self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ), + $theme->parent()->display( 'Name' ) + ) + ) . "

\n"; + } + endif; + break; + case '.css': + echo "\t

" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "

\n"; + break; + default: + /* translators: %s: file extension */ + echo "\t

" . sprintf( __( '%s files' ), $file_type ) . "

\n"; + break; + } + + echo "\t