-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block Bindings: Fix showing bindings field values in theme templates #65639
Block Bindings: Fix showing bindings field values in theme templates #65639
Conversation
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 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. |
Size Change: +604 B (+0.03%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
postContext.postType = match[ 1 ]; | ||
} | ||
break; | ||
const themeSlug = post.slug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this case is for theme templates. But still I don't really like the naming.
Maybe we could just use post.slug
on the comparisons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in this commit 🙂 3344a5b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added a nitpick.
…65639) * Move `is_custom` check to page case * Check themeSlug in conditional * Use `post.slug` directly Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: 353c87f |
// If the slug is single-{postType}, infer the post type from the slug. | ||
const postTypesSlugs = | ||
postTypes?.map( ( entity ) => entity.slug ) || []; | ||
const match = post.slug.match( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that post.slug is not part of the dependencies of the useMemo call which means potentially a hidden bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing it out. I started this pull request to address that.
What?
While working on adding this test, I realized that connected blocks in CPT templates like
single-movie
weren't showing the default values. When you create a single-movie template from the editor, it works as expected. However, when you directly create asingle-movie.html
in your theme, it doesn't.This pull request aims to solve that.
Why?
It should work for theme files as well.
How?
After triaging it, it seems that
single-movie.html
is treated as a custom template, even if it is specific to movies. For that reason, I've change the conditional to not rely onpost.is_custom
and directly check the slug. That conditional was there to cover use cases likepage-custom-template
. With the new code, it directly checks that the theme slug matches "page", while previously it was checking the theme slug starts with "page".Testing Instructions
This one is hard to test manually because you need a CPT theme template like
single-movie.html
and cannot be created through the editor UI. It will be covered by this automated test, among others, in the future.Basically, you would need to:
register_meta(
'post',
'movie_title',
array(
'label' => 'Movie Title',
'object_subtype' => 'movie',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'default' => 'Default movie title',
)
);
single-movie.html
file in your theme.