Theme pattern files are not registered until the pattern cache is cleared
Maintainers usually reply within 1 day
Assessment
This issue has not been assessed yet.
Description
What happens
A pattern file added to a theme's patterns/ directory is not registered on a Studio site. It stays missing across page loads and WP-CLI runs until the theme's pattern cache is cleared.
This affects anyone developing a block theme in Studio, and Studio Code in particular: the agent scaffolds and edits themes, adds a pattern, and then cannot find it in the block pattern registry.
Why
Since WordPress 6.4, WP_Theme::get_block_patterns() caches the theme's pattern file data in a transient. It only bypasses the cache when the site is in theme development mode (wp_is_development_mode( 'theme' )).
Studio sites define WP_ENVIRONMENT_TYPE as local, but leave WP_DEVELOPMENT_MODE empty, so the cache is used.
Reproduce
On a fresh Studio site running Twenty Twenty-Five:
- Load the front page once.
- Add
wp-content/themes/twentytwentyfive/patterns/repro.phpwith the headerSlug: twentytwentyfive/repro. - Run
studio wp eval 'var_dump( WP_Block_Patterns_Registry::get_instance()->is_registered( "twentytwentyfive/repro" ) );', which printsfalse. It's stillfalseafter more page loads. - Run
studio wp eval 'wp_get_theme()->delete_pattern_cache();', and the check from step 3 printstrue.
wp_get_development_mode() returns an empty string on the site.
Suggested fix
In packages/common/lib/mu-plugins.ts, next to the existing WP_ENVIRONMENT_TYPE default, define the development mode when the site has not set it:
if ( ! defined( 'WP_DEVELOPMENT_MODE' ) ) define( 'WP_DEVELOPMENT_MODE', 'theme' );
That snippet runs before wp-settings.php, so it takes effect for both page loads and WP-CLI. Theme development mode is what core provides for local theme work. It also skips the theme.json cache, which helps for the same reason.
A narrower alternative is for Studio Code's file tools to call wp_get_theme()->delete_pattern_cache() after writing to a theme's patterns/ directory. That only covers the agent, though, not people editing themes by hand.
How this was found
In an eval run of the Studio Code agent, it added a slideshow pattern to the theme it had scaffolded. It then spent about 10 tool calls working out why the pattern wasn't registered.
Investigated and drafted with AI assistance (Claude, running in the Pi coding agent): the agent traced the eval transcript, read the WordPress core caching path, and ran the reproduction above on a throwaway Studio site. Reviewed by the author before posting.
- Dominant language
- TypeScript
- Stars
- 543
- Forks
- 104
- Avg merge
- 23h 59m
- Merged PRs (30d)
- 276
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Automattic/studio
-
Enhancement
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Automattic/studio#3017 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Automattic/studio#2868 · 2 comments ·
Maintainers usually reply within 1 day
-
Allow the native PHP worker pool size to be configured (hardcoded to 4)Possibly taken @chubes4 claimed this 1 day ago. Open
Automattic/studio#5238 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
Automattic/studio#5200 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Automattic/studio#5169 ·
Maintainers usually reply within 1 day
All issues in Automattic/studio
Similar issues
-
bug P3 UI/UX
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
StellarState/SS-backend#712 ·
Maintainers usually reply within 1 day
-
area: backend bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
snapotter-hq/SnapOtter#3473 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
gitroomhq/postiz-app#2304 ·
Maintainers usually reply within 1 day
-
harlan-agent-ready-to-implement routine:ci-review
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
harlan-zw/unlighthouse#454 · 2 comments ·
Maintainers usually reply within 1 day