Themes: Allow block themes to be activated without `index.php`.

This removes the requirement for block themes to have an unused `index.php` template just for activation, as they use a `templates/index.html` file instead.

The updated requirements are as follows:

* Standalone themes need to have a `templates/index.html` or `index.php` template file.
* Child themes need to have a `Template` header in the `style.css` stylesheet.

Follow-up to [52069], [52247].

Props poena, sabbirshouvo, scruffian, manfcarlo, overclokk, andraganescu, SergeyBiryukov.
Fixes #54272.
Built from https://develop.svn.wordpress.org/trunk@52940


git-svn-id: http://core.svn.wordpress.org/trunk@52529 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-03-16 18:30:03 +00:00
parent 54bdc31c99
commit 0538720bba
3 changed files with 17 additions and 6 deletions

View File

@ -338,10 +338,15 @@ final class WP_Theme implements ArrayAccess {
if ( ! $this->template ) {
$this->template = $this->stylesheet;
if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet . '/index.php' ) ) {
$theme_path = $this->theme_root . '/' . $this->stylesheet;
if ( ! file_exists( $theme_path . '/templates/index.html' )
&& ! file_exists( $theme_path . '/index.php' )
) {
$error_message = sprintf(
/* translators: 1: index.php, 2: Documentation URL, 3: style.css */
__( 'Template is missing. Standalone themes need to have a %1$s template file. <a href="%2$s">Child themes</a> need to have a Template header in the %3$s stylesheet.' ),
/* translators: 1: templates/index.html, 2: index.php, 3: Documentation URL, 4: 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 Template header in the %4$s stylesheet.' ),
'<code>templates/index.html</code>',
'<code>index.php</code>',
__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ),
'<code>style.css</code>'

View File

@ -830,7 +830,10 @@ function switch_theme( $stylesheet ) {
}
/**
* Checks that the active theme has 'index.php' and 'style.css' files.
* Checks that the active theme has the required files.
*
* Standalone themes need to have a `templates/index.html` or `index.php` template file.
* Child themes need to have a `Template` header in the `style.css` stylesheet.
*
* Does not initially check the default theme, which is the fallback and should always exist.
* But if it doesn't exist, it'll fall back to the latest core default theme that does exist.
@ -840,6 +843,7 @@ function switch_theme( $stylesheet ) {
* this functionality.
*
* @since 1.5.0
* @since 6.0.0 Removed the requirement for block themes to have an `index.php` template.
*
* @see WP_DEFAULT_THEME
*
@ -857,7 +861,9 @@ function validate_current_theme() {
return true;
}
if ( ! file_exists( get_template_directory() . '/index.php' ) ) {
if ( ! file_exists( get_template_directory() . '/templates/index.html' )
&& ! file_exists( get_template_directory() . '/index.php' )
) {
// Invalid.
} elseif ( ! file_exists( get_template_directory() . '/style.css' ) ) {
// Invalid.

View File

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