WordPress.org

Make WordPress Core

Ticket #34306: 34306.5.diff

File 34306.5.diff, 14.9 KB (added by dd32, 6 years ago)
  • src/wp-admin/includes/update-core.php

    $_old_files = array( 
    703703);
    704704
    705705/**
    706706 * Stores new files in wp-content to copy
    707707 *
    708708 * The contents of this array indicate any new bundled plugins/themes which
    709709 * should be installed with the WordPress Upgrade. These items will not be
    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 *
    713713 * The content of this array should follow the following format:
    714714 * Filename (relative to wp-content) => Introduced version
    715715 * Directories should be noted by suffixing it with a trailing slash (/)
    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
    720723 * @name $_new_bundled_files
    721724 */
    722725global $_new_bundled_files;
    723726
    724727$_new_bundled_files = array(
    725728        'plugins/akismet/'       => '2.0',
    726729        'themes/twentyten/'      => '3.0',
    727730        'themes/twentyeleven/'   => '3.2',
    728731        'themes/twentytwelve/'   => '3.5',
    729732        'themes/twentythirteen/' => '3.6',
    730733        'themes/twentyfourteen/' => '3.8',
    731734        'themes/twentyfifteen/'  => '4.1',
    732735        'themes/twentysixteen/'  => '4.4',
    733736);
    734737
     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}
     742
    735743/**
    736744 * Upgrade the core of WordPress.
    737745 *
    738746 * This will create a .maintenance file at the base of the WordPress directory
    739747 * to ensure that people can not access the web site, when the files are being
    740748 * copied to their locations.
    741749 *
    742750 * The files in the {@link $_old_files} list will be removed and the new files
    743751 * copied from the zip file after the database is upgraded.
    744752 *
    745753 * The files in the {@link $_new_bundled_files} list will be added to the installation
    746754 * if the version is greater than or equal to the old version being upgraded.
    747755 *
    748756 * The steps for the upgrader for after the new release is downloaded and
    749757 * unzipped is:
  • src/wp-admin/includes/schema.php

    function populate_options() { 
    356356        $guessurl = wp_guess_url();
    357357        /**
    358358         * Fires before creating WordPress options and populating their default values.
    359359         *
    360360         * @since 2.6.0
    361361         */
    362362        do_action( 'populate_options' );
    363363
    364364        if ( ini_get('safe_mode') ) {
    365365                // Safe mode can break mkdir() so use a flat structure by default.
    366366                $uploads_use_yearmonth_folders = 0;
    367367        } else {
    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        }
     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 = '';
    378385        $gmt_offset = 0;
    379386        /* translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
    380387           or a valid timezone string (America/New_York). See http://us3.php.net/manual/en/timezones.php
    381388           for all timezone strings supported by PHP.
    382389        */
    383390        $offset_or_tz = _x( '0', 'default GMT offset or timezone string' );
    384391        if ( is_numeric( $offset_or_tz ) )
    385392                $gmt_offset = $offset_or_tz;
    386393        elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) )
    387394                        $timezone_string = $offset_or_tz;
    388395
    389396        $options = array(
    390397        'siteurl' => $guessurl,
    function populate_options() { 
    421428        'moderation_notify' => 1,
    422429        'permalink_structure' => '',
    423430        'hack_file' => 0,
    424431        'blog_charset' => 'UTF-8',
    425432        'moderation_keys' => '',
    426433        'active_plugins' => array(),
    427434        'category_base' => '',
    428435        'ping_sites' => 'http://rpc.pingomatic.com/',
    429436        'comment_max_links' => 2,
    430437        'gmt_offset' => $gmt_offset,
    431438
    432439        // 1.5
    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,
    440447        'html_type' => 'text/html',
    441448
    442449        // 1.5.1
    443450        'use_trackback' => 0,
    444451
    445452        // 2.0
    446453        'default_role' => 'subscriber',
    447454        'db_version' => $wp_db_version,
    448455
    449456        // 2.0.1
    450457        'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders,
    451458        'upload_path' => '',
    function populate_network( $network_id = 
    902909                $errors->add( 'invalid_email', __( 'You must provide a valid email address.' ) );
    903910
    904911        if ( $errors->get_error_code() )
    905912                return $errors;
    906913
    907914        // If a user with the provided email does not exist, default to the current user as the new network admin.
    908915        $site_user = get_user_by( 'email', $email );
    909916        if ( false === $site_user ) {
    910917                $site_user = wp_get_current_user();
    911918        }
    912919
    913920        // Set up site tables.
    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        }
     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 ) {
    923941                $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) );
    924942                $network_id = $wpdb->insert_id;
    925943        } else {
    926944                $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) );
    927945        }
    928946
    929947        wp_cache_delete( 'networks_have_paths', 'site-options' );
    930948
    931949        if ( !is_multisite() ) {
    932950                $site_admins = array( $site_user->user_login );
    933951                $users = get_users( array( 'fields' => array( 'ID', 'user_login' ) ) );
    934952                if ( $users ) {
    935953                        foreach ( $users as $user ) {
  • src/wp-includes/class-wp-theme.php

    final class WP_Theme implements ArrayAcc 
    4444         * Default themes.
    4545         *
    4646         * @static
    4747         * @access private
    4848         * @var array
    4949         */
    5050        private static $default_themes = array(
    5151                'classic'        => 'WordPress Classic',
    5252                'default'        => 'WordPress Default',
    5353                'twentyten'      => 'Twenty Ten',
    5454                'twentyeleven'   => 'Twenty Eleven',
    5555                'twentytwelve'   => 'Twenty Twelve',
    5656                'twentythirteen' => 'Twenty Thirteen',
    5757                'twentyfourteen' => 'Twenty Fourteen',
    5858                'twentyfifteen'  => 'Twenty Fifteen',
     59                'twentysixteen'  => 'Twenty Sixteen',
    5960        );
    6061
    6162        /**
    6263         * Renamed theme tags.
    6364         *
    6465         * @static
    6566         * @access private
    6667         * @var array
    6768         */
    6869        private static $tag_map = array(
    6970                'fixed-width'    => 'fixed-layout',
    7071                'flexible-width' => 'fluid-layout',
    7172        );
    7273
    7374        /**
    final class WP_Theme implements ArrayAcc 
    11391140                        $allowed = self::get_allowed_on_network();
    11401141                        if ( ! empty( $allowed[ $this->get_stylesheet() ] ) )
    11411142                                return true;
    11421143                }
    11431144
    11441145                if ( 'both' == $check || 'site' == $check ) {
    11451146                        $allowed = self::get_allowed_on_site( $blog_id );
    11461147                        if ( ! empty( $allowed[ $this->get_stylesheet() ] ) )
    11471148                                return true;
    11481149                }
    11491150
    11501151                return false;
    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
    11571175         *
    11581176         * @static
    11591177         * @access public
    11601178         *
    11611179         * @param int $blog_id Optional. Defaults to current blog.
    11621180         * @return array Array of stylesheet names.
    11631181         */
    11641182        public static function get_allowed( $blog_id = null ) {
    11651183                /**
    11661184                 * Filter the array of themes allowed on the site or network.
    11671185                 *
    11681186                 * @since MU
  • src/wp-includes/default-constants.php

    function wp_templating_constants() { 
    336336        /**
    337337         * Filesystem path to the current active template directory
    338338         * @since 1.5.0
    339339         */
    340340        define('TEMPLATEPATH', get_template_directory());
    341341
    342342        /**
    343343         * Filesystem path to the current active template stylesheet directory
    344344         * @since 2.1.0
    345345         */
    346346        define('STYLESHEETPATH', get_stylesheet_directory());
    347347
    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

    function switch_theme( $stylesheet ) { 
    741741        update_option( 'theme_switched', $old_theme->get_stylesheet() );
    742742        /**
    743743         * Fires after the theme is switched.
    744744         *
    745745         * @since 1.5.0
    746746         *
    747747         * @param string   $new_name  Name of the new theme.
    748748         * @param WP_Theme $new_theme WP_Theme instance of the new theme.
    749749         */
    750750        do_action( 'switch_theme', $new_name, $new_theme );
    751751}
    752752
    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 *
    761763 * @since 1.5.0
    762764 * @see WP_DEFAULT_THEME
    763765 *
    764766 * @return bool
    765767 */
    766768function validate_current_theme() {
    767769        /**
    768770         * Filter whether to validate the current theme.
    769771         *
    770772         * @since 2.7.0
    771773         *
    772774         * @param bool true Validation flag to check the current theme.
    773775         */
    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 ( ! 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;
    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/**
    796815 * Retrieve all theme modifications.
    797816 *
    798817 * @since 3.1.0
    799818 *
    800819 * @return array|void Theme modifications.
    801820 */
    802821function get_theme_mods() {
    803822        $theme_slug = get_option( 'stylesheet' );
    804823        $mods = get_option( "theme_mods_$theme_slug" );
    805824        if ( false === $mods ) {
    806825                $theme_name = get_option( 'current_theme' );
    807826                if ( false === $theme_name )
  • tests/phpunit/tests/theme.php

    class Tests_Theme extends WP_UnitTestCas 
    164164
    165165                $this->assertEquals('publish', $theme->get( 'Status' ) );
    166166
    167167                $this->assertEquals( WP_CONTENT_DIR . '/themes/' . $this->theme_slug, $theme->get_stylesheet_directory(), 'get_stylesheet_directory' );
    168168                $this->assertEquals( WP_CONTENT_DIR . '/themes/' . $this->theme_slug, $theme->get_template_directory(), 'get_template_directory' );
    169169                $this->assertEquals( content_url( 'themes/' . $this->theme_slug ), $theme->get_stylesheet_directory_uri(), 'get_stylesheet_directory_uri' );
    170170                $this->assertEquals( content_url( 'themes/' . $this->theme_slug ), $theme->get_template_directory_uri(), 'get_template_directory_uri' );
    171171        }
    172172
    173173        /**
    174174         * Make sure we update the default theme list to include the latest default theme.
    175175         *
    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                }
    182183        }
    183184
    184185        function test_default_themes_have_textdomain() {
    185186                foreach ( $this->default_themes as $theme ) {
    186187                        $this->assertEquals( $theme, wp_get_theme( $theme )->get( 'TextDomain' ) );
    187188                }
    188189        }
    189190
    190191        /**
    191192         * @ticket 20897
    192193         * @expectedDeprecated get_theme_data
    193194         */