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

Fix invalidation path for post type without archive page #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cgrycki
Copy link

@cgrycki cgrycki commented Jan 31, 2023

When an invalidation is submitted for post type that does not have an archive page, the invalidation paths submitted may include the path "://*". This results in a 400 bad request status from the CloudFront API. The issue can be traced to the parse_url function in classes/WP/Post.php. The function will accept a null or empty string for the URL. Doing so will cause the function to return the string "://". Possibly related to #107.

Since the calling function get_the_post_type_archive_links() is already written to handle a situation where parse_url returns an instance of WP_Error, I have updated parse_url to return a WP_Error object when the given url is empty or null. That appears to be the intended behavior from the existing code. As a result of this change, cache invalidations for post types without an archive page do not include the invalid path in the submission to CloudFront.

A unit test has been added to test/WP/Post_Test.php to validate that parse_url returns an instance of the WP_Error class when given an empty string.

@cgrycki cgrycki marked this pull request as draft January 31, 2023 16:53
@cgrycki
Copy link
Author

cgrycki commented Jan 31, 2023

I believe a few additional changes will be necessary before this is ready for review. Hope to have those tested and committed soon.

@cgrycki
Copy link
Author

cgrycki commented Feb 6, 2023

I identified an issue last week that I had initially thought may have been a result of the change in this PR. After further investigation, I determined that the issue was unrelated to the changes in this PR and arose from an update to a different WordPress plugin that introduced a setting impacting when the transition_post_status action was triggered. The issue was resolved by configuring that setting in the other plugin.
The code from this PR is working as expected in our production environment. I will mark this as ready for review.

@cgrycki cgrycki marked this pull request as ready for review February 6, 2023 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant