From 6a6b3a3c27a201d2dc47348db90b346c85d93f64 Mon Sep 17 00:00:00 2001 From: Mario Santos <34552881+SantosGuillamot@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:13:42 +0200 Subject: [PATCH] Block Bindings: Always prioritize using context in post meta source logic (#65449) * Use `getCurrentPostType` * Change conditional to prioritize context Co-authored-by: SantosGuillamot Co-authored-by: gziolo --- packages/editor/src/bindings/post-meta.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/editor/src/bindings/post-meta.js b/packages/editor/src/bindings/post-meta.js index 20013bd8f246b..572cd0b525a00 100644 --- a/packages/editor/src/bindings/post-meta.js +++ b/packages/editor/src/bindings/post-meta.js @@ -11,10 +11,16 @@ import { unlock } from '../lock-unlock'; function getMetadata( registry, context, registeredFields ) { let metaFields = {}; - const { type } = registry.select( editorStore ).getCurrentPost(); + const type = registry.select( editorStore ).getCurrentPostType(); const { getEditedEntityRecord } = registry.select( coreDataStore ); - if ( type === 'wp_template' ) { + if ( context?.postType && context?.postId ) { + metaFields = getEditedEntityRecord( + 'postType', + context?.postType, + context?.postId + ).meta; + } else if ( type === 'wp_template' ) { // Populate the `metaFields` object with the default values. Object.entries( registeredFields || {} ).forEach( ( [ key, props ] ) => { @@ -23,12 +29,6 @@ function getMetadata( registry, context, registeredFields ) { } } ); - } else { - metaFields = getEditedEntityRecord( - 'postType', - context?.postType, - context?.postId - ).meta; } return metaFields;