Ticket #11282: 11282.diff

File 11282.diff, 4.4 KB (added by westi, 3 years ago)

A first pass patch ugly and wide ranging

  • wp-login.php

     
    88 * @package WordPress 
    99 */ 
    1010 
     11// Note that this is the login page 
     12define( 'WP_LOGIN_PAGE', true); 
     13 
    1114/** Make sure that the WordPress bootstrap has run before continuing. */ 
    1215require( dirname(__FILE__) . '/wp-load.php' ); 
    1316 
  • wp-settings.php

     
    273273 
    274274do_action( 'after_setup_theme' ); 
    275275 
     276// Check that we have a working theme to output with 
     277validate_active_theme(); 
     278 
    276279// Load any template functions the theme supports. 
    277280require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-thumbnail-template.php' ); 
    278281 
  • wp-admin/themes.php

     
    4848} 
    4949?> 
    5050 
    51 <?php if ( ! validate_current_theme() ) : ?> 
    52 <div id="message1" class="updated"><p><?php _e('The active theme is broken.  Reverting to the default theme.'); ?></p></div> 
     51<?php if ( is_wp_error( validate_current_theme() ) ) : ?> 
     52<div id="message1" class="updated"><p><?php _e('The active theme is broken.  Reverting to the fallback theme.'); ?></p></div> 
    5353<?php elseif ( isset($_GET['activated']) ) : 
    5454                if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) ) { ?> 
    5555<div id="message2" class="updated"><p><?php printf(__('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings page</a> to configure them.'), admin_url('widgets.php') ); ?></p></div><?php 
  • wp-includes/load.php

     
    577577        return false; 
    578578} 
    579579 
     580function is_login() { 
     581        if ( defined( 'WP_LOGIN_PAGE' ) ) 
     582                return WP_LOGIN_PAGE; 
     583        return false; 
     584} 
     585 
    580586?> 
     587 No newline at end of file 
  • wp-includes/theme.php

     
    11841184 * @since 1.5.0 
    11851185 * @see WP_FALLBACK_THEME 
    11861186 * 
    1187  * @return bool 
     1187 * @param bool $switch_if_invalid Whether or not to switch the theme to the fallback if it is invalid 
     1188 * @return WP_Error | bool - true if valid or WP_Error with a message if not 
    11881189 */ 
    1189 function validate_current_theme() { 
     1190function validate_current_theme( $switch_if_invalid = true, $check_fallback = false) { 
    11901191        // Don't validate during an install/upgrade. 
    11911192        if ( defined('WP_INSTALLING') || !apply_filters( 'validate_current_theme', true ) ) 
    11921193                return true; 
    11931194 
    1194         if ( get_template() != WP_FALLBACK_THEME && !file_exists(get_template_directory() . '/index.php') ) { 
     1195        $valid = true; 
     1196         
     1197        if ( ( $check_fallback || get_template() != WP_FALLBACK_THEME ) && !file_exists(get_template_directory() . '/index.php') ) 
     1198                $valid = new WP_Error( 'theme_missing_index', sprintf( __( 'The current theme is missing the required file index.php please <a href="%s">switch</a> to a valid theme.' ), admin_url('themes.php') ) ) ; 
     1199                 
     1200        if ( ( $check_fallback || get_stylesheet() != WP_FALLBACK_THEME ) && !file_exists(get_stylesheet_directory() . '/style.css') ) 
     1201                $valid = new WP_Error( 'theme_missing_style', sprintf( __( 'The current theme is missing the required file style.css please <a href="%s">switch</a> to a valid theme.' ), admin_url('themes.php') ) ) ; 
     1202         
     1203        if ( $switch_if_invalid && is_wp_error($valid) ) 
    11951204                switch_theme( WP_FALLBACK_THEME, WP_FALLBACK_THEME ); 
    1196                 return false; 
    1197         } 
     1205         
     1206        return $valid; 
     1207} 
    11981208 
    1199         if ( get_stylesheet() != WP_FALLBACK_THEME && !file_exists(get_template_directory() . '/style.css') ) { 
    1200                 switch_theme( WP_FALLBACK_THEME, WP_FALLBACK_THEME ); 
    1201                 return false; 
     1209/** 
     1210 * Checks that active theme files 'index.php' and 'style.css' exists. 
     1211 *  
     1212 * Will report an error if the theme is not valid 
     1213 * 
     1214 * @since 3.0.0 
     1215 * 
     1216 * @return nothing 
     1217 */ 
     1218function validate_active_theme() { 
     1219        $is_valid = validate_current_theme(false, true); 
     1220         
     1221        if ( is_wp_error( $is_valid ) && !is_admin() && !is_login() ) { 
     1222                // Allow for a custom page to be displayed 
     1223                do_action( 'active_theme_invalid', $is_valid ); 
     1224                wp_die($is_valid); 
    12021225        } 
    1203  
    1204         return true; 
    12051226} 
    12061227 
    12071228/**