Skip to content
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

PHP notice in the site editor #22800

Closed
carolinan opened this issue Jun 1, 2020 · 9 comments · Fixed by #22954
Closed

PHP notice in the site editor #22800

carolinan opened this issue Jun 1, 2020 · 9 comments · Fixed by #22954
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@carolinan
Copy link
Contributor

carolinan commented Jun 1, 2020

Describe the bug
With 8.2.0 and later, this notice is showing in the site editor
Notice: Undefined index: front-page in /var/www/html/wp-content/plugins/gutenberg/lib/edit-site-page.php on line 162

https://github.com/WordPress/gutenberg/blob/master/lib/edit-site-page.php#L162

To reproduce
Steps to reproduce the behavior:

  1. Install Gutenberg
  2. Enable full site editing
  3. Enable a theme that has support for full site editing.
    https://github.com/WordPress/theme-experiments
  4. Open the site editor.
  5. See PHP notice

Expected behavior
I expect experimental features to change often, but not be broken in the plugin releases. :)

Editor version (please complete the following information):
WordPress version: 5.4.1
Gutenberg: 8.2.0, 8.2.1

PHP version: 7.3.13

Desktop (please complete the following information):
Windows 10
Chrome version: 83.0.4103.61

@talldan talldan added [Feature] Full Site Editing [Type] Bug An existing feature does not function as intended labels Jun 3, 2020
@youknowriad
Copy link
Contributor

@epiqueras
Copy link
Contributor

You need to have at least an index.html block template to fall back to for this to work.

@ockham
Copy link
Contributor

ockham commented Jun 4, 2020

My bad! I'll work on a fix tomorrow.

@carolinan
Copy link
Contributor Author

carolinan commented Jun 5, 2020

Requiring and index.html makes sense considering the template hierarchy, but the notice shows when front-page.html is missing, not when index.html is missing.

@ockham
Copy link
Contributor

ockham commented Jun 5, 2020

To repro this:

  • There shouldn't be any wp_template CPTs (neither published nor auto-drafts) from previous Site Editor runs. (It's best to start with a fresh install.)
  • Furthermore, the "Full Site Editing Demo Templates" checkbox in /wp-admin/admin.php?page=gutenberg-experiments must not be ticked.

@epiqueras
Copy link
Contributor

but the notice shows when front-page.html is missing, not when index.html is missing.

Yes, there is a bug there.

Furthermore, the "Full Site Editing Demo Templates" checkbox in /wp-admin/admin.php?page=gutenberg-experiments must not be ticked.

Doesn't that mean there isn't an index.html template? Or are you using a theme that provides one? If that's the case, then the error is in how theme provided files are being looked up. It should be easy to debug that.

@ockham
Copy link
Contributor

ockham commented Jun 5, 2020

but the notice shows when front-page.html is missing, not when index.html is missing.

Yes, there is a bug there.

Right, this is one part of the problem. I think I'm setting the wrong key here:

$template_ids[ $current_template['template_post']->post_name ] = $current_template['template_post']->ID;

This will 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 to index, the template will be stored under the index key, rather than the front-end one.

I think the fix for this is to use the template we were looking for as key:

diff --git a/lib/edit-site-page.php b/lib/edit-site-page.php
index 817c3ef9cb..0dcaf92d6a 100644
--- a/lib/edit-site-page.php
+++ b/lib/edit-site-page.php
@@ -155,7 +155,7 @@ function gutenberg_edit_site_init( $hook ) {
 
                $current_template = gutenberg_find_template_post_and_parts( $template_type );
                if ( isset( $current_template ) ) {
-                       $template_ids[ $current_template['template_post']->post_name ] = $current_template['template_post']->ID;
+                       $template_ids[ $template_type ] = $current_template['template_post']->ID;
                        $template_part_ids = $template_part_ids + $current_template['template_part_ids'];
                }
        }

This should make the error go away when there's no front-page.html, but an index.html -- e.g. for Twenty Twenty Blocks 🤞

Furthermore, the "Full Site Editing Demo Templates" checkbox in /wp-admin/admin.php?page=gutenberg-experiments must not be ticked.

Doesn't that mean there isn't an index.html template? Or are you using a theme that provides one? If that's the case, then the error is in how theme provided files are being looked up. It should be easy to debug that.

The theme I was testing this with was Twenty Twenty (i.e. not the 'Blocks' version), so no index.html. I'm still getting the error about the missing front-page index with themes that don't come with block template, this will need separate fixing. I left a related note here.

@epiqueras
Copy link
Contributor

That fix makes sense. Let's ship it.

@ockham
Copy link
Contributor

ockham commented Jun 5, 2020

That fix makes sense. Let's ship it.

Working on a PR that also addresses this problem.

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants