From ec3b0158d85e7fb2ba72a70e8ce88f8221d1615d Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 20 May 2022 00:49:18 +0000 Subject: [PATCH] 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 --- wp-admin/includes/class-theme-upgrader.php | 23 +++++++++++++++++----- wp-includes/class-wp-theme.php | 4 +++- wp-includes/theme.php | 4 +++- wp-includes/version.php | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/wp-admin/includes/class-theme-upgrader.php b/wp-admin/includes/class-theme-upgrader.php index 0a73f4b86c..4e874cd636 100644 --- a/wp-admin/includes/class-theme-upgrader.php +++ b/wp-admin/includes/class-theme-upgrader.php @@ -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.' ), - 'index.php' + /* 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. Child themes need to have a %4$s header in the %5$s stylesheet.' ), + 'templates/index.html', + 'index.php', + __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ), + 'Template', + 'style.css' ) ); } diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index cef5b034c6..c2398fb4eb 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -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( diff --git a/wp-includes/theme.php b/wp-includes/theme.php index d511ab1a8d..55e2d13789 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -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. diff --git a/wp-includes/version.php b/wp-includes/version.php index a3355b8c66..7c94a7faa9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.