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

Only start main query loop when block template is associated with the current theme #5575

Closed
wants to merge 3 commits into from

Conversation

felixarntz
Copy link
Member

Generally, the block template loaded should always be associated with the current theme since:

  • It either comes from a WP_Query that filters to block templates only for the get_stylesheet() theme
  • Or it comes from the current theme's file system

In both cases, the template ID will begin with get_stylesheet() . '//'.

There are rare situations (e.g. the https://wordpress.org/plugins/echo-knowledge-base/ plugin as reported in the Trac ticket) where a plugin hijacks the block template loading mechanism to inject its own block template, which thus comes from outside the theme and may use any logic. In those cases, the situation is unpredictable by core and therefore the assumption that no main query loop will be present for a singular WP_Query is no longer reliable. As such, in those cases no main query loop should be started, as that would lead to problems if the custom logic was going to attempt to start the main query loop itself. So for those cases, the PR simply falls back to the original pre-6.4 logic of just parsing blocks.

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


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@afragen
Copy link
Member

afragen commented Oct 25, 2023

I have tested the PR and it fixes the issue. Thanks @felixarntz

Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick work on this @felixarntz! I've left a few thoughts.

tests/phpunit/tests/block-template.php Show resolved Hide resolved
tests/phpunit/tests/block-template.php Show resolved Hide resolved
src/wp-includes/block-template.php Outdated Show resolved Hide resolved
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @felixarntz, for the quick PR. It looks solid to me.

src/wp-includes/block-template.php Outdated Show resolved Hide resolved
tests/phpunit/tests/block-template.php Show resolved Hide resolved
Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @felixarntz! LGTM 👍

@hellofromtonya
Copy link
Contributor

Cross-sharing a test report from the ticket: WooCommerce Blocks had a related issue, which is fixed by this PR ✅

Copy link
Contributor

@hellofromtonya hellofromtonya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Ready for commit and backport.

@felixarntz
Copy link
Member Author

@felixarntz felixarntz closed this Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants