Skip to content

Commit 7936454

Browse files
SantosGuillamotcbravobernal
authored andcommitted
Block Bindings: Change core/pattern-attributes source for core/pattern-overrides (#58434)
* Change `pattern-attributes` for `pattern-overrides` * Use `_x()` function for translations * Add check in post meta source * Update pattern description * Update `_x( )` context to be more concise
1 parent 6042c93 commit 7936454

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

lib/compat/wordpress-6.5/block-bindings/sources/pattern.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ function gutenberg_block_bindings_pattern_overrides_callback( $source_attrs, $bl
2828
}
2929

3030
function gutenberg_register_block_bindings_pattern_overrides_source() {
31-
// Override the "core/pattern-attributes" source from core.
32-
if ( array_key_exists( 'core/pattern-attributes', get_all_registered_block_bindings_sources() ) ) {
33-
unregister_block_bindings_source( 'core/pattern-attributes' );
31+
// Override the "core/pattern-overrides" source from core.
32+
if ( array_key_exists( 'core/pattern-overrides', get_all_registered_block_bindings_sources() ) ) {
33+
unregister_block_bindings_source( 'core/pattern-overrides' );
3434
}
3535
register_block_bindings_source(
36-
'core/pattern-attributes',
36+
'core/pattern-overrides',
3737
array(
38-
'label' => __( 'Pattern Attributes' ),
38+
'label' => _x( 'Pattern Overrides', 'block bindings source' ),
3939
'get_value_callback' => 'gutenberg_block_bindings_pattern_overrides_callback',
4040
)
4141
);

lib/compat/wordpress-6.5/block-bindings/sources/post-meta.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ function gutenberg_block_bindings_post_meta_callback( $source_attrs ) {
1717
$post_id = get_the_ID();
1818
}
1919

20+
// If a post isn't public, we need to prevent
21+
// unauthorized users from accessing the post meta.
22+
$post = get_post( $post_id );
23+
if ( ( $post && 'publish' !== $post->post_status && ! current_user_can( 'read_post', $post_id ) ) || post_password_required( $post_id ) ) {
24+
return null;
25+
}
26+
2027
return get_post_meta( $post_id, $source_attrs['key'], true );
2128
}
2229

@@ -28,7 +35,7 @@ function gutenberg_register_block_bindings_post_meta_source() {
2835
register_block_bindings_source(
2936
'core/post-meta',
3037
array(
31-
'label' => __( 'Post Meta' ),
38+
'label' => _x( 'Post Meta', 'block bindings source' ),
3239
'get_value_callback' => 'gutenberg_block_bindings_post_meta_callback',
3340
)
3441
);

packages/block-library/src/block/edit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ function isPartiallySynced( block ) {
4545
) &&
4646
!! block.attributes.metadata?.bindings &&
4747
Object.values( block.attributes.metadata.bindings ).some(
48-
( binding ) => binding.source === 'core/pattern-attributes'
48+
( binding ) => binding.source === 'core/pattern-overrides'
4949
)
5050
);
5151
}
5252
function getPartiallySyncedAttributes( block ) {
5353
return Object.entries( block.attributes.metadata.bindings )
5454
.filter(
55-
( [ , binding ] ) => binding.source === 'core/pattern-attributes'
55+
( [ , binding ] ) => binding.source === 'core/pattern-overrides'
5656
)
5757
.map( ( [ attributeKey ] ) => attributeKey );
5858
}

packages/patterns/src/components/partial-syncing-controls.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) {
2222
attributes.metadata?.bindings?.[ attributeName ]?.source
2323
);
2424
const isConnectedToOtherSources = attributeSources.every(
25-
( source ) => source && source !== 'core/pattern-attributes'
25+
( source ) => source && source !== 'core/pattern-overrides'
2626
);
2727

2828
// Render nothing if all supported attributes are connected to other sources.
@@ -39,7 +39,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) {
3939
for ( const attributeName of Object.keys( syncedAttributes ) ) {
4040
if (
4141
updatedBindings[ attributeName ]?.source ===
42-
'core/pattern-attributes'
42+
'core/pattern-overrides'
4343
) {
4444
delete updatedBindings[ attributeName ];
4545
}
@@ -59,7 +59,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) {
5959
for ( const attributeName of Object.keys( syncedAttributes ) ) {
6060
if ( ! updatedBindings[ attributeName ] ) {
6161
updatedBindings[ attributeName ] = {
62-
source: 'core/pattern-attributes',
62+
source: 'core/pattern-overrides',
6363
};
6464
}
6565
}
@@ -94,7 +94,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) {
9494
__nextHasNoMarginBottom
9595
label={ __( 'Allow instance overrides' ) }
9696
checked={ attributeSources.some(
97-
( source ) => source === 'core/pattern-attributes'
97+
( source ) => source === 'core/pattern-overrides'
9898
) }
9999
onChange={ ( isChecked ) => {
100100
updateBindings( isChecked );

test/e2e/specs/editor/various/pattern-overrides.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test.describe( 'Pattern Overrides', () => {
9292
id: expect.any( String ),
9393
bindings: {
9494
content: {
95-
source: 'core/pattern-attributes',
95+
source: 'core/pattern-overrides',
9696
},
9797
},
9898
},
@@ -222,7 +222,7 @@ test.describe( 'Pattern Overrides', () => {
222222
const paragraphId = 'paragraph-id';
223223
const { id } = await requestUtils.createBlock( {
224224
title: 'Pattern',
225-
content: `<!-- wp:paragraph {"metadata":{"id":"${ paragraphId }","bindings":{"content":{"source":"core/pattern-attributes"}}}} -->
225+
content: `<!-- wp:paragraph {"metadata":{"id":"${ paragraphId }","bindings":{"content":{"source":"core/pattern-overrides"}}}} -->
226226
<p>Editable</p>
227227
<!-- /wp:paragraph -->`,
228228
status: 'publish',
@@ -270,7 +270,7 @@ test.describe( 'Pattern Overrides', () => {
270270
const { id } = await requestUtils.createBlock( {
271271
title: 'Pattern with overrides',
272272
content: `<!-- wp:buttons -->
273-
<div class="wp-block-buttons"><!-- wp:button {"metadata":{"id":"${ buttonId }","bindings":{"text":{"source":"core/pattern-attributes"},"url":{"source":"core/pattern-attributes"},"linkTarget":{"source":"core/pattern-attributes"}}}} -->
273+
<div class="wp-block-buttons"><!-- wp:button {"metadata":{"id":"${ buttonId }","bindings":{"text":{"source":"core/pattern-overrides"},"url":{"source":"core/pattern-overrides"},"linkTarget":{"source":"core/pattern-overrides"}}}} -->
274274
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button" href="http://wp.org" target="_blank" rel="noreferrer noopener">wp.org</a></div>
275275
<!-- /wp:button --></div>
276276
<!-- /wp:buttons -->`,

0 commit comments

Comments
 (0)