Skip to content

Fix remote theme patterns not rendering on the front end#75626

Open
Haruto-works333 wants to merge 1 commit intoWordPress:trunkfrom
Haruto-works333:fix/register-remote-theme-patterns-on-init
Open

Fix remote theme patterns not rendering on the front end#75626
Haruto-works333 wants to merge 1 commit intoWordPress:trunkfrom
Haruto-works333:fix/register-remote-theme-patterns-on-init

Conversation

@Haruto-works333
Copy link
Copy Markdown

What?

Closes #64104

Adds gutenberg_register_remote_theme_patterns() which registers remote theme patterns (from the Pattern Directory)
on init, so they are available when rendering templates on the front end.

Why?

When a theme registers a remote pattern via theme.json and references it in a template file (e.g., <!-- wp:pattern {"slug":"clients-section"} /-->), the pattern displays in the Site Editor but not on the front end.

This happens because _register_remote_theme_patterns() is only called from the REST API endpoint
(WP_REST_Block_Patterns_Controller::get_items()). The Site Editor triggers this endpoint, but front-end rendering
does not — so remote patterns are never registered.

Additionally, the core function cannot simply be hooked to init because it uses rest_do_request() internally,
which enforces the edit_posts permission check — causing it to silently fail for anonymous visitors.

How?

The new gutenberg_register_remote_theme_patterns() function:

  • Fetches patterns directly from the WordPress.org API via wp_remote_get(), bypassing the REST permission layer
  • Shares the same transient cache (1-hour TTL) used by WP_REST_Pattern_Directory_Controller, avoiding duplicate HTTP
    requests
  • Applies the same sanitization as the REST controller's prepare_item_for_response()
  • Respects the should_load_remote_block_patterns filter

Testing Instructions

  1. Activate the Twenty Twenty-Four theme
  2. Set reading settings to "Your latest posts" (Settings → Reading)
  3. Edit wp-content/themes/twentytwentyfour/templates/home.html and add:
    <!-- wp:pattern {"slug":"clients-section"} /-->
    
  4. Visit the front end — the "Clients Section" pattern should be visible

Testing Instructions for Keyboard

This change affects server-side pattern registration only. No UI or keyboard interaction changes.

Screenshots or screencast

Before After
スクリーンショット 2026-02-18 001926 スクリーンショット 2026-02-18 002230

@github-actions
Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Haruto-works333, @margarita-boomCodes, @sangtlee, @Ardmark.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: Haruto-works333, margarita-boomCodes, sangtlee, Ardmark.

Co-authored-by: HosseinKarami <hosseinkarami@git.wordpress.org>
Co-authored-by: SirLouen <sirlouen@git.wordpress.org>
Co-authored-by: sntran <sntran@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Feb 17, 2026
@github-actions
Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @Haruto-works333! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@Haruto-works333
Copy link
Copy Markdown
Author

Hi, I've linked my GitHub and WordPress.org accounts after opening this PR. If this PR looks good to merge, could someone add the props-bot label to refresh the contributor list? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Patterns from the pattern directory do not show if placed in a template

1 participant