Fix remote theme patterns not rendering on the front end#75626
Fix remote theme patterns not rendering on the front end#75626Haruto-works333 wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
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.
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. |
|
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 Unlinked AccountsThe 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. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 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. |
|
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 |
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.jsonand 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 renderingdoes not — so remote patterns are never registered.
Additionally, the core function cannot simply be hooked to
initbecause it usesrest_do_request()internally,which enforces the
edit_postspermission check — causing it to silently fail for anonymous visitors.How?
The new
gutenberg_register_remote_theme_patterns()function:wp_remote_get(), bypassing the REST permission layerWP_REST_Pattern_Directory_Controller, avoiding duplicate HTTPrequests
prepare_item_for_response()should_load_remote_block_patternsfilterTesting Instructions
wp-content/themes/twentytwentyfour/templates/home.htmland add:Testing Instructions for Keyboard
This change affects server-side pattern registration only. No UI or keyboard interaction changes.
Screenshots or screencast