-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
If someone tries to load WC_REST class to early, throw notice #23102
If someone tries to load WC_REST class to early, throw notice #23102
Conversation
…lude rest api classes
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 indeed fixes the fatal I was seeing in Printful, but I think we might need to add one more conditional to the logic to ensure the current request is not a REST request. As-is right now on this branch if I load up /wp-json
the error is still thrown which invalidates the JSON response from the API
@timmyc good catch. The function which outputs the notice should be patched to do this, it already handles ajax requests for the very same reason. |
Codecov Report
|
@mikejolley testing this out again locally, and still seeing: when going to It seems doing other REST requests are working okay - at least clicking around in Gutenberg I can perform RESTful actions like saving a draft. |
…ttps://github.com/woocommerce/woocommerce into update/prevent-fatal-errors-when-extending-rest-api
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.
Thanks @mikejolley - the last commit fixed up all things for me. Verified with printful 2.0.8 installed the warning is shown, no exception is thrown, and REST API requests do not see the warning.
As of 3.6, rest API classes only get included during the
rest_api_init
hook to prevent performance issues on non-rest api pages.Some extensions extend these classes early/outside of this hook.
To prevent this causing fatal errors, this PR adds some code to the autoloader to include those files if missing, outputting a notice to inform the developer whats going on:
You can test by installing the printful intgration from WordPress.org which suffers from this. You should see the above notice with DEBUG mode on, but there will be no fatal error.
cc @timmyc