Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions backport-changelog/6.9/9702.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/9702
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've closed WordPress/wordpress-develop#9702 in favor of WordPress/wordpress-develop#9949.

I've filed a GB PR to update this backport changelog: #71849.


* https://github.com/WordPress/gutenberg/pull/71483
11 changes: 7 additions & 4 deletions lib/compat/wordpress-6.9/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@

// The following filter can be removed once the minimum required WordPress version is 6.9 or newer.
add_filter(
'block_bindings_supported_attributes_core/post-date',
function ( $attributes ) {
if ( ! in_array( 'datetime', $attributes, true ) ) {
'block_bindings_supported_attributes',
function ( $attributes, $block_type ) {
if ( 'core/image' === $block_type && ! in_array( 'caption', $attributes, true ) ) {
$attributes[] = 'caption';
}
if ( 'core/post-date' === $block_type && ! in_array( 'datetime', $attributes, true ) ) {
$attributes[] = 'datetime';
}
return $attributes;
},
10,
3
2
);

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/utils/block-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const PATTERN_OVERRIDES_SOURCE = 'core/pattern-overrides';
const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
'core/paragraph': [ 'content' ],
'core/heading': [ 'content' ],
'core/image': [ 'id', 'url', 'title', 'alt' ],
'core/image': [ 'id', 'url', 'title', 'alt', 'caption' ],
'core/button': [ 'url', 'text', 'linkTarget', 'rel' ],
'core/post-date': [ 'datetime' ],
};
Expand Down
13 changes: 5 additions & 8 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ export default function Image( {
lockAltControlsMessage,
lockTitleControls = false,
lockTitleControlsMessage,
lockCaption = false,
hideCaptionControls = false,
} = useSelect(
( select ) => {
if ( ! isSingleSelected ) {
Expand All @@ -635,6 +635,7 @@ export default function Image( {
url: urlBinding,
alt: altBinding,
title: titleBinding,
caption: captionBinding,
} = metadata?.bindings || {};
const hasParentPattern = !! context[ 'pattern/overrides' ];
const urlBindingSource = getBlockBindingsSource(
Expand All @@ -658,10 +659,7 @@ export default function Image( {
// Disable editing the link of the URL if the image is inside a pattern instance.
// This is a temporary solution until we support overriding the link on the frontend.
hasParentPattern || arePatternOverridesEnabled,
lockCaption:
// Disable editing the caption if the image is inside a pattern instance.
// This is a temporary solution until we support overriding the caption on the frontend.
hasParentPattern,
hideCaptionControls: !! captionBinding,
lockAltControls:
!! altBinding &&
! altBindingSource?.canUserEditValue?.( {
Expand Down Expand Up @@ -1147,10 +1145,9 @@ export default function Image( {
label={ __( 'Image caption text' ) }
showToolbarButton={
isSingleSelected &&
hasNonContentControls &&
! arePatternOverridesEnabled
( hasNonContentControls || isContentOnlyMode ) &&
! hideCaptionControls
}
readOnly={ lockCaption }
/>
</>
);
Expand Down
8 changes: 7 additions & 1 deletion packages/block-library/src/image/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function save( { attributes } ) {
linkTarget,
sizeSlug,
title,
metadata: { bindings = {} } = {},
} = attributes;

const newRel = ! rel ? undefined : rel;
Expand Down Expand Up @@ -70,6 +71,11 @@ export default function save( { attributes } ) {
/>
);

const displayCaption =
! RichText.isEmpty( caption ) ||
bindings.caption ||
bindings?.__default?.source === 'core/pattern-overrides';

const figure = (
<>
{ href ? (
Expand All @@ -84,7 +90,7 @@ export default function save( { attributes } ) {
) : (
image
) }
{ ! RichText.isEmpty( caption ) && (
{ displayCaption && (
<RichText.Content
className={ __experimentalGetElementClassName( 'caption' ) }
tagName="figcaption"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:image {"metadata":{"bindings":{"caption":{"source":"core/post-data","args":{"key":"date"}}}}} -->
<figure class="wp-block-image"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==" alt="" /><figcaption class="wp-element-caption"></figcaption></figure>
<!-- /wp:image -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"name": "core/image",
"isValid": true,
"attributes": {
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==",
"alt": "",
"caption": "",
"metadata": {
"bindings": {
"caption": {
"source": "core/post-data",
"args": {
"key": "date"
}
}
}
}
},
"innerBlocks": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"blockName": "core/image",
"attrs": {
"metadata": {
"bindings": {
"caption": {
"source": "core/post-data",
"args": {
"key": "date"
}
}
}
}
},
"innerBlocks": [],
"innerHTML": "\n<figure class=\"wp-block-image\"><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==\" alt=\"\" /><figcaption class=\"wp-element-caption\"></figcaption></figure>\n",
"innerContent": [
"\n<figure class=\"wp-block-image\"><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==\" alt=\"\" /><figcaption class=\"wp-element-caption\"></figcaption></figure>\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:image {"metadata":{"bindings":{"caption":{"source":"core/post-data","args":{"key":"date"}}}}} -->
<figure class="wp-block-image"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==" alt=""/><figcaption class="wp-element-caption"></figcaption></figure>
<!-- /wp:image -->
Loading