Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
Closes #871
Fixes two issues in the pattern file header generation:
pattern_from_templatewas using the template slug as the title instead of the human-readable$template->titlelabel shown in the Site Editor.pattern_from_wp_blockwas writing pattern category names into theCategoriesheader instead of taxonomy slugs.Why?
For example, when a user exported a theme, the generated pattern
.phpfiles had:Title: archive-productinstead ofTitle: Product Catalog, making patterns hard to identify in the inserter.Categories: Bannersinstead ofCategories: banner, breaking category filtering in the block inserter since Core matches by slug.How?
In
includes/create-theme/theme-patterns.php:pattern_from_template: reads$template->titlewhen present, falls back to$template->slugif absent or empty. Applies the existing*/→*/escaping to the title as well.pattern_from_wp_block: changeswp_list_pluck( $pattern_category_list, 'name' )towp_list_pluck( $pattern_category_list, 'slug' ).In
tests/test-theme-patterns.php:test_pattern_from_template_uses_title_not_slug: Checks that the pattern title uses the human-readable title of the template over its slug.test_pattern_from_template_falls_back_to_slug_when_title_empty: Checks that an empty or missing title falls back to the slug.test_pattern_from_template_escapes_comment_closer_in_title: Checks that*/in the title is safely escaped to*/, preventing the docblock of the pattern file from closing prematurely and causing PHP syntax errors or code injection.test_pattern_from_wp_block_uses_category_slugs_not_names: Checks that categories writes the category slug instead of its display name.test_pattern_from_wp_block_uses_multiple_category_slugs: Checks that multiple categories are exported as comma-separated slugs.Testing Instructions
Unit tests:
npm run test:unit:php:setup(starts wp-env).npm run test:unit:php:base -- --filter Test_Create_Block_Theme_Patterns.Manual test:
patterns/*.php. TheTitle:header should match the Site Editor label, not the file slug, andCategories:should match the file slug.Use of AI Tools