Skip to content

Commit

Permalink
Block Bindings: Fix showing bindings field values in theme templates (W…
Browse files Browse the repository at this point in the history
…ordPress#65639)

* Move `is_custom` check to page case

* Check themeSlug in conditional

* Use `post.slug` directly

Co-authored-by: SantosGuillamot <[email protected]>
Co-authored-by: cbravobernal <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent 893d684 commit 0ee3ed6
Showing 1 changed file with 13 additions and 20 deletions.
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(
`^single-(${ postTypesSlugs.join( '|' ) })(?:-.+)?$`
);
if ( match ) {
postContext.postType = match[ 1 ];
}
}
} else if (
Expand Down

0 comments on commit 0ee3ed6

Please sign in to comment.