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.
Fixes #55754.

Built from https://develop.svn.wordpress.org/trunk@53416


git-svn-id: http://core.svn.wordpress.org/trunk@53005 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-05-20 00:49:18 +00:00
parent 4b46629139
commit ec3b0158d8
4 changed files with 25 additions and 8 deletions

View File

@ -566,15 +566,28 @@ class Theme_Upgrader extends WP_Upgrader {
);
}
// If it's not a child theme, it must have at least an index.php to be legit.
if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) {
/*
* Parent themes must contain an index file:
* - classic themes require /index.php
* - block themes require /templates/index.html or block-templates/index.html (deprecated 5.9.0).
*/
if (
empty( $info['Template'] ) &&
! file_exists( $working_directory . 'index.php' ) &&
! file_exists( $working_directory . 'templates/index.html' ) &&
! file_exists( $working_directory . 'block-templates/index.html' )
) {
return new WP_Error(
'incompatible_archive_theme_no_index',
$this->strings['incompatible_archive'],
sprintf(
/* translators: %s: index.php */
__( 'The theme is missing the %s file.' ),
'<code>index.php</code>'
/* translators: 1: templates/index.html, 2: index.php, 3: Documentation URL, 4: Template, 5: style.css */
__( '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.' ),
'<code>templates/index.html</code>',
'<code>index.php</code>',
__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ),
'<code>Template</code>',
'<code>style.css</code>'
)
);
}

View File

@ -341,7 +341,9 @@ final class WP_Theme implements ArrayAccess {
$this->template = $this->stylesheet;
$theme_path = $this->theme_root . '/' . $this->stylesheet;
if ( ! file_exists( $theme_path . '/templates/index.html' )
if (
! file_exists( $theme_path . '/templates/index.html' )
&& ! file_exists( $theme_path . '/block-templates/index.html' ) // Deprecated path support since 5.9.0.
&& ! file_exists( $theme_path . '/index.php' )
) {
$error_message = sprintf(

View File

@ -861,7 +861,9 @@ function validate_current_theme() {
return true;
}
if ( ! file_exists( get_template_directory() . '/templates/index.html' )
if (
! file_exists( get_template_directory() . '/templates/index.html' )
&& ! file_exists( get_template_directory() . '/block-templates/index.html' ) // Deprecated path support since 5.9.0.
&& ! file_exists( get_template_directory() . '/index.php' )
) {
// Invalid.

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-53414';
$wp_version = '6.1-alpha-53416';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.