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.
Built from https://develop.svn.wordpress.org/trunk@35180


git-svn-id: http://core.svn.wordpress.org/trunk@35146 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2015-10-15 02:20:24 +00:00
parent 317d62bfad
commit 6d91caa931
2 changed files with 64 additions and 20 deletions

View File

@ -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,19 +194,41 @@ if ( $theme->errors() )
<div id="templateside">
<?php
if ( $allowed_files ) :
if ( $has_templates || $theme->parent() ) :
?>
<h2><?php _e( 'Templates' ); ?></h2>
<?php if ( $theme->parent() ) : ?>
<p class="howto"><?php printf( __( 'This child theme inherits templates from a parent theme, %s.' ), '<a href="' . self_admin_url('theme-editor.php?theme=' . urlencode( $theme->get_template() ) ) . '">' . $theme->parent()->display('Name') . '</a>' ); ?></p>
<?php endif; ?>
<ul>
<?php
endif;
$previous_file_type = '';
foreach ( $allowed_files as $filename => $absolute_filename ) :
if ( 'style.css' == $filename )
echo "\t</ul>\n\t<h2>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h2>\n\t<ul>\n";
$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 ) {
@ -196,6 +238,8 @@ if ( $allowed_files ) :
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 ) ?>&amp;theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li>
<?php

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-35179';
$wp_version = '4.4-alpha-35180';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.