diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 01c7aaade1a85..ddc177454d2db 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -213,7 +213,7 @@ An advanced block that allows displaying post comments based on different query - **Name:** core/comments-query-loop - **Category:** theme - **Supports:** align (full, wide), color (background, gradients, link, text), ~~html~~ -- **Attributes:** defaultPage, inherit, order, perPage, tagName +- **Attributes:** tagName ## Cover diff --git a/lib/compat/experimental/blocks.php b/lib/compat/experimental/blocks.php index fbd109ec18103..a90d5a949deb7 100644 --- a/lib/compat/experimental/blocks.php +++ b/lib/compat/experimental/blocks.php @@ -35,21 +35,8 @@ function build_comment_query_vars_from_block( $block ) { $comment_args['hierarchical'] = false; } - $inherit = ! empty( $block->context['comments/inherit'] ); - - $per_page = 0; - if ( $inherit && get_option( 'page_comments' ) ) { - $per_page = get_option( 'comments_per_page' ); - } - - if ( ! $inherit && ! empty( $block->context['comments/perPage'] ) ) { - $per_page = (int) $block->context['comments/perPage']; - } - + $per_page = get_option( 'comments_per_page' ); $default_page = get_option( 'default_comments_page' ); - if ( ! $inherit && ! empty( $block->context['comments/defaultPage'] ) ) { - $default_page = $block->context['comments/defaultPage']; - } if ( $per_page > 0 ) { $comment_args['number'] = $per_page; diff --git a/packages/block-library/src/comment-template/block.json b/packages/block-library/src/comment-template/block.json index 6a5b0f39a373a..7c31aac905cca 100644 --- a/packages/block-library/src/comment-template/block.json +++ b/packages/block-library/src/comment-template/block.json @@ -7,13 +7,7 @@ "parent": [ "core/comments-query-loop" ], "description": "Contains the block elements used to render a comment, like the title, date, author, avatar and more.", "textdomain": "default", - "usesContext": [ - "comments/defaultPage", - "comments/inherit", - "comments/order", - "comments/perPage", - "postId" - ], + "usesContext": [ "postId" ], "supports": { "reusable": false, "html": false, diff --git a/packages/block-library/src/comment-template/edit.js b/packages/block-library/src/comment-template/edit.js index ec26d965354fe..f41f0a98e5d67 100644 --- a/packages/block-library/src/comment-template/edit.js +++ b/packages/block-library/src/comment-template/edit.js @@ -229,29 +229,23 @@ const CommentsList = ( { export default function CommentTemplateEdit( { clientId, - context: { - postId, - 'comments/perPage': perPage, - 'comments/order': order, - 'comments/defaultPage': defaultPage, - 'comments/inherit': inherit, - }, + context: { postId }, } ) { const blockProps = useBlockProps(); const [ activeCommentId, setActiveCommentId ] = useState(); - const { commentOrder, threadCommentsDepth, threadComments } = useSelect( - ( select ) => { - const { getSettings } = select( blockEditorStore ); - return getSettings().__experimentalDiscussionSettings; - } - ); + const { + commentOrder, + threadCommentsDepth, + threadComments, + commentsPerPage, + } = useSelect( ( select ) => { + const { getSettings } = select( blockEditorStore ); + return getSettings().__experimentalDiscussionSettings; + } ); const commentQuery = useCommentQueryArgs( { postId, - perPage, - defaultPage, - inherit, } ); const { topLevelComments, blocks } = useSelect( @@ -270,12 +264,10 @@ export default function CommentTemplateEdit( { [ clientId, commentQuery ] ); - order = inherit || ! order ? commentOrder : order; - // Generate a tree structure of comment IDs. let commentTree = useCommentTree( // Reverse the order of top comments if needed. - order === 'desc' && topLevelComments + commentOrder === 'desc' && topLevelComments ? [ ...topLevelComments ].reverse() : topLevelComments ); @@ -290,7 +282,7 @@ export default function CommentTemplateEdit( { if ( ! postId ) { commentTree = getCommentsPlaceholder( { - perPage, + perPage: commentsPerPage, threadComments, threadCommentsDepth, } ); diff --git a/packages/block-library/src/comment-template/hooks.js b/packages/block-library/src/comment-template/hooks.js index d792887c72e88..ea2ead61331eb 100644 --- a/packages/block-library/src/comment-template/hooks.js +++ b/packages/block-library/src/comment-template/hooks.js @@ -11,21 +11,13 @@ import apiFetch from '@wordpress/api-fetch'; * Return an object with the query args needed to fetch the default page of * comments. * - * @param {Object} props Hook props. - * @param {number} props.postId ID of the post that contains the comments. - * @param {number} props.perPage The number of comments included per page. - * @param {string} props.defaultPage Page shown by default (newest/oldest). - * @param {boolean} props.inherit Overwrite props with values from WP - * discussion settings. + * @param {Object} props Hook props. + * @param {number} props.postId ID of the post that contains the comments. + * discussion settings. * * @return {Object} Query args to retrieve the comments. */ -export const useCommentQueryArgs = ( { - postId, - perPage, - defaultPage, - inherit, -} ) => { +export const useCommentQueryArgs = ( { postId } ) => { // Initialize the query args that are not going to change. const queryArgs = { status: 'approve', @@ -36,23 +28,15 @@ export const useCommentQueryArgs = ( { }; // Get the Discussion settings that may be needed to query the comments. - const { commentsPerPage, defaultCommentsPage } = useSelect( ( select ) => { + const { + commentsPerPage: perPage, + defaultCommentsPage: defaultPage, + } = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); const { __experimentalDiscussionSettings } = getSettings(); return __experimentalDiscussionSettings; } ); - // Overwrite the received attributes if `inherit` is true. - if ( inherit ) { - perPage = commentsPerPage; - defaultPage = defaultCommentsPage; - } - - // If a block props is not set, use the settings value to generate the - // appropriate query arg. - perPage = perPage || commentsPerPage; - defaultPage = defaultPage || defaultCommentsPage; - // Get the number of the default page. const page = useDefaultPageIndex( { defaultPage, diff --git a/packages/block-library/src/comment-template/index.php b/packages/block-library/src/comment-template/index.php index 68daa5dd36b7f..250eee6c43b49 100644 --- a/packages/block-library/src/comment-template/index.php +++ b/packages/block-library/src/comment-template/index.php @@ -68,9 +68,7 @@ function render_block_core_comment_template( $attributes, $content, $block ) { return ''; } - $comment_order = empty( $block->context['comments/inherit'] ) && ! empty( $block->context['comments/order'] ) - ? $block->context['comments/order'] - : get_option( 'comment_order' ); + $comment_order = get_option( 'comment_order' ); if ( 'desc' === $comment_order ) { $comments = array_reverse( $comments ); diff --git a/packages/block-library/src/comments-pagination-next/block.json b/packages/block-library/src/comments-pagination-next/block.json index 7310c119f3666..281f424671af7 100644 --- a/packages/block-library/src/comments-pagination-next/block.json +++ b/packages/block-library/src/comments-pagination-next/block.json @@ -12,14 +12,7 @@ "type": "string" } }, - "usesContext": [ - "postId", - "comments/perPage", - "comments/order", - "comments/inherit", - "comments/defaultPage", - "comments/paginationArrow" - ], + "usesContext": [ "postId", "comments/paginationArrow" ], "supports": { "reusable": false, "html": false, diff --git a/packages/block-library/src/comments-pagination-numbers/block.json b/packages/block-library/src/comments-pagination-numbers/block.json index df9abea4ed0b0..020d838dd7057 100644 --- a/packages/block-library/src/comments-pagination-numbers/block.json +++ b/packages/block-library/src/comments-pagination-numbers/block.json @@ -3,17 +3,11 @@ "apiVersion": 2, "name": "core/comments-pagination-numbers", "title": "Page Numbers", - "category": "theme", + "category": "theme", "parent": [ "core/comments-pagination" ], "description": "Displays a list of page numbers for comments pagination.", "textdomain": "default", - "usesContext": [ - "postId", - "comments/perPage", - "comments/order", - "comments/inherit", - "comments/defaultPage" - ], + "usesContext": [ "postId" ], "supports": { "reusable": false, "html": false diff --git a/packages/block-library/src/comments-query-loop/block.json b/packages/block-library/src/comments-query-loop/block.json index ded2ad1667f7d..6f821670ad64d 100644 --- a/packages/block-library/src/comments-query-loop/block.json +++ b/packages/block-library/src/comments-query-loop/block.json @@ -7,33 +7,11 @@ "description": "An advanced block that allows displaying post comments based on different query parameters and visual configurations.", "textdomain": "default", "attributes": { - "inherit": { - "type": "boolean", - "default": true - }, - "order": { - "type": "string", - "default": null - }, - "perPage": { - "type": "number", - "default": null - }, "tagName": { "type": "string", "default": "div" - }, - "defaultPage": { - "type": "string", - "default": "oldest" } }, - "providesContext": { - "comments/perPage": "perPage", - "comments/order": "order", - "comments/defaultPage": "defaultPage", - "comments/inherit": "inherit" - }, "supports": { "align": [ "wide", "full" ], "html": false, diff --git a/packages/block-library/src/comments-query-loop/edit/comments-inspector-controls.js b/packages/block-library/src/comments-query-loop/edit/comments-inspector-controls.js index 75f693e2edc7f..acc2bbce4e7c4 100644 --- a/packages/block-library/src/comments-query-loop/edit/comments-inspector-controls.js +++ b/packages/block-library/src/comments-query-loop/edit/comments-inspector-controls.js @@ -1,97 +1,16 @@ /** * WordPress dependencies */ -import { - PanelBody, - SelectControl, - ToggleControl, - __experimentalNumberControl as NumberControl, -} from '@wordpress/components'; +import { SelectControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { InspectorControls } from '@wordpress/block-editor'; -const orderOptions = [ - { - label: __( 'Newest to oldest' ), - value: 'desc', - }, - { - label: __( 'Oldest to newest' ), - value: 'asc', - }, -]; - -const defaultPageOptions = [ - { - label: __( 'Newest' ), - value: 'newest', - }, - { - label: __( 'Oldest' ), - value: 'oldest', - }, -]; - export default function CommentsInspectorControls( { - attributes: { TagName, perPage, order, inherit, defaultPage }, + attributes: { TagName }, setAttributes, } ) { return ( - - { - setAttributes( { - inherit: ! inherit, - } ); - } } - /> - { ! inherit && ( - <> - { - setAttributes( { - order: value, - } ); - } } - /> - { - setAttributes( { - defaultPage: value, - } ); - } } - /> - { - const num = parseInt( value, 10 ); - if ( isNaN( num ) || num < 1 || num > 100 ) { - return; - } - setAttributes( { - perPage: num, - } ); - } } - step="1" - value={ perPage } - isDragEnabled={ false } - /> - - ) } - self::$custom_post->ID, - 'comments/perPage' => 77, + 'postId' => self::$custom_post->ID, ) ); @@ -67,38 +66,7 @@ function test_build_comment_query_vars_from_block_with_context() { 'update_comment_meta_cache' => false, 'post_id' => self::$custom_post->ID, 'hierarchical' => 'threaded', - 'number' => 77, - 'paged' => 1, - ) - ); - } - - function test_build_comment_query_vars_from_block_with_context_and_inherit() { - $parsed_blocks = parse_blocks( - '' - ); - - $block = new WP_Block( - $parsed_blocks[0], - array( - 'postId' => self::$custom_post->ID, - 'comments/perPage' => 77, - 'comments/order' => 'desc', - 'comments/inherit' => true, - ) - ); - - $this->assertEquals( - build_comment_query_vars_from_block( $block ), - array( - 'orderby' => 'comment_date_gmt', - 'order' => 'ASC', - 'status' => 'approve', - 'no_found_rows' => false, - 'update_comment_meta_cache' => false, - 'post_id' => self::$custom_post->ID, - 'hierarchical' => 'threaded', - 'number' => self::$per_page, + 'number' => 5, 'paged' => 1, ) ); @@ -120,32 +88,7 @@ function test_build_comment_query_vars_from_block_no_context() { 'no_found_rows' => false, 'update_comment_meta_cache' => false, 'hierarchical' => 'threaded', - ) - ); - } - - function test_build_comment_query_vars_from_block_with_context_and_pagination() { - $parsed_blocks = parse_blocks( - '' - ); - - $block = new WP_Block( - $parsed_blocks[0], - array( - 'comments/perPage' => 77, - ) - ); - - $this->assertEquals( - build_comment_query_vars_from_block( $block ), - array( - 'orderby' => 'comment_date_gmt', - 'order' => 'ASC', - 'status' => 'approve', - 'no_found_rows' => false, - 'update_comment_meta_cache' => false, - 'hierarchical' => 'threaded', - 'number' => 77, + 'number' => 5, 'paged' => 1, ) ); @@ -162,8 +105,7 @@ function test_rendering_comment_template() { $block = new WP_Block( $parsed_blocks[0], array( - 'postId' => self::$custom_post->ID, - 'comments/perPage' => 10, + 'postId' => self::$custom_post->ID, ) ); @@ -212,8 +154,7 @@ function test_rendering_comment_template_nested() { $block = new WP_Block( $parsed_blocks[0], array( - 'postId' => self::$custom_post->ID, - 'comments/perPage' => 10, + 'postId' => self::$custom_post->ID, ) ); diff --git a/test/integration/fixtures/blocks/core__comments-query-loop.html b/test/integration/fixtures/blocks/core__comments-query-loop.html index a2feedf0a708e..feed071fb840f 100644 --- a/test/integration/fixtures/blocks/core__comments-query-loop.html +++ b/test/integration/fixtures/blocks/core__comments-query-loop.html @@ -1,15 +1,17 @@ - -
- - - - - - - - - - - -
- \ No newline at end of file + +
+ + + + + + + + + + + + + +
+ diff --git a/test/integration/fixtures/blocks/core__comments-query-loop.json b/test/integration/fixtures/blocks/core__comments-query-loop.json index 8e77727b45118..643bec7fe6671 100644 --- a/test/integration/fixtures/blocks/core__comments-query-loop.json +++ b/test/integration/fixtures/blocks/core__comments-query-loop.json @@ -3,11 +3,7 @@ "name": "core/comments-query-loop", "isValid": true, "attributes": { - "inherit": false, - "order": "desc", - "perPage": 2, - "tagName": "div", - "defaultPage": "oldest" + "tagName": "div" }, "innerBlocks": [ { diff --git a/test/integration/fixtures/blocks/core__comments-query-loop.parsed.json b/test/integration/fixtures/blocks/core__comments-query-loop.parsed.json index 1f1522100f516..e674c73c1f6f5 100644 --- a/test/integration/fixtures/blocks/core__comments-query-loop.parsed.json +++ b/test/integration/fixtures/blocks/core__comments-query-loop.parsed.json @@ -1,12 +1,7 @@ [ { "blockName": "core/comments-query-loop", - "attrs": { - "inherit": false, - "perPage": 2, - "order": "desc", - "defaultPage": "oldest" - }, + "attrs": {}, "innerBlocks": [ { "blockName": "core/comment-template", @@ -55,29 +50,29 @@ "innerContent": [] } ], - "innerHTML": "\n \n \n \n \n \n \n \n \n \n \n \n ", + "innerHTML": "\n\t\n\n\t\n\n\t\n\n\t\n\n\t\n\n\t\n\t", "innerContent": [ - "\n ", + "\n\t", null, - "\n \n ", + "\n\n\t", null, - "\n \n ", + "\n\n\t", null, - "\n \n ", + "\n\n\t", null, - "\n \n ", + "\n\n\t", null, - "\n \n ", + "\n\n\t", null, - "\n " + "\n\t" ] } ], - "innerHTML": "\n
\n ", + "innerHTML": "\n
\n\t\n
\n", "innerContent": [ - "\n
", + "\n
\n\t", null, - "
\n " + "\n
\n" ] } ] diff --git a/test/integration/fixtures/blocks/core__comments-query-loop.serialized.html b/test/integration/fixtures/blocks/core__comments-query-loop.serialized.html index 9c27b84474cb6..6496d12b1c37b 100644 --- a/test/integration/fixtures/blocks/core__comments-query-loop.serialized.html +++ b/test/integration/fixtures/blocks/core__comments-query-loop.serialized.html @@ -1,4 +1,4 @@ - +