Fix handling responses to form submissions from an AMP Cache #1382
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It turns out that submitting a form from a page on an AMP cache is currently failing with the plugin. An error
The reason is that the plugin was not sending back the proper CORS response headers as detailed in the CORS in AMP docs. In particular, the
Access-Control-Allow-Origin
header was not being sent, and theOrigin
checking was not taking into the AMP Cache domains.In this PR:
AMP_Theme_Support
and the entirety ofAMP_Response_Headers
to form a new classAMP_HTTP
.allowed_redirect_hosts
so thatwp_validate_redirect()
will allow such origins.Access-Control-Allow-Credentials:true
andVary:origin
response headers.Access-Control-Expose-Headers
response headers.To test this, you need to have the code deployed publicly and then access your site on the AMP cache, specifically a page that has a contact form on it. For an easy way to determine the AMP Cache URL for any given URL, see https://ampbyexample.com/advanced/using_the_google_amp_cache/#amp-cache-url-format
Fixes #1356.