WordPress.org

Make WordPress Core

Ticket #34306: 34306.2.diff

File 34306.2.diff, 8.1 KB (added by nacin, 4 years ago)
  • src/wp-admin/includes/schema.php

     
    368368                $uploads_use_yearmonth_folders = 1;
    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        }
    376377
     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        }
     383
    377384        $timezone_string = '';
    378385        $gmt_offset = 0;
    379386        /* translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
     
    433440        'default_email_category' => 1,
    434441        'recently_edited' => '',
    435442        'template' => $template,
    436         'stylesheet' => WP_DEFAULT_THEME,
     443        'stylesheet' => $stylesheet,
    437444        'comment_whitelist' => 1,
    438445        'blacklist_keys' => '',
    439446        'comment_registration' => 0,
     
    914921        $template = get_option( 'template' );
    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        }
    921932
     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 ] = true;
     937                }
     938        }
     939
    922940        if ( 1 == $network_id ) {
    923941                $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) );
    924942                $network_id = $wpdb->insert_id;
  • src/wp-admin/includes/update-core.php

     
    710710 * re-installed in future upgrades, this behaviour is controlled by the
    711711 * introduced version present here being older than the current installed version.
    712712 *
     713 * Starting with Twenty Sixteen, new themes are not automatically installed
     714 * on upgrade. This can still be explicitly asked for by explicitly defining
     715 * CORE_UPGRADE_SKIP_NEW_BUNDLED as false.
     716 *
    713717 * The content of this array should follow the following format:
    714718 * Filename (relative to wp-content) => Introduced version
    715719 * Directories should be noted by suffixing it with a trailing slash (/)
     
    729733        'themes/twentythirteen/' => '3.6',
    730734        'themes/twentyfourteen/' => '3.8',
    731735        'themes/twentyfifteen/'  => '4.1',
    732         'themes/twentysixteen/'  => '4.4',
     736       
    733737);
    734738
     739// If explicitly defined as false, then install Twenty Sixteen and later.
     740if ( defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) && ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) {
     741        $_new_bundled_files['themes/twentysixteen/'] = '4.4';
     742}
     743
    735744/**
    736745 * Upgrade the core of WordPress.
    737746 *
  • src/wp-includes/class-wp-theme.php

     
    5656                'twentythirteen' => 'Twenty Thirteen',
    5757                'twentyfourteen' => 'Twenty Fourteen',
    5858                'twentyfifteen'  => 'Twenty Fifteen',
     59                'twentysixteen'  => 'Twenty Sixteen',
    5960        );
    6061
    6162        /**
     
    11511152        }
    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         *
    11561174         * @since 3.4.0
  • src/wp-includes/default-constants.php

     
    348348        /**
    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') )
    355                 define( 'WP_DEFAULT_THEME', 'twentyfifteen' );
     357                define( 'WP_DEFAULT_THEME', 'twentysixteen' );
    356358
    357359}
  • src/wp-includes/theme.php

     
    753753/**
    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.
    760762 *
     
    774776        if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) )
    775777                return true;
    776778
    777         if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) {
    778                 switch_theme( WP_DEFAULT_THEME );
    779                 return false;
     779        if ( get_template() != WP_DEFAULT_THEME && ! file_exists( get_template_directory() . '/index.php' ) ) {
     780                // Invalid.
     781        } elseif ( get_stylesheet() != WP_DEFAULT_THEME && ! 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;
    780788        }
    781789
    782         if ( get_stylesheet() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/style.css') ) {
     790        $default = wp_get_theme( WP_DEFAULT_THEME );
     791        if ( $default->exists() ) {
    783792                switch_theme( WP_DEFAULT_THEME );
    784793                return false;
    785794        }
    786795
    787         if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {
    788                 switch_theme( WP_DEFAULT_THEME );
    789                 return false;
     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;
    790808        }
    791809
    792         return true;
     810        switch_theme( $default->get_stylesheet() );
     811        return false;
    793812}
    794813
    795814/**
  • tests/phpunit/tests/theme.php

     
    176176         * @ticket 29925
    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 );
    181182                }