Always set WP_Theme->template even when there is an error and we have no idea what the template is. (Assume it is the stylesheet.) Prevents a number of issues including WP_Theme->is_child_theme() lying. Tidy the theme editor for broken themes and themes with no templates (PHP files), or no template (parent), or are broken. Allow broken themes to be edited. see #20103.

git-svn-id: http://svn.automattic.com/wordpress/trunk@20315 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2012-03-29 04:16:17 +00:00
parent 107733e263
commit 5b8037afe6
2 changed files with 17 additions and 11 deletions

View File

@ -55,6 +55,8 @@ if ( ! $theme )
wp_die( __( 'The requested theme does not exist.' ) );
$allowed_files = $theme->get_files( 'php', 1 );
$has_templates = ! empty( $allowed_files );
$style_files = $theme->get_files( 'css' );
if ( isset( $style_files['style.css'] ) ) {
$allowed_files['style.css'] = $style_files['style.css'];
@ -132,7 +134,7 @@ default:
<?php endif;
$description = get_file_description( $file );
$file_show = array_search( $file, $allowed_files );
$file_show = array_search( $file, array_filter( $allowed_files ) );
if ( $description != $file_show )
$description .= ' <span>(' . $file_show . ')</span>';
?>
@ -142,14 +144,14 @@ if ( $description != $file_show )
<div class="fileedit-sub">
<div class="alignleft">
<h3><?php echo $theme->display('Name') . ': ' . $description; ?></h3>
<h3><?php echo $theme->display('Name'); if ( $description ) echo ': ' . $description; ?></h3>
</div>
<div class="alignright">
<form action="theme-editor.php" method="post">
<strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong>
<select name="theme" id="theme">
<?php
foreach ( wp_get_themes() as $a_stylesheet => $a_theme ) {
foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {
$selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : '';
echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>';
}
@ -162,7 +164,8 @@ foreach ( wp_get_themes() as $a_stylesheet => $a_theme ) {
</div>
<div id="templateside">
<?php
if ( $allowed_files ) :
if ( array_filter( $allowed_files ) ) :
if ( $has_templates || $theme->is_child_theme() ) :
?>
<h3><?php _e('Templates'); ?></h3>
<?php if ( $theme->is_child_theme() ) : ?>
@ -170,6 +173,8 @@ if ( $allowed_files ) :
<?php endif; ?>
<ul>
<?php
endif;
foreach ( $allowed_files as $filename => $absolute_filename ) :
if ( 'style.css' == $filename ) {
echo "\t</ul>\n\t<h3>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h3>\n\t<ul>\n";

View File

@ -199,14 +199,16 @@ final class WP_Theme implements ArrayAccess {
$this->errors = new WP_Error( 'theme_not_found', __( 'The theme directory does not exist.' ) );
else
$this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) );
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
$this->template = $this->stylesheet;
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
if ( ! file_exists( $this->theme_root ) ) // Don't cache this one.
$this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn&#8217;t exist. Please check your installation.' ) );
return;
} elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) {
$this->headers['Name'] = $this->stylesheet;
$this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) );
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
$this->template = $this->stylesheet;
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
return;
} else {
$this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' );
@ -218,13 +220,12 @@ final class WP_Theme implements ArrayAccess {
}
}
// (If template is set from cache, we know it's good.)
// (If template is set from cache [and there are no errors], we know it's good.)
if ( ! $this->template && ! ( $this->template = $this->headers['Template'] ) ) {
if ( file_exists( $this->theme_root . '/' . $this->stylesheet . '/index.php' ) ) {
$this->template = $this->stylesheet;
} else {
if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet . '/index.php' ) ) {
$this->errors = new WP_Error( 'theme_no_index', __( 'Template is missing.' ) );
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
return;
}
}