Patterns API: Use the requesting site's version to filter out incompatible patterns #536
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.
This uses the fact that WordPress sites send in the version number with each request to return only patterns that are supported by that version.
For example, the Link in Bio pattern would be flagged as
6.1
, so that only sites with WP 6.1+ will see that result (except not yet, I haven't re-listed that pattern since until this is merged it will cause those console errors).This is a fix for WordPress/gutenberg#45179, though it's not a long-term fix since the version needs to be manually set. Due to the setup of the pattern directory, running WP trunk + Gutenberg, we don't have an easy way to detect vanilla WordPress version issues. Patterns can be flagged manually (like I'll do for Link in Bio), if/when they're reported as broken. On the plus side, this doesn't require a core change :)
The version can be added via a sandbox:
wp --url=wordpress.org/patterns post meta set [post id] wpop_wp_version 6.1
See #517
How to test the changes in this Pull Request:
Apply to a sandbox, and test with this URL — these three patterns have different version settings, so you can change
wp-version
in the URL and see the results change. "Shark Hero Banner" will only show on 6.0+, "Content Writer Block" on 5.9+, and "Simple Table" always.To test it locally, set up some patterns, and add the meta values using wp-cli.
/wp-json/wp/v2/wporg-pattern?_fields=id,title,meta.wpop_wp_version&wp-version=6.1.0