WordPress.org

Make WordPress Core

Changeset 35738


Ignore:
Timestamp:
11/25/2015 09:44:02 PM (3 years ago)
Author:
wonderboymusic
Message:

Upgrade: New themes are not automatically installed on upgrade. This can still be explicitly asked for by defining CORE_UPGRADE_SKIP_NEW_BUNDLED as false.

In populate_options(), if the theme specified by WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme. If we can't find a core default theme, WP_DEFAULT_THEME is the best we can do.

Props nacin, jeremyfelt, dd32.
See #34306.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/schema.php

    r35688 r35738  
    369369    }
    370370
    371     $template = WP_DEFAULT_THEME;
    372     // If default theme is a child theme, we need to get its template
    373     $theme = wp_get_theme( $template );
    374     if ( ! $theme->errors() )
    375         $template = $theme->get_template();
     371    // If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
     372    $stylesheet = $template = WP_DEFAULT_THEME;
     373    $theme = wp_get_theme( WP_DEFAULT_THEME );
     374    if ( ! $theme->exists() ) {
     375        $theme = WP_Theme::get_core_default_theme();
     376    }
     377
     378    // If we can't find a core default theme, WP_DEFAULT_THEME is the best we can do.
     379    if ( $theme ) {
     380        $stylesheet = $theme->get_stylesheet();
     381        $template   = $theme->get_template();
     382    }
    376383
    377384    $timezone_string = '';
     
    434441    'recently_edited' => '',
    435442    'template' => $template,
    436     'stylesheet' => WP_DEFAULT_THEME,
     443    'stylesheet' => $stylesheet,
    437444    'comment_whitelist' => 1,
    438445    'blacklist_keys' => '',
     
    915922    $stylesheet = get_option( 'stylesheet' );
    916923    $allowed_themes = array( $stylesheet => true );
    917     if ( $template != $stylesheet )
     924
     925    if ( $template != $stylesheet ) {
    918926        $allowed_themes[ $template ] = true;
    919     if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template )
     927    }
     928
     929    if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) {
    920930        $allowed_themes[ WP_DEFAULT_THEME ] = true;
     931    }
     932
     933    // If WP_DEFAULT_THEME doesn't exist, also whitelist the latest core default theme.
     934    if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) {
     935        if ( $core_default = WP_Theme::get_core_default_theme() ) {
     936            $allowed_themes[ $core_default->get_stylesheet() ] = true;
     937        }
     938    }
    921939
    922940    if ( 1 == $network_id ) {
  • trunk/src/wp-admin/includes/update-core.php

    r35718 r35738  
    716716 *
    717717 * @since 3.2.0
     718 * @since 4.4.0 New themes are not automatically installed on upgrade.
     719 *              This can still be explicitly asked for by defining
     720 *              CORE_UPGRADE_SKIP_NEW_BUNDLED as false.
    718721 * @global array $_new_bundled_files
    719722 * @var array
     
    732735    'themes/twentysixteen/'  => '4.4',
    733736);
     737
     738// If not explicitly defined as false, don't install new default themes.
     739if ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || CORE_UPGRADE_SKIP_NEW_BUNDLED ) {
     740    $_new_bundled_files = array( 'plugins/akismet/' => '2.0' );
     741}
    734742
    735743/**
  • trunk/src/wp-includes/class-wp-theme.php

    r34995 r35738  
    5757        'twentyfourteen' => 'Twenty Fourteen',
    5858        'twentyfifteen'  => 'Twenty Fifteen',
     59        'twentysixteen'  => 'Twenty Sixteen',
    5960    );
    6061
     
    11521153
    11531154    /**
     1155     * Determines the latest WordPress default theme that is installed.
     1156     *
     1157     * This hits the filesystem.
     1158     *
     1159     * @return WP_Theme|false Object, or false if no theme is installed, which would be bad.
     1160     */
     1161    public static function get_core_default_theme() {
     1162        foreach ( array_reverse( self::$default_themes ) as $slug => $name ) {
     1163            $theme = wp_get_theme( $slug );
     1164            if ( $theme->exists() ) {
     1165                return $theme;
     1166            }
     1167        }
     1168        return false;
     1169    }
     1170
     1171    /**
    11541172     * Returns array of stylesheet names of themes allowed on the site or network.
    11551173     *
  • trunk/src/wp-includes/default-constants.php

    r35290 r35738  
    349349     * Slug of the default theme for this install.
    350350     * Used as the default theme when installing new sites.
    351      * Will be used as the fallback if the current theme doesn't exist.
     351     * It will be used as the fallback if the current theme doesn't exist.
     352     *
    352353     * @since 3.0.0
     354     * @see WP_Theme::get_core_default_theme()
    353355     */
    354356    if ( !defined('WP_DEFAULT_THEME') )
  • trunk/src/wp-includes/theme.php

    r35595 r35738  
    754754 * Checks that current theme files 'index.php' and 'style.css' exists.
    755755 *
    756  * Does not check the default theme, which is the fallback and should always exist.
     756 * Does not initially check the default theme, which is the fallback and should always exist.
     757 * But if it doesn't exist, it'll fall back to the latest core default theme that does exist.
    757758 * Will switch theme to the fallback theme if current theme does not validate.
     759 *
    758760 * You can use the 'validate_current_theme' filter to return false to
    759761 * disable this functionality.
     
    775777        return true;
    776778
    777     if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) {
     779    if ( ! file_exists( get_template_directory() . '/index.php' ) ) {
     780        // Invalid.
     781    } elseif ( ! file_exists( get_template_directory() . '/style.css' ) ) {
     782        // Invalid.
     783    } elseif ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {
     784        // Invalid.
     785    } else {
     786        // Valid.
     787        return true;
     788    }
     789
     790    $default = wp_get_theme( WP_DEFAULT_THEME );
     791    if ( $default->exists() ) {
    778792        switch_theme( WP_DEFAULT_THEME );
    779793        return false;
    780794    }
    781795
    782     if ( get_stylesheet() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/style.css') ) {
    783         switch_theme( WP_DEFAULT_THEME );
    784         return false;
    785     }
    786 
    787     if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {
    788         switch_theme( WP_DEFAULT_THEME );
    789         return false;
    790     }
    791 
    792     return true;
     796    /**
     797     * If we're in an invalid state but WP_DEFAULT_THEME doesn't exist,
     798     * switch to the latest core default theme that's installed.
     799     * If it turns out that this latest core default theme is our current
     800     * theme, then there's nothing we can do about that, so we have to bail,
     801     * rather than going into an infinite loop. (This is why there are
     802     * checks against WP_DEFAULT_THEME above, also.) We also can't do anything
     803     * if it turns out there is no default theme installed. (That's `false`.)
     804     */
     805    $default = WP_Theme::get_core_default_theme();
     806    if ( false === $default || get_stylesheet() == $default->get_stylesheet() ) {
     807        return true;
     808    }
     809
     810    switch_theme( $default->get_stylesheet() );
     811    return false;
    793812}
    794813
  • trunk/tests/phpunit/tests/theme.php

    r33815 r35738  
    177177     */
    178178    function test_default_theme_in_default_theme_list() {
     179        $this->markTestSkipped( 'Core repository inclusion was stopped after Twenty Fifteen' );
    179180        if ( 'twenty' === substr( WP_DEFAULT_THEME, 0, 6 ) ) {
    180181            $this->assertContains( WP_DEFAULT_THEME, $this->default_themes );
Note: See TracChangeset for help on using the changeset viewer.