-
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
Plugin Block Template editor inconsistency #65584
Comments
Thanks for reporting this issue. However, I'm not certain that it is a bug, or merely how the API is designed? With the example code above it seems you would be trying to overwrite the If we look at this check: https://github.com/WordPress/wordpress-develop/blob/292769dde95d7fec3b4f335af5b1c5cf04054db4/src/wp-includes/class-wp-block-templates-registry.php#L89 It is doing a lookup for If my understanding is correct then maybe we could look to introduce some additional error boundary for checking against I may be misunderstanding @widoz use case, and please forgive me if so. 😃 |
I meant to also tag @getdave and @kevin940726 for insight please. |
Hi @colorful-tones, They do not if the template exists in the theme but it is allowed if the theme does not provide one of them. |
@Aljullu since you have worked on the template registration API, would you be able to provide any insight here? |
Since RC1 is occurring later today and there is no active PR, I think we should punt this to 6.8 or 6.7.1. Thoughts @colorful-tones @getdave @kevin940726? |
Agree 👍 |
Thanks for opening this issue, @widoz. I'm not able to reproduce and I'm not 100% sure to understand what's going on here. A couple of questions:
Also wondering if you can reproduce the issue by hardcoding the add_action( 'init', static function() {
wp_register_block_template(
'templates//page',
[
'title' => 'My Single Page',
'description' => 'This is my single template',
'content' => '<!-- wp:paragraph --><p>This is a plugin-registered template.</p><!-- /wp:paragraph -->',
'post_types' => [ 'page' ],
]
);
} );
In fact, the goal of the API is to allow registering any template, even default WP ones. However, as @widoz mentions, theme templates take priority over plugin-registered templates. So if the theme includes a |
I wondered about this too. Good call out for simplifying the recreation steps. 👍 |
@widoz do you mind clarifying these items please:
|
Hi everyone, sorry about the late reply, I'll try to answer as best as I can @Aljullu
Yes
Unfortunately, I cannot replicate the problem anymore, at least not the way I was able to replicate it the first time (see first video). Now as you can see from the video below, the Template name appears for less than a second. It's not persistent anymore. No differences in using a Screencast.from.2024-10-18.23-31-44.webmUnfortunately I had problems with my local setup, and I had to destroy everything and I've also updated to the latest changes in the plugin, therefore my current installation is no longer the same of the one I had when I was experiencing the issue. |
Thanks for the additional info @widoz. I was finally able to replicate this. As you mentioned, the issue is no longer persistent, but I was able to capture the flash in the video below. custom-template-bug.mp4Steps to replicate:
cc @Aljullu |
The fact that "Swap template" takes a second to load in is not an issue. It happens with or without a registered template. The issue is that the name of the registered template "My Single Page" displays briefly. Here's a screenshot from the video above. My understanding is that if you register a template that is already part of the theme, the theme template takes precedence. At least that's what's noted in the PR. In the case of the example, the If this is just a visual bug, I don't think it's high priority. However, I do want to ensure it is just a visual bug and not something more. |
Thanks for your reporting the issue and your investigation trying to reproduce this, I was able to reproduce too.
Yes, this is my perception as well. There are two requests to the I will investigate it a bit more this week and hopefully come up with a fix, but I agree that this seems to be only a visual bug, it doesn't seem to affect the functionality of the editor or the frontend. |
Fantastic, thanks for the confirmation @Aljullu 🙏
Given this, I recommend we punt to 6.7.1 or 6.8. Thoughts @getdave @colorful-tones? |
I have been investigating this a bit more, the issue seems to be that In any case, I created a PR to fix this in Gutenberg: #66359. @ndiego I would appreciate it if you can take a look or ping somebody to take a look. I can then create the PR in WordPress core, but I want to make sure this is the correct approach, as I'm not very familiar with this logic. |
I was trying to debug a bit the issue based on the @Aljullu comment, I can say the problem is due to one of the two rest calls made when clicking on the The solution used in #66359 might not be practicable, for two main reasons,
register_block_template(
'templates//single',
[
'title' => 'My Single Page',
'description' => 'This is template 1',
'content' => load_template('page'),
'post_types' => [ 'post' ],
]
);
Furthermore, I've registered a new post type, and I've noticed that having the following configuration, the template info (title) is retrieved from the one registered by the plugin while the content comes from the theme (might not be related). register_post_type(
'production',
[
'public' => true,
'label' => 'Production',
'supports' => ['title', 'editor', 'custom-fields'],
'show_in_rest' => true
]
);
register_block_template(
'templates//single-production',
[
'title' => 'My Single Page',
'description' => 'This is template 1',
'content' => load_template('page'),
'post_types' => [ 'production' ],
]
); I don't have a final thought on this to be honest, I'm still trying to understand, specifically about point two. Hope this help a bit. |
You're right, @widoz, the issue was not only in pages, but any other post type. Thanks for pointing it out! I tried a different approach in #66359 which I think might be simpler and has the benefit of containing the changes in the Template registration API code, so we don't need to modify existing functions from core. |
Hi @Aljullu I see, so not passing the query will make the function Have you had a chance to look at the custom post type issue where the title gets changed with the one registered from the plugin? I've not checked yet and I was curious to know if the fix does also solve that issue. It should right? As far as I understanding the following condition is the one that will include the candidate in both cases. if (
! $post_type ||
( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) )
) {
$template_files[ $template_slug ] = $candidate;
} |
Hey there, @widoz,
Yes, exactly!
Do you have some steps to reproduce? I'm not 100% sure to understand what you mean. If in the theme, I create a For example, with this code snippet in a plugin: add_action( 'init', function() {
register_post_type(
'production',
[
'public' => true,
'label' => 'Production',
'supports' => ['title', 'editor', 'custom-fields'],
'show_in_rest' => true,
]
);
register_block_template(
'templates//single-production',
[
'title' => 'My Single Production Template',
'description' => 'This is template 3',
'content' => '<!-- wp:paragraph --><p>This is a plugin-registered template.</p><!-- /wp:paragraph -->',
'post_types' => [ 'production' ],
]
);
} ); If the theme has {
...
"customTemplates": [
...
{
"name": "single-production",
"postTypes": ["production"],
"title": "This is the theme single production template"
}
]
} The theme title will take priority. On the other hand, if the theme doesn't provide a title, we use the one from the plugin, but that's intentional. It means that themes can override plugin templates without the need to declare the template title in Does it make sense? I recognize it's a bit confusing, so I might have missed something. 😅 |
Description
I've noticed that registering a block template with a slug matching exactly
page
even if not applied (so the meta _wp_page_template does not exist) will be applied if and only if I click on the Template within the editor.The template is applied only to the Editor.
Below is the code I've used
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Screencast.from.2024-09-23.23-41-27.webm
Environment info
WordPress Version: 6.7-alpha-59076
Gutenberg Version: 19.3.0-rc.1
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
The text was updated successfully, but these errors were encountered: