-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edit Site: Fix template lookup #22954
Conversation
Size Change: 0 B Total Size: 1.13 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixed the issue for me.
lib/template-loader.php
Outdated
// `index.html` block template. We create one so that people that are trying to access the editor are greeted | ||
// with a blank page rather than an error. | ||
if( ! $current_template_post && ( is_admin() || defined( 'REST_REQUEST' ) ) ) { | ||
// 'index' is the ultimate fallback template. If even this template doesn't exist, we create an empty one for it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it has already been covered in the above comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot, thanks! I'll remove this line.
e2e tests are still failing 😕
I'll try a rebase. |
Co-authored-by: Enrique Piqueras <epiqueras@users.noreply.github.com>
47b321a
to
4852ce3
Compare
## Description This PR fixes two issues with template lookup: ### 1. Templates with `index.html` block template fallback When using a theme that came with an `index.html` but not with a `front-page.html` block template, the site editor would show the following `Notice: Undefined index: front-page in /var/www/html/wp-content/plugins/gutenberg/lib/edit-site-page.php on line 162`. The reason is that I was setting the wrong key here: https://github.com/WordPress/gutenberg/blob/710373b254fbcd15d524afdeb31da0d93c4defd4/lib/edit-site-page.php#L158 This would use the name of the template that was _found_, not the name of the key that was looked for. So if we're looking up `front-page`, but don't find any template, and [thus fall](https://github.com/WordPress/gutenberg/blob/710373b254fbcd15d524afdeb31da0d93c4defd4/lib/template-loader.php#L226) back to `index`, the template will be stored under the `index` key, rather than the front-end one. The fix for this is to use the template we were looking for as key (rather than the name of the template we actually found). ### 2. Templates without `index.html` block template fallback When using a theme that doesn't come with any block templates at all, we need to provide a blank `index` template when the user first opens the site editor (see [discussion](#22893 (comment))). Co-authored-by: Enrique Piqueras <epiqueras@users.noreply.github.com>
👋 Just noting that this will be backported to Gutenberg 8.3 release as part of #23026 |
- Edit Site: fix template lookup. #22954 - Fix for FSE template parts: #23050 - Fix link color style rule. #23025 - Fix for link color: it needs to be opt-in. #23049 - Revert "Image Block: add caption field to placeholder" #23027 - Cover padding: reset button + hook namespace + improve visualizer #23041 - Fix failing 'Build artifacts' CI job (by updating `package-lock.json`): #23052
Description
This PR fixes two issues with template lookup:
1. Templates with
index.html
block template fallbackWhen using a theme that came with an
index.html
but not with afront-page.html
block template, the site editor would show the followingNotice: Undefined index: front-page in /var/www/html/wp-content/plugins/gutenberg/lib/edit-site-page.php on line 162
.The reason is that I was setting the wrong key here:
gutenberg/lib/edit-site-page.php
Line 158 in 710373b
This would use the name of the template that was found, not the name of the key that was looked for. So if we're looking up
front-page
, but don't find any template, and thus fall back toindex
, the template will be stored under theindex
key, rather than the front-end one.The fix for this is to use the template we were looking for as key (rather than the name of the template we actually found).
2. Templates without
index.html
block template fallbackWhen using a theme that doesn't come with any block templates at all, we need to provide a blank
index
template when the user first opens the site editor (see discussion).How has this been tested?
wp_template
CPTs (neither published norauto-draft
s) from previous Site Editor runs. (It's best to start with a fresh install, i.e.npx wp-env clean all && npx wp-env start
. Careful, this will wipe your WordPress install's data!)/wp-admin/admin.php?page=gutenberg-experiments
must not be ticked. (Make sure the "Full Site Editing" checkbox is ticked -- since it also gets reset after a wipe.)theme-experiments
repo (see thewp-env
README).Open question
Upon running
I see a sleuth of
index
templateauto-draft
s. I was hoping that only one would be created 😕 -- maybe my newly added logic is still buggy.Types of changes
Bug fix. Fixes #22800.
Checklist: