Make WordPress Core

Changeset 53417


Ignore:
Timestamp:
05/20/2022 12:59:55 AM (3 years ago)
Author:
peterwilsoncc
Message:

Themes: Accept valid block themes.

Updates theme validation to accept block themes. This replaces the requirement for an index.php with a requirement for either an index.php, /templates/index.html or the deprecated /block-templates/index.html.

Validation is updated for theme uploads, within WP_Theme::__construct and validate_current_theme().

A block theme using the deprecated file structure is now included in the unit tests.

Props peterwilsoncc, sergeybiryukov, hellofromtonya, costdev, azaozz, gziolo, FlorianBrinkmann, Boniu91, aristath, poena, audrasjb.
Merges [53416] to the 6.0 branch.
Fixes #55682.

Location:
branches/6.0
Files:
11 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/6.0

  • branches/6.0/src/wp-admin/includes/class-theme-upgrader.php

    r52998 r53417  
    567567        }
    568568
    569         // If it's not a child theme, it must have at least an index.php to be legit.
    570         if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) {
     569        /*
     570         * Parent themes must contain an index file:
     571         * - classic themes require /index.php
     572         * - block themes require /templates/index.html or block-templates/index.html (deprecated 5.9.0).
     573         */
     574        if (
     575            empty( $info['Template'] ) &&
     576            ! file_exists( $working_directory . 'index.php' ) &&
     577            ! file_exists( $working_directory . 'templates/index.html' ) &&
     578            ! file_exists( $working_directory . 'block-templates/index.html' )
     579        ) {
    571580            return new WP_Error(
    572581                'incompatible_archive_theme_no_index',
    573582                $this->strings['incompatible_archive'],
    574583                sprintf(
    575                     /* translators: %s: index.php */
    576                     __( 'The theme is missing the %s file.' ),
    577                     '<code>index.php</code>'
     584                    /* translators: 1: templates/index.html, 2: index.php, 3: Documentation URL, 4: Template, 5: style.css */
     585                    __( 'Template is missing. Standalone themes need to have a %1$s or %2$s template file. <a href="%3$s">Child themes</a> need to have a %4$s header in the %5$s stylesheet.' ),
     586                    '<code>templates/index.html</code>',
     587                    '<code>index.php</code>',
     588                    __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ),
     589                    '<code>Template</code>',
     590                    '<code>style.css</code>'
    578591                )
    579592            );
  • branches/6.0/src/wp-includes/class-wp-theme.php

    r53254 r53417  
    342342            $theme_path     = $this->theme_root . '/' . $this->stylesheet;
    343343
    344             if ( ! file_exists( $theme_path . '/templates/index.html' )
     344            if (
     345                ! file_exists( $theme_path . '/templates/index.html' )
     346                && ! file_exists( $theme_path . '/block-templates/index.html' ) // Deprecated path support since 5.9.0.
    345347                && ! file_exists( $theme_path . '/index.php' )
    346348            ) {
  • branches/6.0/src/wp-includes/theme.php

    r53053 r53417  
    862862    }
    863863
    864     if ( ! file_exists( get_template_directory() . '/templates/index.html' )
     864    if (
     865        ! file_exists( get_template_directory() . '/templates/index.html' )
     866        && ! file_exists( get_template_directory() . '/block-templates/index.html' ) // Deprecated path support since 5.9.0.
    865867        && ! file_exists( get_template_directory() . '/index.php' )
    866868    ) {
  • branches/6.0/tests/phpunit/tests/rest-api/wpRestTemplatesController.php

    r52436 r53417  
    286286                    'post_title'   => 'Home Page Template',
    287287                    'post_content' => file_get_contents( $theme_root_dir . 'block-theme/templates/page-home.html' ),
     288                    'post_excerpt' => 'Description of page home template.',
     289                ),
     290            ),
     291            'template: parent theme deprecated path'      => array(
     292                'theme_dir' => 'themedir1/block-theme-deprecated-path',
     293                'template'  => 'page-home',
     294                'args'      => array(
     295                    'post_name'    => 'page-home',
     296                    'post_title'   => 'Home Page Template',
     297                    'post_content' => file_get_contents( $theme_root_dir . 'block-theme-deprecated-path/block-templates/page-home.html' ),
    288298                    'post_excerpt' => 'Description of page home template.',
    289299                ),
  • branches/6.0/tests/phpunit/tests/theme/themeDir.php

    r53282 r53417  
    166166            'Block Theme [0.4.0]',
    167167            'Block Theme [1.0.0] in subdirectory',
     168            'Block Theme Deprecated Path',
    168169            'Webfonts theme',
    169170            'Empty `fontFace` in theme.json - no webfonts defined',
    170171        );
    171172
    172         sort( $theme_names );
    173         sort( $expected );
    174 
    175         $this->assertSame( $expected, $theme_names );
     173        $this->assertSameSets( $expected, $theme_names );
    176174    }
    177175
  • branches/6.0/tests/phpunit/tests/theme/wpTheme.php

    r53253 r53417  
    310310                'expected'  => true,
    311311            ),
     312            'deprecated block theme'    => array(
     313                'theme_dir' => 'block-theme-deprecated-path',
     314                'expected'  => true,
     315            ),
    312316        );
    313317    }
     
    336340    public function data_get_file_path() {
    337341        return array(
    338             'no theme: no file given'           => array(
     342            'no theme: no file given'              => array(
    339343                'theme_dir' => 'nonexistent',
    340344                'file'      => '',
    341345                'expected'  => '/nonexistent',
    342346            ),
    343             'parent theme: no file given'       => array(
     347            'parent theme: no file given'          => array(
    344348                'theme_dir' => 'block-theme',
    345349                'file'      => '',
    346350                'expected'  => '/block-theme',
    347351            ),
    348             'child theme: no file given'        => array(
     352            'child theme: no file given'           => array(
    349353                'theme_dir' => 'block-theme-child',
    350354                'file'      => '',
    351355                'expected'  => '/block-theme-child',
    352356            ),
    353             'nonexistent theme: file given'     => array(
     357            'nonexistent theme: file given'        => array(
    354358                'theme_dir' => 'nonexistent',
    355359                'file'      => '/templates/page.html',
    356360                'expected'  => '/nonexistent/templates/page.html',
    357361            ),
    358             'parent theme: file exists'         => array(
     362            'parent theme: file exists'            => array(
    359363                'theme_dir' => 'block-theme',
    360364                'file'      => '/templates/page-home.html',
    361365                'expected'  => '/block-theme/templates/page-home.html',
    362366            ),
    363             'parent theme: file does not exist' => array(
     367            'parent theme: deprecated file exists' => array(
     368                'theme_dir' => 'block-theme-deprecated-path',
     369                'file'      => '/block-templates/page-home.html',
     370                'expected'  => '/block-theme-deprecated-path/block-templates/page-home.html',
     371            ),
     372            'parent theme: file does not exist'    => array(
    364373                'theme_dir' => 'block-theme',
    365374                'file'      => '/templates/nonexistent.html',
    366375                'expected'  => '/block-theme/templates/nonexistent.html',
    367376            ),
    368             'child theme: file exists'          => array(
     377            'child theme: file exists'             => array(
    369378                'theme_dir' => 'block-theme-child',
    370379                'file'      => '/templates/page-1.html',
    371380                'expected'  => '/block-theme-child/templates/page-1.html',
    372381            ),
    373             'child theme: file does not exist'  => array(
     382            'child theme: file does not exist'     => array(
    374383                'theme_dir' => 'block-theme-child',
    375384                'file'      => '/templates/nonexistent.html',
Note: See TracChangeset for help on using the changeset viewer.