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.

git-svn-id: https://develop.svn.wordpress.org/trunk@52940 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2022-03-16 18:28:46 +00:00
parent 573581f43f
commit 8941c5efca
2 changed files with 16 additions and 5 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>'