diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md
index eb132d03c1d18..3ba0f74c68bb2 100644
--- a/docs/reference-guides/core-blocks.md
+++ b/docs/reference-guides/core-blocks.md
@@ -60,7 +60,7 @@ Prompt visitors to take action with a group of button-style links. ([Source](htt
- **Name:** core/buttons
- **Category:** design
- **Supports:** align (full, wide), anchor, spacing (blockGap, margin)
-- **Attributes:**
+- **Attributes:**
## Calendar
@@ -168,7 +168,7 @@ Contains the block elements used to display a comment, like the title, date, aut
- **Name:** core/comment-template
- **Category:** design
- **Supports:** align, ~~html~~, ~~reusable~~
-- **Attributes:**
+- **Attributes:**
## Comments
@@ -204,7 +204,7 @@ Displays a list of page numbers for comments pagination. ([Source](https://githu
- **Name:** core/comments-pagination-numbers
- **Category:** theme
- **Supports:** ~~html~~, ~~reusable~~
-- **Attributes:**
+- **Attributes:**
## Previous Page
@@ -420,7 +420,7 @@ Separate your content into a multi-page experience. ([Source](https://github.com
- **Name:** core/nextpage
- **Category:** design
- **Supports:** ~~className~~, ~~customClassName~~, ~~html~~
-- **Attributes:**
+- **Attributes:**
## Page List
@@ -485,15 +485,6 @@ This block is deprecated. Please use the Comments block instead. ([Source](https
- **Supports:** ~~html~~, ~~inserter~~
- **Attributes:** commentId
-## Post Comments (deprecated)
-
-This block is deprecated. Please use the Comments block instead. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/post-comments))
-
-- **Name:** core/post-comments
-- **Category:** theme
-- **Supports:** align (full, wide), color (background, gradients, link, text), typography (fontSize, lineHeight), ~~html~~, ~~inserter~~
-- **Attributes:** textAlign
-
## Post Comments Count
Display a post's comments count. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/post-comments-count))
@@ -528,7 +519,7 @@ Displays the contents of a post or page. ([Source](https://github.com/WordPress/
- **Name:** core/post-content
- **Category:** theme
- **Supports:** align (full, wide), ~~html~~
-- **Attributes:**
+- **Attributes:**
## Post Date
@@ -573,7 +564,7 @@ Contains the block elements used to render a post, like the title, date, feature
- **Name:** core/post-template
- **Category:** theme
- **Supports:** align, ~~html~~, ~~reusable~~
-- **Attributes:**
+- **Attributes:**
## Post Terms
@@ -627,7 +618,7 @@ Contains the block elements used to render content when no query results are fou
- **Name:** core/query-no-results
- **Category:** theme
- **Supports:** align, color (background, gradients, link, text), ~~html~~, ~~reusable~~
-- **Attributes:**
+- **Attributes:**
## Pagination
@@ -654,7 +645,7 @@ Displays a list of page numbers for pagination ([Source](https://github.com/Word
- **Name:** core/query-pagination-numbers
- **Category:** theme
- **Supports:** color (background, gradients, ~~text~~), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
-- **Attributes:**
+- **Attributes:**
## Previous Page
diff --git a/lib/blocks.php b/lib/blocks.php
index 18a9eb34ff166..39f94ae0aaccc 100644
--- a/lib/blocks.php
+++ b/lib/blocks.php
@@ -63,6 +63,7 @@ function gutenberg_reregister_core_block_types() {
'comments-pagination-numbers.php' => 'core/comments-pagination-numbers',
'comments-pagination-previous.php' => 'core/comments-pagination-previous',
'comments-title.php' => 'core/comments-title',
+ 'comments.php' => 'core/comments-query-loop',
'file.php' => 'core/file',
'home-link.php' => 'core/home-link',
'image.php' => 'core/image',
diff --git a/packages/block-library/src/comments/block.json b/packages/block-library/src/comments/block.json
index 582de73d8d0e9..151664b2904ff 100644
--- a/packages/block-library/src/comments/block.json
+++ b/packages/block-library/src/comments/block.json
@@ -10,6 +10,9 @@
"tagName": {
"type": "string",
"default": "div"
+ },
+ "legacy": {
+ "type": "boolean"
}
},
"supports": {
@@ -25,5 +28,6 @@
}
}
},
- "editorStyle": "wp-block-comments-editor"
+ "editorStyle": "wp-block-comments-editor",
+ "usesContext": [ "postId", "postType" ]
}
diff --git a/packages/block-library/src/comments/edit/index.js b/packages/block-library/src/comments/edit/index.js
new file mode 100644
index 0000000000000..888292d03513d
--- /dev/null
+++ b/packages/block-library/src/comments/edit/index.js
@@ -0,0 +1,131 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+
+/**
+ * WordPress dependencies
+ */
+import {
+ AlignmentControl,
+ BlockControls,
+ Warning,
+ useBlockProps,
+ useInnerBlocksProps,
+ store as blockEditorStore,
+} from '@wordpress/block-editor';
+import { __, sprintf } from '@wordpress/i18n';
+import { useSelect } from '@wordpress/data';
+import { useEntityProp, store as coreStore } from '@wordpress/core-data';
+
+/**
+ * Internal dependencies
+ */
+import CommentsInspectorControls from './comments-inspector-controls';
+import Placeholder from './placeholder';
+import TEMPLATE from './template';
+
+export default function PostCommentsEdit( {
+ attributes,
+ setAttributes,
+ context: { postType, postId },
+} ) {
+ const { tagName: TagName, textAlign } = attributes;
+
+ const [ commentStatus ] = useEntityProp(
+ 'postType',
+ postType,
+ 'comment_status',
+ postId
+ );
+
+ const { defaultCommentStatus } = useSelect(
+ ( select ) =>
+ select( blockEditorStore ).getSettings()
+ .__experimentalDiscussionSettings
+ );
+
+ const isSiteEditor = postType === undefined || postId === undefined;
+
+ const postTypeSupportsComments = useSelect( ( select ) =>
+ postType
+ ? !! select( coreStore ).getPostType( postType )?.supports.comments
+ : false
+ );
+
+ let warning = __(
+ 'Post Comments block: This is just a placeholder, not a real comment. The final styling may differ because it also depends on the current theme. For better compatibility with the Block Editor, please consider replacing this block with the "Comments Query Loop" block.'
+ );
+ let showPlacholder = true;
+
+ if ( ! isSiteEditor && 'open' !== commentStatus ) {
+ if ( 'closed' === commentStatus ) {
+ warning = sprintf(
+ /* translators: 1: Post type (i.e. "post", "page") */
+ __(
+ 'Post Comments block: Comments to this %s are not allowed.'
+ ),
+ postType
+ );
+ showPlacholder = false;
+ } else if ( ! postTypeSupportsComments ) {
+ warning = sprintf(
+ /* translators: 1: Post type (i.e. "post", "page") */
+ __(
+ 'Post Comments block: Comments for this post type (%s) are not enabled.'
+ ),
+ postType
+ );
+ showPlacholder = false;
+ } else if ( 'open' !== defaultCommentStatus ) {
+ warning = __( 'Post Comments block: Comments are not enabled.' );
+ showPlacholder = false;
+ }
+ }
+
+ const blockProps = useBlockProps( {
+ className: classnames(
+ // We add the previous block name for backward compatibility.
+ 'wp-block-comments-query-loop',
+ {
+ [ `has-text-align-${ textAlign }` ]: textAlign,
+ }
+ ),
+ } );
+ const innerBlocksProps = useInnerBlocksProps( blockProps, {
+ template: TEMPLATE,
+ } );
+
+ if ( ! attributes.legacy ) {
+ return (
+ <>
+
+
+ >
+ );
+ }
+
+ return (
+ <>
+
+ {
+ setAttributes( { textAlign: nextAlign } );
+ } }
+ />
+
+
+
+
{ warning }
+
+ { showPlacholder && (
+
+ ) }
+
+ >
+ );
+}
diff --git a/packages/block-library/src/comments/edit/placeholder.js b/packages/block-library/src/comments/edit/placeholder.js
new file mode 100644
index 0000000000000..07556f6d52396
--- /dev/null
+++ b/packages/block-library/src/comments/edit/placeholder.js
@@ -0,0 +1,121 @@
+/**
+ * WordPress dependencies
+ */
+import { store as blockEditorStore } from '@wordpress/block-editor';
+import { __ } from '@wordpress/i18n';
+import { useSelect } from '@wordpress/data';
+import { useEntityProp } from '@wordpress/core-data';
+import { useDisabled } from '@wordpress/compose';
+
+/**
+ * Internal dependencies
+ */
+import CommentsForm from '../../post-comments-form/form';
+
+export default function PostCommentsPlaceholder( { postType, postId } ) {
+ let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId );
+ postTitle = postTitle || __( 'Post Title' );
+
+ const { avatarURL } = useSelect(
+ ( select ) =>
+ select( blockEditorStore ).getSettings()
+ .__experimentalDiscussionSettings
+ );
+
+ const disabledRef = useDisabled();
+
+ return (
+
+
+ { __( 'One response to' ) } “{ postTitle }”
+
+
+
+
+
+
+
+
+
+
+
+ { __( 'Hi, this is a comment.' ) }
+
+ { __(
+ 'To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.'
+ ) }
+
+ { __( 'Commenter avatars come from' ) }{ ' ' }
+ Gravatar .
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+}
diff --git a/packages/block-library/src/comments/edit.js b/packages/block-library/src/comments/edit/template.js
similarity index 62%
rename from packages/block-library/src/comments/edit.js
rename to packages/block-library/src/comments/edit/template.js
index 2191c1a84fb99..18897325027c4 100644
--- a/packages/block-library/src/comments/edit.js
+++ b/packages/block-library/src/comments/edit/template.js
@@ -1,13 +1,3 @@
-/**
- * WordPress dependencies
- */
-import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
-
-/**
- * Internal dependencies
- */
-import CommentsInspectorControls from './edit/comments-inspector-controls';
-
const TEMPLATE = [
[ 'core/comments-title' ],
[
@@ -88,24 +78,4 @@ const TEMPLATE = [
[ 'core/post-comments-form' ],
];
-export default function CommentsEdit( { attributes, setAttributes } ) {
- const { tagName: TagName } = attributes;
-
- const blockProps = useBlockProps( {
- // We add the previous block name for backward compatibility.
- className: 'wp-block-comments-query-loop',
- } );
- const innerBlocksProps = useInnerBlocksProps( blockProps, {
- template: TEMPLATE,
- } );
-
- return (
- <>
-
-
- >
- );
-}
+export default TEMPLATE;
diff --git a/packages/block-library/src/comments/editor.scss b/packages/block-library/src/comments/editor.scss
index 6e21a9899421e..ad9a4c9af741e 100644
--- a/packages/block-library/src/comments/editor.scss
+++ b/packages/block-library/src/comments/editor.scss
@@ -1,3 +1,12 @@
+@import "./style.scss";
+
.block-library-comments-toolbar__popover .components-popover__content {
min-width: 230px;
}
+
+.wp-block-post-comments__placeholder {
+ @extend .wp-block-post-comments;
+ * {
+ pointer-events: none;
+ }
+}
diff --git a/packages/block-library/src/comments/index.php b/packages/block-library/src/comments/index.php
new file mode 100644
index 0000000000000..4774dbfc06042
--- /dev/null
+++ b/packages/block-library/src/comments/index.php
@@ -0,0 +1,213 @@
+name || isset( $attributes['legacy'] );
+ if ( ! $is_legacy ) {
+ $inner_blocks_html = '';
+ foreach ( $block->inner_blocks as $inner_block ) {
+ $inner_blocks_html .= $inner_block->render();
+ }
+ return $inner_blocks_html;
+ }
+
+ $post_id = $block->context['postId'];
+ if ( ! isset( $post_id ) ) {
+ return '';
+ }
+
+ $comment_args = array(
+ 'post_id' => $post_id,
+ 'count' => true,
+ );
+ // Return early if there are no comments and comments are closed.
+ if ( ! comments_open( $post_id ) && get_comments( $comment_args ) === 0 ) {
+ return '';
+ }
+
+ $post_before = $post;
+ $post = get_post( $post_id );
+ setup_postdata( $post );
+
+ ob_start();
+ // There's a deprecation warning generated by WP Core.
+ // Ideally this deprecation is removed from Core.
+ // In the meantime, this removes it from the output.
+ add_filter( 'deprecated_file_trigger_error', '__return_false' );
+ comments_template();
+ remove_filter( 'deprecated_file_trigger_error', '__return_false' );
+ $post = $post_before;
+
+ $classnames = array();
+ // Adds the old class name for styles' backwards compatibility.
+ if ( isset( $attributes['legacy'] ) ) {
+ $classnames[] = 'wp-block-post-comments';
+ }
+ if ( isset( $attributes['textAlign'] ) ) {
+ $classnames[] = 'has-text-align-' . $attributes['textAlign'];
+ }
+
+ $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode(' ', $classnames ) ) );
+ $output = ob_get_clean();
+
+ wp_enqueue_script( 'comment-reply' );
+ enqueue_legacy_post_comments_block_styles( $block->name );
+
+ return sprintf( '%2$s
', $wrapper_attributes, $output );
+}
+
+/**
+ * Registers the `core/comments-query-loop` block on the server.
+ */
+function register_block_core_comments_query_loop() {
+ register_block_type_from_metadata(
+ __DIR__ . '/comments',
+ array(
+ 'render_callback' => 'render_block_core_comments_query_loop',
+ 'skip_inner_blocks' => true,
+ )
+ );
+}
+add_action( 'init', 'register_block_core_comments_query_loop' );
+
+/**
+ * Use the button block classes for the form-submit button.
+ *
+ * @param array $fields The default comment form arguments.
+ *
+ * @return array Returns the modified fields.
+ */
+function comments_query_loop_block_form_defaults( $fields ) {
+ if ( wp_is_block_theme() ) {
+ $fields['submit_button'] = ' ';
+ $fields['submit_field'] = '%1$s %2$s
';
+ }
+
+ return $fields;
+}
+add_filter( 'comment_form_defaults', 'comments_query_loop_block_form_defaults' );
+
+/**
+ * Enqueues styles from the legacy `core/post-comments` block. These styles are
+ * required by the block's fallback.
+ *
+ * @param string $block_name Name of the new block type.
+ */
+function enqueue_legacy_post_comments_block_styles( $block_name ) {
+ static $are_styles_enqueued = false;
+
+ if ( ! $are_styles_enqueued ) {
+ $handles = array(
+ 'wp-block-post-comments',
+ 'wp-block-buttons',
+ 'wp-block-button',
+ );
+ foreach( $handles as $handle ) {
+ wp_enqueue_block_style( $block_name, array( 'handle' => $handle) );
+ }
+ $are_styles_enqueued = true;
+ }
+}
+
+/**
+ * Renders the legacy `core/post-comments` block on the server.
+ * It triggers a developer warning and then calls the renamed
+ * block's `render_callback` function output.
+ *
+ * This can be removed when WordPress X.X is released.
+ *
+ * @param array $attributes Block attributes.
+ * @param string $content Block default content.
+ * @param WP_Block $block Block instance.
+ *
+ * @return string Returns the output of the block.
+ */
+function render_legacy_post_comments_block( $attributes, $content, $block ) {
+ trigger_error(
+ /* translators: %1$s: Block type */
+ sprintf( __( 'Block %1$s has been renamed to Comments Query Loop. %1$s will be supported until WordPress version X.X.', 'gutenberg' ), $block->name ),
+ headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
+ );
+ return render_block_core_comments_query_loop( $attributes, $content, $block );
+}
+
+/**
+ * Ensures backwards compatibility for any users running the Gutenberg plugin
+ * who have used Post Comments before it was merged into Comments Query Loop.
+ *
+ * The same approach was followed when core/query-loop was renamed to
+ * core/post-template.
+ *
+ * This can be removed when WordPress X.X is released.
+ *
+ * @see https://github.com/WordPress/gutenberg/pull/41807
+ * @see https://github.com/WordPress/gutenberg/pull/32514
+ */
+function gutenberg_register_legacy_post_comments_block() {
+ $registry = WP_Block_Type_Registry::get_instance();
+ if ( $registry->is_registered( 'core/post-comments' ) ) {
+ unregister_block_type( 'core/post-comments' );
+ }
+ register_block_type(
+ 'core/post-comments',
+ array(
+ 'category' => 'theme',
+ 'attributes' => array(
+ 'textAlign' => array(
+ 'type' => 'string',
+ ),
+ ),
+ 'uses_context' => array(
+ 'postId',
+ 'postType',
+ ),
+ 'supports' => array(
+ 'html' => false,
+ 'align' => array( 'wide', 'full' ),
+ 'typography' => array(
+ 'fontSize' => true,
+ 'lineHeight' => true,
+ '__experimentalFontStyle' => true,
+ '__experimentalFontWeight' => true,
+ '__experimentalLetterSpacing' => true,
+ '__experimentalTextTransform' => true,
+ '__experimentalDefaultControls' => array(
+ 'fontSize' => true,
+ ),
+ ),
+ 'color' => array(
+ 'gradients' => true,
+ 'link' => true,
+ '__experimentalDefaultControls' => array(
+ 'background' => true,
+ 'text' => true
+ )
+ ),
+ 'inserter' => false
+ ),
+ 'style' => array(
+ 'wp-block-post-comments',
+ 'wp-block-buttons',
+ 'wp-block-button'
+ ),
+ 'editorStyle' => 'wp-block-post-comments-editor',
+ 'render_callback' => 'render_legacy_post_comments_block',
+ 'skip_inner_blocks' => true,
+ )
+ );
+}
+add_action( 'init', 'gutenberg_register_legacy_post_comments_block', 21);
diff --git a/packages/block-library/src/comments/save.js b/packages/block-library/src/comments/save.js
index 47c774fc4b9bb..14a8309eb92c4 100644
--- a/packages/block-library/src/comments/save.js
+++ b/packages/block-library/src/comments/save.js
@@ -1,12 +1,13 @@
/**
* WordPress dependencies
*/
-import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
+import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';
-export default function CommentsSave( { attributes: { tagName: Tag } } ) {
- return (
-
-
-
- );
+export default function save( { attributes: { tagName: Tag, legacy } } ) {
+ const blockProps = useBlockProps.save();
+ const innerBlocksProps = useInnerBlocksProps.save( blockProps );
+
+ // The legacy version is dynamic (i.e. PHP rendered) and doesn't allow inner
+ // blocks, so nothing is saved in that case.
+ return legacy ? null : ;
}
diff --git a/packages/block-library/src/post-comments/style.scss b/packages/block-library/src/comments/style.scss
similarity index 96%
rename from packages/block-library/src/post-comments/style.scss
rename to packages/block-library/src/comments/style.scss
index ebcf192d898b1..732e42d5bcaa4 100644
--- a/packages/block-library/src/post-comments/style.scss
+++ b/packages/block-library/src/comments/style.scss
@@ -1,4 +1,6 @@
+/* Styles for backwards compatibility with the legacy `post-comments` block */
.wp-block-post-comments {
+
/* utility classes */
.alignleft {
float: left;
@@ -7,6 +9,7 @@
.alignright {
float: right;
}
+
/* end utility classes */
.navigation {
@@ -62,9 +65,11 @@
.comment-meta {
font-size: 0.875em;
line-height: 1.5;
+
b {
font-weight: normal;
}
+
.comment-awaiting-moderation {
margin-top: 1em;
margin-bottom: 1em;
@@ -87,6 +92,7 @@
}
.comment-form {
+
textarea,
input:not([type="submit"]):not([type="checkbox"]) {
display: block;
@@ -106,6 +112,7 @@
.comment-reply-title {
margin-bottom: 0;
+
:where(small) {
font-size: var(--wp--preset--font-size--medium, smaller);
margin-left: 0.5em;
diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss
index ba031d6cbdeaa..138e480263021 100644
--- a/packages/block-library/src/editor.scss
+++ b/packages/block-library/src/editor.scss
@@ -49,7 +49,6 @@
@import "./query-pagination/editor.scss";
@import "./query-pagination-numbers/editor.scss";
@import "./post-featured-image/editor.scss";
-@import "./post-comments/editor.scss";
@import "./post-comments-form/editor.scss";
:root .editor-styles-wrapper {
diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js
index ff72f0b90d101..f0d5924d7248d 100644
--- a/packages/block-library/src/index.js
+++ b/packages/block-library/src/index.js
@@ -73,7 +73,6 @@ import * as postAuthor from './post-author';
import * as postAuthorName from './post-author-name';
import * as postAuthorBiography from './post-author-biography';
import * as postComment from './post-comment';
-import * as postComments from './post-comments';
import * as postCommentsCount from './post-comments-count';
import * as postCommentsForm from './post-comments-form';
import * as postCommentsLink from './post-comments-link';
@@ -228,7 +227,6 @@ const getAllBlocks = () => [
commentsPaginationNext,
commentsPaginationNumbers,
commentsPaginationPrevious,
- postComments,
postCommentsForm,
tableOfContents,
homeLink,
diff --git a/packages/block-library/src/post-comments/block.json b/packages/block-library/src/post-comments/block.json
deleted file mode 100644
index dc719fff5d708..0000000000000
--- a/packages/block-library/src/post-comments/block.json
+++ /dev/null
@@ -1,45 +0,0 @@
-{
- "$schema": "https://schemas.wp.org/trunk/block.json",
- "apiVersion": 2,
- "name": "core/post-comments",
- "title": "Post Comments (deprecated)",
- "category": "theme",
- "description": "This block is deprecated. Please use the Comments block instead.",
- "textdomain": "default",
- "attributes": {
- "textAlign": {
- "type": "string"
- }
- },
- "usesContext": [ "postId", "postType" ],
- "supports": {
- "html": false,
- "align": [ "wide", "full" ],
- "typography": {
- "fontSize": true,
- "lineHeight": true,
- "__experimentalFontStyle": true,
- "__experimentalFontWeight": true,
- "__experimentalLetterSpacing": true,
- "__experimentalTextTransform": true,
- "__experimentalDefaultControls": {
- "fontSize": true
- }
- },
- "color": {
- "gradients": true,
- "link": true,
- "__experimentalDefaultControls": {
- "background": true,
- "text": true
- }
- },
- "inserter": false
- },
- "style": [
- "wp-block-post-comments",
- "wp-block-buttons",
- "wp-block-button"
- ],
- "editorStyle": "wp-block-post-comments-editor"
-}
diff --git a/packages/block-library/src/post-comments/edit.js b/packages/block-library/src/post-comments/edit.js
deleted file mode 100644
index 251a290eb0a96..0000000000000
--- a/packages/block-library/src/post-comments/edit.js
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
- * External dependencies
- */
-import classnames from 'classnames';
-
-/**
- * WordPress dependencies
- */
-import {
- AlignmentControl,
- BlockControls,
- Warning,
- useBlockProps,
- store as blockEditorStore,
-} from '@wordpress/block-editor';
-import { __, sprintf } from '@wordpress/i18n';
-import { useSelect } from '@wordpress/data';
-import { useEntityProp, store as coreStore } from '@wordpress/core-data';
-import { useDisabled } from '@wordpress/compose';
-import { createInterpolateElement } from '@wordpress/element';
-
-/**
- * Internal dependencies
- */
-import CommentsForm from '../post-comments-form/form';
-
-export default function PostCommentsEdit( {
- attributes: { textAlign },
- setAttributes,
- context: { postType, postId },
-} ) {
- let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId );
- postTitle = postTitle || __( 'Post Title' );
-
- const [ commentStatus ] = useEntityProp(
- 'postType',
- postType,
- 'comment_status',
- postId
- );
-
- const { avatarURL, defaultCommentStatus } = useSelect(
- ( select ) =>
- select( blockEditorStore ).getSettings()
- .__experimentalDiscussionSettings
- );
-
- const isSiteEditor = postType === undefined || postId === undefined;
-
- const postTypeSupportsComments = useSelect( ( select ) =>
- postType
- ? !! select( coreStore ).getPostType( postType )?.supports.comments
- : false
- );
-
- let warning = __(
- 'Post Comments block: This is just a placeholder, not a real comment. The final styling may differ because it also depends on the current theme. For better compatibility with the Block Editor, please consider replacing this block with the "Comments" block.'
- );
- let showPlaceholder = true;
-
- if ( ! isSiteEditor && 'open' !== commentStatus ) {
- if ( 'closed' === commentStatus ) {
- warning = sprintf(
- /* translators: 1: Post type (i.e. "post", "page") */
- __(
- 'Post Comments block: Comments to this %s are not allowed.'
- ),
- postType
- );
- showPlaceholder = false;
- } else if ( ! postTypeSupportsComments ) {
- warning = sprintf(
- /* translators: 1: Post type (i.e. "post", "page") */
- __(
- 'Post Comments block: Comments for this post type (%s) are not enabled.'
- ),
- postType
- );
- showPlaceholder = false;
- } else if ( 'open' !== defaultCommentStatus ) {
- warning = __( 'Post Comments block: Comments are not enabled.' );
- showPlaceholder = false;
- }
- }
-
- const blockProps = useBlockProps( {
- className: classnames( {
- [ `has-text-align-${ textAlign }` ]: textAlign,
- } ),
- } );
-
- const disabledRef = useDisabled();
-
- return (
- <>
-
- {
- setAttributes( { textAlign: nextAlign } );
- } }
- />
-
-
-
-
{ warning }
-
- { showPlaceholder && (
-
-
- {
- /* translators: %s: Post title. */
- sprintf( __( 'One response to %s' ), postTitle )
- }
-
-
-
-
-
-
-
-
-
-
- { createInterpolateElement(
- sprintf(
- /* translators: %s: Comment author link. */
- __(
- '%s
says: '
- ),
- sprintf(
- '
%s ',
- __(
- 'A WordPress Commenter'
- )
- )
- ),
- {
- span: (
-
- ),
- a: (
- /* eslint-disable jsx-a11y/anchor-has-content */
-
- /* eslint-enable jsx-a11y/anchor-has-content */
- ),
- cite: (
-
- ),
- }
- ) }
-
-
-
-
-
-
-
- { __( 'Hi, this is a comment.' ) }
-
- { __(
- 'To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.'
- ) }
-
- { createInterpolateElement(
- __(
- 'Commenter avatars come from Gravatar '
- ),
- {
- a: (
- /* eslint-disable-next-line jsx-a11y/anchor-has-content */
-
- ),
- }
- ) }
-
-
-
-
-
-
-
-
-
-
-
-
- ) }
-
- >
- );
-}
diff --git a/packages/block-library/src/post-comments/editor.scss b/packages/block-library/src/post-comments/editor.scss
deleted file mode 100644
index 9d7c54f020fe3..0000000000000
--- a/packages/block-library/src/post-comments/editor.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-.wp-block-post-comments__placeholder * {
- pointer-events: none;
-}
diff --git a/packages/block-library/src/post-comments/index.js b/packages/block-library/src/post-comments/index.js
deleted file mode 100644
index db109a576b7f9..0000000000000
--- a/packages/block-library/src/post-comments/index.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * WordPress dependencies
- */
-import { postComments as icon } from '@wordpress/icons';
-
-/**
- * Internal dependencies
- */
-import metadata from './block.json';
-import edit from './edit';
-
-const { name } = metadata;
-export { metadata, name };
-
-export const settings = {
- icon,
- edit,
-};
diff --git a/packages/block-library/src/post-comments/index.php b/packages/block-library/src/post-comments/index.php
deleted file mode 100644
index 494bcb86746fa..0000000000000
--- a/packages/block-library/src/post-comments/index.php
+++ /dev/null
@@ -1,87 +0,0 @@
-context['postId'];
- if ( ! isset( $post_id ) ) {
- return '';
- }
-
- $comment_args = array(
- 'post_id' => $post_id,
- 'count' => true,
- );
- // Return early if there are no comments and comments are closed.
- if ( ! comments_open( $post_id ) && get_comments( $comment_args ) === 0 ) {
- return '';
- }
-
- $post_before = $post;
- $post = get_post( $post_id );
- setup_postdata( $post );
-
- ob_start();
- // There's a deprecation warning generated by WP Core.
- // Ideally this deprecation is removed from Core.
- // In the meantime, this removes it from the output.
- add_filter( 'deprecated_file_trigger_error', '__return_false' );
- comments_template();
- remove_filter( 'deprecated_file_trigger_error', '__return_false' );
- $post = $post_before;
-
- $classes = '';
- if ( isset( $attributes['textAlign'] ) ) {
- $classes .= 'has-text-align-' . $attributes['textAlign'];
- }
-
- $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
- $output = ob_get_clean();
-
- wp_enqueue_script( 'comment-reply' );
-
- return sprintf( '%2$s
', $wrapper_attributes, $output );
-}
-
-/**
- * Registers the `core/post-comments` block on the server.
- */
-function register_block_core_post_comments() {
- register_block_type_from_metadata(
- __DIR__ . '/post-comments',
- array(
- 'render_callback' => 'render_block_core_post_comments',
- )
- );
-}
-add_action( 'init', 'register_block_core_post_comments' );
-
-/**
- * Use the button block classes for the form-submit button.
- *
- * @param array $fields The default comment form arguments.
- *
- * @return array Returns the modified fields.
- */
-function post_comments_block_form_defaults( $fields ) {
- if ( wp_is_block_theme() ) {
- $fields['submit_button'] = ' ';
- $fields['submit_field'] = '%1$s %2$s
';
- }
-
- return $fields;
-}
-add_filter( 'comment_form_defaults', 'post_comments_block_form_defaults' );
diff --git a/packages/block-library/src/style.scss b/packages/block-library/src/style.scss
index c7013a739933a..2c0817f698fa6 100644
--- a/packages/block-library/src/style.scss
+++ b/packages/block-library/src/style.scss
@@ -7,6 +7,7 @@
@import "./categories/style.scss";
@import "./code/style.scss";
@import "./columns/style.scss";
+@import "./comments/style.scss";
@import "./comments-pagination/style.scss";
@import "./comment-template/style.scss";
@import "./cover/style.scss";
@@ -25,7 +26,6 @@
@import "./page-list/style.scss";
@import "./paragraph/style.scss";
@import "./post-author/style.scss";
-@import "./post-comments/style.scss";
@import "./post-comments-form/style.scss";
@import "./post-excerpt/style.scss";
@import "./post-featured-image/style.scss";
diff --git a/packages/blocks/src/api/parser/convert-legacy-block.js b/packages/blocks/src/api/parser/convert-legacy-block.js
index fd40b55e136ba..03156e47664f6 100644
--- a/packages/blocks/src/api/parser/convert-legacy-block.js
+++ b/packages/blocks/src/api/parser/convert-legacy-block.js
@@ -73,5 +73,12 @@ export function convertLegacyBlockNameAndAttributes( name, attributes ) {
// for the ID change to work.
}
+ // Checks needed after merging core/comments-query-loop and core/post-comments.
+
+ if ( name === 'core/post-comments' ) {
+ name = 'core/comments-query-loop';
+ newAttributes.legacy = true;
+ }
+
return [ name, newAttributes ];
}