From 83521d65d8092f7aedf34792c7dc4f2302582718 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 30 Jan 2024 12:18:08 +0100 Subject: [PATCH 1/5] Change `pattern-attributes` for `pattern-overrides` --- .../wordpress-6.5/block-bindings/sources/pattern.php | 10 +++++----- packages/block-library/src/block/edit.js | 4 ++-- .../src/components/partial-syncing-controls.js | 8 ++++---- .../e2e/specs/editor/various/pattern-overrides.spec.js | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php index b43484660f1f8..7eb81336748e7 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php @@ -28,14 +28,14 @@ function gutenberg_block_bindings_pattern_overrides_callback( $source_attrs, $bl } function gutenberg_register_block_bindings_pattern_overrides_source() { - // Override the "core/pattern-attributes" source from core. - if ( array_key_exists( 'core/pattern-attributes', get_all_registered_block_bindings_sources() ) ) { - unregister_block_bindings_source( 'core/pattern-attributes' ); + // Override the "core/pattern-overrides" source from core. + if ( array_key_exists( 'core/pattern-overrides', get_all_registered_block_bindings_sources() ) ) { + unregister_block_bindings_source( 'core/pattern-overrides' ); } register_block_bindings_source( - 'core/pattern-attributes', + 'core/pattern-overrides', array( - 'label' => __( 'Pattern Attributes' ), + 'label' => __( 'Pattern Overrides' ), 'get_value_callback' => 'gutenberg_block_bindings_pattern_overrides_callback', ) ); diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index b76b655ee0d94..c940f36e1a8b8 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -45,14 +45,14 @@ function isPartiallySynced( block ) { ) && !! block.attributes.metadata?.bindings && Object.values( block.attributes.metadata.bindings ).some( - ( binding ) => binding.source === 'core/pattern-attributes' + ( binding ) => binding.source === 'core/pattern-overrides' ) ); } function getPartiallySyncedAttributes( block ) { return Object.entries( block.attributes.metadata.bindings ) .filter( - ( [ , binding ] ) => binding.source === 'core/pattern-attributes' + ( [ , binding ] ) => binding.source === 'core/pattern-overrides' ) .map( ( [ attributeKey ] ) => attributeKey ); } diff --git a/packages/patterns/src/components/partial-syncing-controls.js b/packages/patterns/src/components/partial-syncing-controls.js index 0f6cde5ce7d68..f55ee7bdc26d3 100644 --- a/packages/patterns/src/components/partial-syncing-controls.js +++ b/packages/patterns/src/components/partial-syncing-controls.js @@ -22,7 +22,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) { attributes.metadata?.bindings?.[ attributeName ]?.source ); const isConnectedToOtherSources = attributeSources.every( - ( source ) => source && source !== 'core/pattern-attributes' + ( source ) => source && source !== 'core/pattern-overrides' ); // Render nothing if all supported attributes are connected to other sources. @@ -39,7 +39,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) { for ( const attributeName of Object.keys( syncedAttributes ) ) { if ( updatedBindings[ attributeName ]?.source === - 'core/pattern-attributes' + 'core/pattern-overrides' ) { delete updatedBindings[ attributeName ]; } @@ -59,7 +59,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) { for ( const attributeName of Object.keys( syncedAttributes ) ) { if ( ! updatedBindings[ attributeName ] ) { updatedBindings[ attributeName ] = { - source: 'core/pattern-attributes', + source: 'core/pattern-overrides', }; } } @@ -94,7 +94,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) { __nextHasNoMarginBottom label={ __( 'Allow instance overrides' ) } checked={ attributeSources.some( - ( source ) => source === 'core/pattern-attributes' + ( source ) => source === 'core/pattern-overrides' ) } onChange={ ( isChecked ) => { updateBindings( isChecked ); diff --git a/test/e2e/specs/editor/various/pattern-overrides.spec.js b/test/e2e/specs/editor/various/pattern-overrides.spec.js index 541f2f1600ad2..417827a907158 100644 --- a/test/e2e/specs/editor/various/pattern-overrides.spec.js +++ b/test/e2e/specs/editor/various/pattern-overrides.spec.js @@ -92,7 +92,7 @@ test.describe( 'Pattern Overrides', () => { id: expect.any( String ), bindings: { content: { - source: 'core/pattern-attributes', + source: 'core/pattern-overrides', }, }, }, @@ -222,7 +222,7 @@ test.describe( 'Pattern Overrides', () => { const paragraphId = 'paragraph-id'; const { id } = await requestUtils.createBlock( { title: 'Pattern', - content: ` + content: `

Editable

`, status: 'publish', @@ -270,7 +270,7 @@ test.describe( 'Pattern Overrides', () => { const { id } = await requestUtils.createBlock( { title: 'Pattern with overrides', content: ` -
+ `, From 4a0b15577ddb307fe197e92052361eab7e406586 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 30 Jan 2024 13:23:25 +0100 Subject: [PATCH 2/5] Use `_x()` function for translations --- lib/compat/wordpress-6.5/block-bindings/sources/pattern.php | 2 +- lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php index 7eb81336748e7..3e8ac3f6015dc 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php @@ -35,7 +35,7 @@ function gutenberg_register_block_bindings_pattern_overrides_source() { register_block_bindings_source( 'core/pattern-overrides', array( - 'label' => __( 'Pattern Overrides' ), + 'label' => _x( 'Pattern Overrides', 'Label for the block bindings source used for partially synced overrides' ), 'get_value_callback' => 'gutenberg_block_bindings_pattern_overrides_callback', ) ); diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php index 4166ed3243ef0..ed4ebba08fb21 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php @@ -28,7 +28,7 @@ function gutenberg_register_block_bindings_post_meta_source() { register_block_bindings_source( 'core/post-meta', array( - 'label' => __( 'Post Meta' ), + 'label' => _x( 'Post Meta', 'Label for the block bindings source used to connect with post meta' ), 'get_value_callback' => 'gutenberg_block_bindings_post_meta_callback', ) ); From f3f8f781d64e973acd54ed7db46c4ad1b8df1b1d Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 30 Jan 2024 13:31:10 +0100 Subject: [PATCH 3/5] Add check in post meta source --- .../wordpress-6.5/block-bindings/sources/post-meta.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php index ed4ebba08fb21..7d3f5e87947d7 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php @@ -17,6 +17,13 @@ function gutenberg_block_bindings_post_meta_callback( $source_attrs ) { $post_id = get_the_ID(); } + // If a post isn't public, we need to prevent + // unauthorized users from accessing the post meta. + $post = get_post( $post_id ); + if ( ( $post && 'publish' !== $post->post_status && ! current_user_can( 'read_post', $post_id ) ) || post_password_required( $post_id ) ) { + return null; + } + return get_post_meta( $post_id, $source_attrs['key'], true ); } From 68a75963d0fe65c5bd3253fe29cb8e6c71a3c109 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 30 Jan 2024 13:47:43 +0100 Subject: [PATCH 4/5] Update pattern description --- lib/compat/wordpress-6.5/block-bindings/sources/pattern.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php index 3e8ac3f6015dc..c4ff487d0fe9d 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php @@ -35,7 +35,7 @@ function gutenberg_register_block_bindings_pattern_overrides_source() { register_block_bindings_source( 'core/pattern-overrides', array( - 'label' => _x( 'Pattern Overrides', 'Label for the block bindings source used for partially synced overrides' ), + 'label' => _x( 'Pattern Overrides', 'Label for the block bindings source used for synced pattern overrides' ), 'get_value_callback' => 'gutenberg_block_bindings_pattern_overrides_callback', ) ); From 27e9c67370ef58d67fdcb4e2858c5ad2688dbc01 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 30 Jan 2024 13:49:36 +0100 Subject: [PATCH 5/5] Update `_x( )` context to be more concise --- lib/compat/wordpress-6.5/block-bindings/sources/pattern.php | 2 +- lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php index c4ff487d0fe9d..503723596bf9c 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/pattern.php @@ -35,7 +35,7 @@ function gutenberg_register_block_bindings_pattern_overrides_source() { register_block_bindings_source( 'core/pattern-overrides', array( - 'label' => _x( 'Pattern Overrides', 'Label for the block bindings source used for synced pattern overrides' ), + 'label' => _x( 'Pattern Overrides', 'block bindings source' ), 'get_value_callback' => 'gutenberg_block_bindings_pattern_overrides_callback', ) ); diff --git a/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php index 7d3f5e87947d7..e9b84108e52a3 100644 --- a/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php +++ b/lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php @@ -35,7 +35,7 @@ function gutenberg_register_block_bindings_post_meta_source() { register_block_bindings_source( 'core/post-meta', array( - 'label' => _x( 'Post Meta', 'Label for the block bindings source used to connect with post meta' ), + 'label' => _x( 'Post Meta', 'block bindings source' ), 'get_value_callback' => 'gutenberg_block_bindings_post_meta_callback', ) );