Skip to content
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

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,19 @@ export const ExperimentalEditorProvider = withRegistryProvider(
const postContext = {};
// If it is a template, try to inherit the post type from the slug.
if ( post.type === 'wp_template' ) {
if ( ! post.is_custom ) {
const [ kind ] = post.slug.split( '-' );
switch ( kind ) {
case 'page':
postContext.postType = 'page';
break;
case 'single':
// Infer the post type from the slug.
const postTypesSlugs =
postTypes?.map( ( entity ) => entity.slug ) ||
[];
const match = post.slug.match(
`^single-(${ postTypesSlugs.join(
'|'
) })(?:-.+)?$`
);
if ( match ) {
postContext.postType = match[ 1 ];
}
break;
if ( post.slug === 'page' ) {
postContext.postType = 'page';
} else if ( post.slug === 'single' ) {
postContext.postType = 'post';
} else if ( post.slug.split( '-' )[ 0 ] === 'single' ) {
// 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(
Copy link
Contributor

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.

Copy link
Contributor Author

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.

`^single-(${ postTypesSlugs.join( '|' ) })(?:-.+)?$`
);
if ( match ) {
postContext.postType = match[ 1 ];
}
}
} else if (
Expand Down
Loading