Make WordPress Core

Changeset 20315


Ignore:
Timestamp:
03/29/2012 04:16:17 AM (13 years ago)
Author:
nacin
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/theme-editor.php

    r20314 r20315  
    5656
    5757$allowed_files = $theme->get_files( 'php', 1 );
     58$has_templates = ! empty( $allowed_files );
     59
    5860$style_files = $theme->get_files( 'css' );
    5961if ( isset( $style_files['style.css'] ) ) {
     
    133135
    134136$description = get_file_description( $file );
    135 $file_show = array_search( $file, $allowed_files );
     137$file_show = array_search( $file, array_filter( $allowed_files ) );
    136138if ( $description != $file_show )
    137139    $description .= ' <span>(' . $file_show . ')</span>';
     
    143145<div class="fileedit-sub">
    144146<div class="alignleft">
    145 <h3><?php echo $theme->display('Name') . ': ' . $description; ?></h3>
     147<h3><?php echo $theme->display('Name'); if ( $description ) echo ': ' . $description; ?></h3>
    146148</div>
    147149<div class="alignright">
     
    150152        <select name="theme" id="theme">
    151153<?php
    152 foreach ( wp_get_themes() as $a_stylesheet => $a_theme ) {
     154foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {
    153155    $selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : '';
    154156    echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>';
     
    163165    <div id="templateside">
    164166<?php
    165 if ( $allowed_files ) :
     167if ( array_filter( $allowed_files ) ) :
     168    if ( $has_templates || $theme->is_child_theme() ) :
    166169?>
    167170    <h3><?php _e('Templates'); ?></h3>
     
    171174    <ul>
    172175<?php
     176    endif;
     177
    173178    foreach ( $allowed_files as $filename => $absolute_filename ) :
    174179        if ( 'style.css' == $filename ) {
  • trunk/wp-includes/class-wp-theme.php

    r20312 r20315  
    200200            else
    201201                $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) );
    202             $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
     202            $this->template = $this->stylesheet;
     203            $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
    203204            if ( ! file_exists( $this->theme_root ) ) // Don't cache this one.
    204205                $this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn&#8217;t exist. Please check your installation.' ) );
     
    207208            $this->headers['Name'] = $this->stylesheet;
    208209            $this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) );
    209             $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
     210            $this->template = $this->stylesheet;
     211            $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
    210212            return;
    211213        } else {
     
    219221        }
    220222
    221         // (If template is set from cache, we know it's good.)
     223        // (If template is set from cache [and there are no errors], we know it's good.)
    222224        if ( ! $this->template && ! ( $this->template = $this->headers['Template'] ) ) {
    223             if ( file_exists( $this->theme_root . '/' . $this->stylesheet . '/index.php' ) ) {
    224                 $this->template = $this->stylesheet;
    225             } else {
     225            $this->template = $this->stylesheet;
     226            if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet . '/index.php' ) ) {
    226227                $this->errors = new WP_Error( 'theme_no_index', __( 'Template is missing.' ) );
    227                 $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
     228                $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
    228229                return;
    229230            }
Note: See TracChangeset for help on using the changeset viewer.