Make WordPress Core

Opened 3 months ago

Closed 10 days ago

Last modified 10 days ago

#62053 closed enhancement (fixed)

Warn logged in users when rendering empty template in the front end

Reported by: vcanales's profile vcanales Owned by: mikachan's profile mikachan
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch
Focuses: template Cc:

Description

Proposes adding a warning for logged-in users when navigating to a page or post rendered through an empty template. The warning explains why the website's visitors might encounter a blank page and points the logged-in user to the Site Editor to fix the template by resetting it or adding content to it.

Discussion: https://github.com/WordPress/gutenberg/issues/64027

Proposed UI:

https://cldup.com/CSwlTfOXOW-3000x3000.png

Attachments (1)

Screenshot 2024-10-02 at 12.52.26 PM.png (115.7 KB) - added by peterwilsoncc 2 months ago.

Download all attachments as: .zip

Change History (15)

This ticket was mentioned in PR #7354 on WordPress/wordpress-develop by @vcanales.


3 months ago
#1

Proposes adding a warning for logged-in users when navigating to a page or post rendered through an empty template. The warning explains why the website's visitors might encounter a blank page and points the logged-in user to the Site Editor to fix the template by resetting it or adding content to it.

Related issue: https://github.com/WordPress/gutenberg/issues/64027

Trac ticket: https://core.trac.wordpress.org/ticket/62053

#2 @mrfoxtalbot
2 months ago

I added a comment to the related issue suggesting two things:

  • A slightly different wording:

"This page is blank because your theme's template is currently empty. It may have been accidentally deleted, but don't worry!You can easily reset or edit this template in the site editor."

@mrfoxtalbot commented on PR #7354:


2 months ago
#3

Thank you for working on this @vcanales, I added a comment with two minor suggestions https://github.com/WordPress/gutenberg/issues/64027#issuecomment-2385791997

@mrfoxtalbot commented on PR #7354:


2 months ago
#4

Can I ask you, @cbravobernal, or maybe @getdave to review this?
I'd love for this change to make it to the 6.7 in time.
Thanks a bunch.

#5 @mikachan
2 months ago

Thanks @vcanales! Also pinging @peterwilsoncc and @kirasong here as the 6.7 Core Tech Leads 🙇

#6 @peterwilsoncc
2 months ago

While testing, I noticed that the editor falls back to the version of templates included in the theme if they are emptied in the site editor.

In the screen shot above, the left window is viewing the home page (after emptying it) while logged in and the right window is while logged out.

I like the idea for templates that aren't in the theme but for templates that are, it would be good to show what the logged out users see.

To reproduce the screen shot:

  1. Activate 2025
  2. Open the site editor
  3. Edit the blog home page
  4. Switch to the code editor
  5. Delete all markup and save
  6. View the site while logged in
  7. View the site using a private/incognito window

I did confirm the warning only shows if the template is empty, it doesn't show for empty template-parts. So the code is a good starting point.

I'll leave some notes on the PR too for code related issues.

Last edited 2 months ago by peterwilsoncc (previous) (diff)

#7 @mikachan
4 weeks ago

Thanks for all the feedback here and on the PR, @peterwilsoncc.

With your testing steps above, I'm seeing something slightly different. I see a blank page on the front end when logged out, which also matches the Editor. And then the front end logged in shows the new warning message:

Editor:
https://cldup.com/nwXfxOMKTq.png

Front end, logged in:
https://cldup.com/XYDqAREoGw.png

Front end, logged out:
https://cldup.com/8xWj6fSeXV.png

Is this the expected behaviour? I'm happy to pick this up and help progress if I can. I went ahead and merged the latest trunk into the PR, in case there are any other changes that may affect how this is working.

#8 @peterwilsoncc
4 weeks ago

@mikachan Did you empty the template in the code editor or by deleting the blocks via the UI? It's possible the template was clear of blocks but had some white space causing the white screen.

I noticed that if I delete all the code, I get the default while logged out. But if I make the content <!-- empty but not empty --> or even a few spaces then the template shows as a white screen for logged out users.

Maybe WP needs some smarts to figure out if a template is truly empty. Unfortunately this will be more complex.

#9 @mikachan
4 weeks ago

I used the code editor to delete the blocks, and I can't see any white space left behind. I also tried adding blocks back in (just a paragraph block), saving, and then deleting this via the code editor again, and I still see a blank template when logged out.

Just to clarify what I'm seeing in the code editor:

https://cldup.com/L1qKqoXYsY.png

In any case, I like the idea of defaulting to the theme's template when the user is logged out, so I've gone ahead and committed a change to the PR that hopefully does this. To test (following your steps above):

  1. Activate 2025
  2. Open the site editor
  3. Edit the blog home page
  4. Switch to the code editor
  5. Delete all markup and save
  6. View the site while logged in: It should show the new, "This page is blank because the template might have been deleted..." warning message.
  7. View the site using a private/incognito window: If the template is included with the theme (like Blog Home), then it should default to the contents from the theme. If the template is not included with the theme, e.g. a custom template, it should show a blank template.

I've also applied a wording change from @mrfoxtalbot in this commit.

@mikachan commented on PR #7354:


3 weeks ago
#10

Thanks for all the feedback, @richtabor 🙇 I think I've addressed all your comments, this is ready for another review.

@get_dave commented on PR #7354:


12 days ago
#11

@mikachan Let me know when you are ready to commit this and we can pair on commit to WP Core.

@get_dave commented on PR #7354:


10 days ago
#12

@mikachan This now needs a commit. A good opportunity for you. LMK if you want to run through this.

#13 @mikachan
10 days ago

  • Owner set to mikachan
  • Resolution set to fixed
  • Status changed from new to closed

In 59449:

Editor: Warn about empty templates on the frontend for logged in users.

Adds a new function, wp_render_empty_block_template_warning, that renders a warning for logged-in users when a block template is empty.

Reviewed by get_dave, richtabor.
Props vcanales, mikachan, peterwilsoncc, richtabor, get_dave, mrfoxtalbot, matveb, arielmaidana, seifradwane, annezazu.
Fixes #62053.

Note: See TracTickets for help on using tickets.