WordPress.org

Make WordPress Core

Ticket #14874: validate_current_theme.diff

File validate_current_theme.diff, 2.5 KB (added by transom, 4 years ago)

Diff to wp-includes/theme.php and wp-admin/theme.php

  • trunk/wp-includes/theme.php

     
    12271227 * Will switch theme to the fallback theme if current theme does not validate. 
    12281228 * You can use the 'validate_current_theme' filter to return FALSE to 
    12291229 * disable this functionality. 
     1230 * You can use the 'validate_current_theme_requirements' to return WP_Error object 
     1231 * if some prerequisite for the theme has not been met 
    12301232 * 
    12311233 * @since 1.5.0 
    12321234 * @see WP_DEFAULT_THEME 
     
    12401242 
    12411243        if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) { 
    12421244                switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); 
    1243                 return false; 
     1245                return new WP_Error('cannot-activate_theme', __('The active theme is broken.  Reverting to the default theme.')); 
    12441246        } 
    12451247 
    12461248        if ( get_stylesheet() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/style.css') ) { 
    12471249                switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); 
    1248                 return false; 
     1250                return new WP_Error('cannot-activate_theme', __('The active theme is broken.  Reverting to the default theme.')); 
    12491251        } 
    1250  
     1252        // add hook so that a theme can validate itself for prerequisites (php5, classes, plugins, etc.) 
     1253        // Should return true if OK, or object of WP_Error if not with error 
     1254        $result = apply_filters('validate_current_theme_requirements', true); 
     1255        if( is_wp_error( $result ) ){ 
     1256                switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME); 
     1257                return $result; 
     1258        } 
    12511259        return true; 
    12521260} 
    12531261 
  • trunk/wp-admin/themes.php

     
    5656} 
    5757?> 
    5858 
    59 <?php if ( ! validate_current_theme() ) : ?> 
    60 <div id="message1" class="updated"><p><?php _e('The active theme is broken.  Reverting to the default theme.'); ?></p></div> 
     59<?php $result = validate_current_theme(); if( is_wp_error($result) ) : ?> 
     60<div id="message1" class="updated"><p><?php echo $result->get_error_message(); ?></p></div> 
    6161<?php elseif ( isset($_GET['activated']) ) : 
    6262                if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?> 
    6363<div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php