From cf7fc3c72cbe3ee309daf786c28a41b79b5f589b Mon Sep 17 00:00:00 2001 From: Huzaifa Al Mesbah Date: Tue, 24 Feb 2026 15:30:33 +0600 Subject: [PATCH 1/4] Post Date: Migrate to textAlign block support --- docs/reference-guides/core-blocks.md | 4 +- .../block-library/src/post-date/block.json | 4 +- .../block-library/src/post-date/deprecated.js | 92 +++++++++++++++++-- packages/block-library/src/post-date/edit.js | 36 +++----- .../core__post-date__deprecated-v4.html | 5 + .../core__post-date__deprecated-v4.json | 59 ++++++++++++ ...core__post-date__deprecated-v4.parsed.json | 43 +++++++++ ...__post-date__deprecated-v4.serialized.html | 5 + 8 files changed, 208 insertions(+), 40 deletions(-) create mode 100644 test/integration/fixtures/blocks/core__post-date__deprecated-v4.html create mode 100644 test/integration/fixtures/blocks/core__post-date__deprecated-v4.json create mode 100644 test/integration/fixtures/blocks/core__post-date__deprecated-v4.parsed.json create mode 100644 test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 76328014059702..b683045089447c 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -716,8 +716,8 @@ Display a custom date. ([Source](https://github.com/WordPress/gutenberg/tree/tru - **Name:** core/post-date - **Category:** theme -- **Supports:** anchor, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~ -- **Attributes:** datetime, format, isLink, textAlign +- **Supports:** anchor, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight, textAlign), ~~html~~ +- **Attributes:** datetime, format, isLink ## Excerpt diff --git a/packages/block-library/src/post-date/block.json b/packages/block-library/src/post-date/block.json index 7952e36af36614..75eb1eda38d8f5 100644 --- a/packages/block-library/src/post-date/block.json +++ b/packages/block-library/src/post-date/block.json @@ -11,9 +11,6 @@ "type": "string", "role": "content" }, - "textAlign": { - "type": "string" - }, "format": { "type": "string" }, @@ -46,6 +43,7 @@ "typography": { "fontSize": true, "lineHeight": true, + "textAlign": true, "__experimentalFontFamily": true, "__experimentalFontWeight": true, "__experimentalFontStyle": true, diff --git a/packages/block-library/src/post-date/deprecated.js b/packages/block-library/src/post-date/deprecated.js index 1aaae679c1e4a8..35a2b2e9a99192 100644 --- a/packages/block-library/src/post-date/deprecated.js +++ b/packages/block-library/src/post-date/deprecated.js @@ -1,12 +1,85 @@ -/** - * External dependencies - */ -import clsx from 'clsx'; - /** * Internal dependencies */ import migrateFontFamily from '../utils/migrate-font-family'; +import migrateTextAlign from '../utils/migrate-text-align'; + +const v4 = { + attributes: { + datetime: { + type: 'string', + role: 'content', + }, + textAlign: { + type: 'string', + }, + format: { + type: 'string', + }, + isLink: { + type: 'boolean', + default: false, + role: 'content', + }, + }, + supports: { + anchor: true, + html: false, + color: { + gradients: true, + link: true, + __experimentalDefaultControls: { + background: true, + text: true, + link: true, + }, + }, + spacing: { + margin: true, + padding: true, + }, + typography: { + fontSize: true, + lineHeight: true, + __experimentalFontFamily: true, + __experimentalFontWeight: true, + __experimentalFontStyle: true, + __experimentalTextTransform: true, + __experimentalTextDecoration: true, + __experimentalLetterSpacing: true, + __experimentalDefaultControls: { + fontSize: true, + }, + }, + interactivity: { + clientNavigation: true, + }, + __experimentalBorder: { + radius: true, + color: true, + width: true, + style: true, + __experimentalDefaultControls: { + radius: true, + color: true, + width: true, + style: true, + }, + }, + }, + save() { + return null; + }, + migrate: migrateTextAlign, + isEligible( attributes ) { + return ( + !! attributes.textAlign || + !! attributes.className?.match( + /\bhas-text-align-(left|center|right)\b/ + ) + ); + }, +}; const v3 = { attributes: { @@ -178,10 +251,9 @@ const v2 = { migrate( { className, displayType, metadata, ...otherAttributes } ) { if ( displayType === 'date' || displayType === 'modified' ) { if ( displayType === 'modified' ) { - className = clsx( - className, - 'wp-block-post-date__modified-date' - ); + className = [ className, 'wp-block-post-date__modified-date' ] + .filter( Boolean ) + .join( ' ' ); } return { @@ -254,4 +326,4 @@ const v1 = { * * See block-deprecation.md */ -export default [ v3, v2, v1 ]; +export default [ v4, v3, v2, v1 ]; diff --git a/packages/block-library/src/post-date/edit.js b/packages/block-library/src/post-date/edit.js index ce8f1d6e12a371..a14feb87b8ea41 100644 --- a/packages/block-library/src/post-date/edit.js +++ b/packages/block-library/src/post-date/edit.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import clsx from 'clsx'; - /** * WordPress dependencies */ @@ -14,7 +9,6 @@ import { getSettings as getDateSettings, } from '@wordpress/date'; import { - AlignmentControl, BlockControls, InspectorControls, store as blockEditorStore, @@ -41,19 +35,18 @@ import { store as blocksStore } from '@wordpress/blocks'; * Internal dependencies */ import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; +import useDeprecatedTextAlign from '../utils/deprecated-text-align-attributes'; -export default function PostDateEdit( { - attributes, - context: { postType: postTypeSlug, queryId }, - setAttributes, - name, -} ) { - const { datetime, textAlign, format, isLink } = attributes; - const blockProps = useBlockProps( { - className: clsx( { - [ `has-text-align-${ textAlign }` ]: textAlign, - } ), - } ); +export default function PostDateEdit( props ) { + const { + attributes, + context: { postType: postTypeSlug, queryId }, + setAttributes, + name, + } = props; + useDeprecatedTextAlign( props ); + const { datetime, format, isLink } = attributes; + const blockProps = useBlockProps(); const dropdownMenuProps = useToolsPanelDropdownMenuProps(); // Use internal state instead of a ref to make sure that the component @@ -129,13 +122,6 @@ export default function PostDateEdit( { { ( blockEditingMode === 'default' || ! isDescendentOfQueryLoop ) && ( - { - setAttributes( { textAlign: nextAlign } ); - } } - /> - { activeBlockVariationName !== 'post-date-modified' && ( ! isDescendentOfQueryLoop || ! activeBlockVariationName ) && ( diff --git a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.html b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.html new file mode 100644 index 00000000000000..437c6c22a7cf3d --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.html @@ -0,0 +1,5 @@ + + + + + diff --git a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json new file mode 100644 index 00000000000000..e98640c007fd6f --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json @@ -0,0 +1,59 @@ +[ + { + "name": "core/post-date", + "isValid": true, + "attributes": { + "textAlign": "left", + "isLink": false, + "metadata": { + "bindings": { + "datetime": { + "source": "core/post-data", + "args": { + "field": "date" + } + } + } + } + }, + "innerBlocks": [] + }, + { + "name": "core/post-date", + "isValid": true, + "attributes": { + "textAlign": "center", + "isLink": false, + "metadata": { + "bindings": { + "datetime": { + "source": "core/post-data", + "args": { + "field": "date" + } + } + } + } + }, + "innerBlocks": [] + }, + { + "name": "core/post-date", + "isValid": true, + "attributes": { + "textAlign": "right", + "isLink": false, + "metadata": { + "bindings": { + "datetime": { + "source": "core/post-data", + "args": { + "field": "date" + } + } + } + } + }, + "innerBlocks": [] + } +] diff --git a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.parsed.json b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.parsed.json new file mode 100644 index 00000000000000..84c65556181b14 --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.parsed.json @@ -0,0 +1,43 @@ +[ + { + "blockName": "core/post-date", + "attrs": { + "textAlign": "left" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\n", + "innerContent": [ "\n\n" ] + }, + { + "blockName": "core/post-date", + "attrs": { + "textAlign": "center" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\n", + "innerContent": [ "\n\n" ] + }, + { + "blockName": "core/post-date", + "attrs": { + "textAlign": "right" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + } +] diff --git a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html new file mode 100644 index 00000000000000..548566fe5c9cd5 --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html @@ -0,0 +1,5 @@ + + + + + From d5ff6a9d235b1573450a38934cee8afb4daf754f Mon Sep 17 00:00:00 2001 From: Huzaifa Al Mesbah Date: Sat, 14 Mar 2026 21:50:46 +0600 Subject: [PATCH 2/4] Consolidate conditional checks in Post Date block Combine nested conditionals into a single check to avoid empty BlockControls wrapper components. Co-Authored-By: Claude Opus 4.6 --- packages/block-library/src/post-date/edit.js | 111 +++++++++---------- 1 file changed, 54 insertions(+), 57 deletions(-) diff --git a/packages/block-library/src/post-date/edit.js b/packages/block-library/src/post-date/edit.js index a14feb87b8ea41..8b0ce36ad168b6 100644 --- a/packages/block-library/src/post-date/edit.js +++ b/packages/block-library/src/post-date/edit.js @@ -119,64 +119,61 @@ export default function PostDateEdit( props ) { } return ( <> - { ( blockEditingMode === 'default' || - ! isDescendentOfQueryLoop ) && ( - - { activeBlockVariationName !== 'post-date-modified' && - ( ! isDescendentOfQueryLoop || - ! activeBlockVariationName ) && ( - - ( - - setAttributes( { - datetime: newDatetime, - } ) - } - is12Hour={ is12HourFormat( - siteTimeFormat - ) } - onClose={ onClose } - dateOrder={ - /* translators: Order of day, month, and year. Available formats are 'dmy', 'mdy', and 'ymd'. */ - _x( 'dmy', 'date order' ) - } + { ( blockEditingMode === 'default' || ! isDescendentOfQueryLoop ) && + activeBlockVariationName !== 'post-date-modified' && + ( ! isDescendentOfQueryLoop || ! activeBlockVariationName ) && ( + + + ( + + setAttributes( { + datetime: newDatetime, + } ) + } + is12Hour={ is12HourFormat( + siteTimeFormat + ) } + onClose={ onClose } + dateOrder={ + /* translators: Order of day, month, and year. Available formats are 'dmy', 'mdy', and 'ymd'. */ + _x( 'dmy', 'date order' ) + } + /> + ) } + renderToggle={ ( { isOpen, onToggle } ) => { + const openOnArrowDown = ( event ) => { + if ( + ! isOpen && + event.keyCode === DOWN + ) { + event.preventDefault(); + onToggle(); + } + }; + return ( + - ) } - renderToggle={ ( { isOpen, onToggle } ) => { - const openOnArrowDown = ( event ) => { - if ( - ! isOpen && - event.keyCode === DOWN - ) { - event.preventDefault(); - onToggle(); - } - }; - return ( - - ); - } } - /> - - ) } - - ) } + ); + } } + /> + + + ) } Date: Sat, 14 Mar 2026 22:26:54 +0600 Subject: [PATCH 3/4] Fix Post Date v4 deprecation migration and revert clsx removal --- .../block-library/src/post-date/deprecated.js | 17 ++++++--- .../core__post-date__deprecated-v4.json | 36 +++++-------------- ...__post-date__deprecated-v4.serialized.html | 6 ++-- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/packages/block-library/src/post-date/deprecated.js b/packages/block-library/src/post-date/deprecated.js index 35a2b2e9a99192..69aa509e8e9141 100644 --- a/packages/block-library/src/post-date/deprecated.js +++ b/packages/block-library/src/post-date/deprecated.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import clsx from 'clsx'; + /** * Internal dependencies */ @@ -251,9 +256,10 @@ const v2 = { migrate( { className, displayType, metadata, ...otherAttributes } ) { if ( displayType === 'date' || displayType === 'modified' ) { if ( displayType === 'modified' ) { - className = [ className, 'wp-block-post-date__modified-date' ] - .filter( Boolean ) - .join( ' ' ); + className = clsx( + className, + 'wp-block-post-date__modified-date' + ); } return { @@ -274,8 +280,11 @@ const v2 = { isEligible( attributes ) { // If there's neither an explicit `datetime` attribute nor a block binding for that attribute, // then we're dealing with an old version of the block. + // Exclude blocks with `textAlign`, as those are handled by the v4 deprecation. return ( - ! attributes.datetime && ! attributes?.metadata?.bindings?.datetime + ! attributes.textAlign && + ! attributes.datetime && + ! attributes?.metadata?.bindings?.datetime ); }, }; diff --git a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json index e98640c007fd6f..f826aeb5de42ac 100644 --- a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json +++ b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json @@ -3,16 +3,10 @@ "name": "core/post-date", "isValid": true, "attributes": { - "textAlign": "left", "isLink": false, - "metadata": { - "bindings": { - "datetime": { - "source": "core/post-data", - "args": { - "field": "date" - } - } + "style": { + "typography": { + "textAlign": "left" } } }, @@ -22,16 +16,10 @@ "name": "core/post-date", "isValid": true, "attributes": { - "textAlign": "center", "isLink": false, - "metadata": { - "bindings": { - "datetime": { - "source": "core/post-data", - "args": { - "field": "date" - } - } + "style": { + "typography": { + "textAlign": "center" } } }, @@ -41,16 +29,10 @@ "name": "core/post-date", "isValid": true, "attributes": { - "textAlign": "right", "isLink": false, - "metadata": { - "bindings": { - "datetime": { - "source": "core/post-data", - "args": { - "field": "date" - } - } + "style": { + "typography": { + "textAlign": "right" } } }, diff --git a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html index 548566fe5c9cd5..7e3b7f649dc42d 100644 --- a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html +++ b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html @@ -1,5 +1,5 @@ - + - + - + From e9ee2654f1b8accb14e4f06dc68b9a6d592e53e5 Mon Sep 17 00:00:00 2001 From: Huzaifa Al Mesbah Date: Tue, 17 Mar 2026 14:00:07 +0600 Subject: [PATCH 4/4] Fix Post Date v4 deprecation migration and add migrateTextAlign to v1-v3 --- .../block-library/src/post-date/deprecated.js | 17 +++++------ .../core__post-date__deprecated-v4.json | 30 +++++++++++++++++++ ...__post-date__deprecated-v4.serialized.html | 6 ++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/packages/block-library/src/post-date/deprecated.js b/packages/block-library/src/post-date/deprecated.js index 69aa509e8e9141..84295eea2f5513 100644 --- a/packages/block-library/src/post-date/deprecated.js +++ b/packages/block-library/src/post-date/deprecated.js @@ -165,7 +165,7 @@ const v3 = { ...otherAttributes } ) { // Change the block bindings source argument name from "key" to "field". - return { + return migrateTextAlign( { metadata: { bindings: { datetime: { @@ -177,7 +177,7 @@ const v3 = { ...otherMetadata, }, ...otherAttributes, - }; + } ); }, isEligible( attributes ) { return ( @@ -262,7 +262,7 @@ const v2 = { ); } - return { + return migrateTextAlign( { ...otherAttributes, className, metadata: { @@ -274,17 +274,14 @@ const v2 = { }, }, }, - }; + } ); } }, isEligible( attributes ) { // If there's neither an explicit `datetime` attribute nor a block binding for that attribute, // then we're dealing with an old version of the block. - // Exclude blocks with `textAlign`, as those are handled by the v4 deprecation. return ( - ! attributes.textAlign && - ! attributes.datetime && - ! attributes?.metadata?.bindings?.datetime + ! attributes.datetime && ! attributes?.metadata?.bindings?.datetime ); }, }; @@ -321,7 +318,9 @@ const v1 = { save() { return null; }, - migrate: migrateFontFamily, + migrate( attributes ) { + return migrateTextAlign( migrateFontFamily( attributes ) ); + }, isEligible( { style } ) { return style?.typography?.fontFamily; }, diff --git a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json index f826aeb5de42ac..14d29e174d6a84 100644 --- a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json +++ b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.json @@ -8,6 +8,16 @@ "typography": { "textAlign": "left" } + }, + "metadata": { + "bindings": { + "datetime": { + "source": "core/post-data", + "args": { + "field": "date" + } + } + } } }, "innerBlocks": [] @@ -21,6 +31,16 @@ "typography": { "textAlign": "center" } + }, + "metadata": { + "bindings": { + "datetime": { + "source": "core/post-data", + "args": { + "field": "date" + } + } + } } }, "innerBlocks": [] @@ -34,6 +54,16 @@ "typography": { "textAlign": "right" } + }, + "metadata": { + "bindings": { + "datetime": { + "source": "core/post-data", + "args": { + "field": "date" + } + } + } } }, "innerBlocks": [] diff --git a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html index 7e3b7f649dc42d..f06bd6a951b3d9 100644 --- a/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html +++ b/test/integration/fixtures/blocks/core__post-date__deprecated-v4.serialized.html @@ -1,5 +1,5 @@ - + - + - +