-
Notifications
You must be signed in to change notification settings - Fork 109
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
Fix Optimization Detective compatibility with WooCommerce when Coming Soon page is served #1565
Conversation
…in template_include filter
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Note that Optimization Detective does not operate on this Coming Soon page because WooCommerce is outputting it inside the $template = apply_filters( 'template_include', $template ); WooCommerce's injecting a template override in the |
I also opened a Woo PR to fix this issue as it could cause problems with other plugins: woocommerce/woocommerce#51751 |
@@ -27,10 +27,10 @@ | |||
* @access private | |||
* @link https://core.trac.wordpress.org/ticket/43258 | |||
* | |||
* @param string $passthrough Value for the template_include filter which is passed through. | |||
* @return string Unmodified value of $passthrough. | |||
* @param string|mixed $passthrough Value for the template_include filter which is passed through. |
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.
Would be good to include a note here explaining why that's not always a string.
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.
We do the |mixed
type elsewhere for callbacks for filters. But in general the reason is that other plugins may return anything in filter callbacks, so there is no guarantee for the type.
So you want something like the following?
* @param string|mixed $passthrough Value for the template_include filter which is passed through. | |
* @param string|mixed $passthrough Value for the template_include filter which is passed through. (A plugin may have filtered this to return `null` or any other value type.) |
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.
Ah, nevermind then. I somehow was confused thinking this was a callback to a PHP function like ob_start()
, but since it's a filter callback, it's fine without a comment.
When testing WooCommerce, I discovered an unexpected result when attempting to access the Shop page:
In my local testing site, I imported some sample products but didn't "launch" the store yet, so WooCommerce is attempting to serve the Coming Soon page to a logged-out user. The relevant code is
ComingSoonRequestHandler::handle_template_include()
which filterstemplate_include
to conditionally returnnull
on FSE themes:This causes a fatal error in Optimization Detective:
This is because
od_buffer_output()
is erroneously defined with a strictstring
type for the method parameter. Well, I suppose WooCommerce is also erroneously returningnull
when it should instead return an empty string (which has the same effect) since thetemplate_include
filter is defined as passing astring
and notstring|null
.In any case, since we don't actually do anything with the variable we can just remove the typing. The result is the page as expected: