diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index c08869db34b484..e7e904e5072eda 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -625,7 +625,7 @@ Display the publish date for an entry such as a post or page. ([Source](https:// - **Name:** core/post-date - **Category:** theme - **Supports:** color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~ -- **Attributes:** displayType, format, isLink, textAlign +- **Attributes:** displayType, format, isLink, prefix, suffix, textAlign ## Excerpt diff --git a/packages/block-library/src/post-date/block.json b/packages/block-library/src/post-date/block.json index 176e5b6b0ee616..22791fbe9712e7 100644 --- a/packages/block-library/src/post-date/block.json +++ b/packages/block-library/src/post-date/block.json @@ -10,9 +10,17 @@ "textAlign": { "type": "string" }, + "prefix": { + "type": "string", + "default": "" + }, "format": { "type": "string" }, + "suffix": { + "type": "string", + "default": "" + }, "isLink": { "type": "boolean", "default": false diff --git a/packages/block-library/src/post-date/edit.js b/packages/block-library/src/post-date/edit.js index cfb5c572106008..1cad1cde81c771 100644 --- a/packages/block-library/src/post-date/edit.js +++ b/packages/block-library/src/post-date/edit.js @@ -13,6 +13,7 @@ import { AlignmentControl, BlockControls, InspectorControls, + RichText, useBlockProps, __experimentalDateFormatPicker as DateFormatPicker, __experimentalPublishDateTimePicker as PublishDateTimePicker, @@ -30,7 +31,7 @@ import { DOWN } from '@wordpress/keycodes'; import { useSelect } from '@wordpress/data'; export default function PostDateEdit( { - attributes: { textAlign, format, isLink, displayType }, + attributes: { textAlign, format, prefix, suffix, isLink, displayType }, context: { postId, postType: postTypeSlug, queryId }, setAttributes, } ) { @@ -148,7 +149,6 @@ export default function PostDateEdit( { ) } - -
{ postDate }
+
+ setAttributes( { prefix: value } ) } + tagName="span" + /> + { postDate } + setAttributes( { suffix: value } ) } + tagName="span" + /> +
); } diff --git a/packages/block-library/src/post-date/index.php b/packages/block-library/src/post-date/index.php index bcfff02fc178d7..a64507ee38ff59 100644 --- a/packages/block-library/src/post-date/index.php +++ b/packages/block-library/src/post-date/index.php @@ -48,15 +48,27 @@ function render_block_core_post_date( $attributes, $content, $block ) { $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); + $prefix = ''; + if ( isset( $attributes['prefix'] ) && $attributes['prefix'] ) { + $prefix = wp_kses_post( '' . $attributes['prefix'] . '' ); + } + if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { $formatted_date = sprintf( '%2s', get_the_permalink( $post_ID ), $formatted_date ); } + $suffix = ''; + if ( isset( $attributes['suffix'] ) && $attributes['suffix'] ) { + $suffix = wp_kses_post( '' . $attributes['suffix'] . '' ); + } + return sprintf( - '
', + '
%2$s%5$s
', $wrapper_attributes, + $prefix, $unformatted_date, - $formatted_date + $formatted_date, + $suffix ); } diff --git a/test/integration/fixtures/blocks/core__post-date.json b/test/integration/fixtures/blocks/core__post-date.json index ec8dc784b3403b..8f061f73649b5e 100644 --- a/test/integration/fixtures/blocks/core__post-date.json +++ b/test/integration/fixtures/blocks/core__post-date.json @@ -4,7 +4,9 @@ "isValid": true, "attributes": { "isLink": false, - "displayType": "date" + "displayType": "date", + "prefix": "", + "suffix": "" }, "innerBlocks": [] }