-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synced Patterns iteration for WordPress 6.7 (Draft) #62566
Comments
Thanks for putting all this together! I'm sure many of these features will be complex to implement (and many are quite related), but from my perspective the standout here for me would be #59272 (Add support for synced theme patterns (with overrides), as it sounds like that would really make the feature impactful for theme developers, or agencies that build a theme that'll be used across a number of clients. |
Just adding a 👍 from me. My goal is to sync every pattern in my theme so that I can keep the design updated on a user's site without them having to reimplement the updated patterns in their posts, pages, and customized templates. |
I just finished an article on the WordPress Developer Blog covering the introduction of pattern overrides. This enhancement is amazing, but it has limited applications for agency developers due to the current limitations of synced patterns. In the post, I use the example of a Card layout. Here's a screenshot of the finished product with overrides. While this was created in the Editor, which is great for many types of WordPress users, folks building sites for clients would often like to keep this design in a pattern file provided by the theme. This would allow them to keep the file in version control and serve any future updates to the design through the pattern file instead of having to manually update the synced pattern stored in the database. Allowed themes to include synced patterns would be a massive win for this user base and dramatically increase the power of patterns and block themes. |
I can only second what @ndiego shared above. Besides the ability to have synced patterns in themes however there is one additional thing that would make this even more powerful. And that is the ability to add custom block overrides in custom blocks. For example in a custom icon block I want to be able to allow folks to override the icon used. Is that something that can get tracked here or should it get tracked with GbR block bindings feature? |
Nice post @ndiego, thanks a lot. It will sure be an awesome enhancement.
Doing this is not that difficult if we try to do it the easy and direct way: save them in xml format instead of saving theme as files in the patterns subfolder, and import them in the WordPress installation using the wp import / export tool. There are two problems here:
So with solution to this two problems, there is nothing that would keep us from including synced patterns in themes. Just in the synced-patterns subfolder in xml format or in the assets/xml subfolder. |
This is an interesting approach, but I strongly suggest that synced patterns operate the same way unsynced patterns do in theme folders. They should be basically identical except for a few block attributes. While this approach may be more complicated to architect, the end result would be a simpler theme development experience. |
Yes, you are probably right. |
I've been thinking about this issue and the different use-cases mentioned here (also in relation to the unification of patterns and template parts) with the goal about simplifying the concepts in the process and unifying everything. I believe the more we consolidate, the better is for theme and plugin authors to understand what's possible and for users to understand how to use the features. So with this in mind, here's a proposal:
What needs to be done to achieve this?An iterative process is needed in order to achieve the above without breaking change while offering a migration path to this "consolidated" pattern-based approach.
Aside I created a very similar proposal for style variations and I believe that if we do things properly, the three concepts (patterns, style variations and templates) will end up behaving exactly the same way:
|
This is something that will be important to get right. If the plan is to unify patterns/template parts in the future, then it'll make sense for this endpoint to return template parts, but it'll be challenging to have it work that way from the start until all the smaller details are solved (areas, origins, sources etc.). Perhaps developing an experimental endpoint in the plugin first is the way to go. I mentioned in a comment that it might be good to try and help migrate the navigation block to use slugs first, and hopefully learn from that what the right solution is for patterns - #55911 (comment). |
On the endpoint, I agree it's important to get right. I was thinking that we can probably explore "just" copying what we already do for template and template parts's endpoint and just use the "patterns registry" as the "source". The DataViews page in the site editor for "patterns" mix and matches between using the template part REST API and patterns which seems like an opportunity to try and test (unify) that endpoint. |
It is possible to use a manually marked up Imagine this is an excerpt from <!-- wp:block {"postName": "product-card"} /--> The filter below will extract the add_filter(
'render_block',
function($block_content, $block) {
if('core/block' !== $block['blockName']) {
return $block_content;
}
if(isset($block['attrs']['postName'])) {
$post_name = $block['attrs']['postName'];
$args = array(
'post_type' => 'wp_block',
'name' => $post_name
);
$results = get_posts($args);
if(count($results) > 0) {
$pattern = $results[0];
$block_content = do_blocks(sprintf(
'<!-- wp:block {"ref": %d} /-->',
$pattern->ID
));
}
}
return $block_content;
}, 10, 2
); This can allow a theme developer to use synced patterns in their template, patterns, and template parts files, provided the site's database contains a Perhaps that example is hardly a solution. I do think it is an interesting approach using some of the existing API. With a bit more hackery, it should be possible to have synced patterns inserted via a post's block editor bear the I understand the conversation in this thread to be quite large in scope. There's talk about unifying template parts and patterns, working on the REST API, etc. My comprehension of that stuff isn't great. I've only recently grasped the difference between template parts and patterns (now that I get it, I think the difference is warranted.) I still don't understand why theme pattern files can't be synced, but I suspect it has something to do with the fact that they are stored as posts. What interests me in the proposal so far is this:
As I see it, adding this attribute accomplishes 90% of what developers like me need without causing any great upheaval in the existing block paradigms. It may also help refocus on the fact that patterns are posts, and that they should be given the same economy other post types get, such as reference by their slug. |
Is it possible to add postmeta to the database when a Synced pattern is saved, this would make it easier to identify when users export a theme and save templates, patterns and assets, related to WordPress/create-block-theme#675 |
I did an initial exploration based on @youknowriad proposal, I can confirm that we need to address the REST API part first as the
💯, at this point, we shouldn't extend the |
Just want to mention that this PR is very close to landing #61577 and that it adds a registry for templates as well bringing them even closer to patterns. (register template, fetch template using slug...). Something to keep in mind for consistency as we implement the REST API changes for patterns. |
I am looking at patterns from the general user kind of view. As in how do I want to customize the content I have available for my own site.
I went ahead and made a video: https://youtu.be/Y8qi7LIgZic |
Very unlikely this will make it into 6.7 – I've punted it in the project board. |
Unsync a pattern is also a need see #66774 |
Succeeds #59819.
This is currently a draft and needs discussion/refinement
Improved customization flows for synced patterns / Theme bundling of synced patterns
The following issues solve a number of related aims:
Related issues
Patterns as sections
Connects with the work on section styling and zoomed out editing.
Pattern overrides / Block bindings
Continuation of block bindings and pattern overrides.
TODO: Track anything punted from the 6.6 Beta/RC period. There may also be further UI improvements to pattern overrides to define.
Extensibility
Code Quality
The text was updated successfully, but these errors were encountered: