2022-04-12 17:12:47 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Server-side rendering of the `core/comment-template` block.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that recursively renders a list of nested comments.
|
|
|
|
*
|
2022-04-26 15:42:07 +02:00
|
|
|
* @global int $comment_depth
|
|
|
|
*
|
2022-04-19 17:11:17 +02:00
|
|
|
* @param WP_Comment[] $comments The array of comments.
|
2022-04-12 17:12:47 +02:00
|
|
|
* @param WP_Block $block Block instance.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function block_core_comment_template_render_comments( $comments, $block ) {
|
2022-04-19 17:11:17 +02:00
|
|
|
global $comment_depth;
|
2022-09-27 19:32:52 +02:00
|
|
|
$thread_comments = get_option( 'thread_comments' );
|
|
|
|
$thread_comments_depth = get_option( 'thread_comments_depth' );
|
2022-04-19 17:11:17 +02:00
|
|
|
|
|
|
|
if ( empty( $comment_depth ) ) {
|
|
|
|
$comment_depth = 1;
|
|
|
|
}
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
$content = '';
|
|
|
|
foreach ( $comments as $comment ) {
|
|
|
|
|
|
|
|
$block_content = ( new WP_Block(
|
|
|
|
$block->parsed_block,
|
|
|
|
array(
|
|
|
|
'commentId' => $comment->comment_ID,
|
|
|
|
)
|
|
|
|
) )->render( array( 'dynamic' => false ) );
|
|
|
|
|
|
|
|
$children = $comment->get_children();
|
|
|
|
|
2022-04-26 15:42:07 +02:00
|
|
|
/*
|
|
|
|
* We need to create the CSS classes BEFORE recursing into the children.
|
|
|
|
* This is because comment_class() uses globals like `$comment_alt`
|
|
|
|
* and `$comment_thread_alt` which are order-sensitive.
|
|
|
|
*
|
|
|
|
* The `false` parameter at the end means that we do NOT want the function
|
|
|
|
* to `echo` the output but to return a string.
|
|
|
|
* See https://developer.wordpress.org/reference/functions/comment_class/#parameters.
|
|
|
|
*/
|
|
|
|
$comment_classes = comment_class( '', $comment->comment_ID, $comment->comment_post_ID, false );
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
// If the comment has children, recurse to create the HTML for the nested
|
|
|
|
// comments.
|
2022-09-27 19:32:52 +02:00
|
|
|
if ( ! empty( $children ) && ! empty( $thread_comments ) ) {
|
|
|
|
if ( $comment_depth < $thread_comments_depth ) {
|
2023-02-07 08:04:52 +01:00
|
|
|
++$comment_depth;
|
2022-09-27 19:32:52 +02:00
|
|
|
$inner_content = block_core_comment_template_render_comments(
|
|
|
|
$children,
|
|
|
|
$block
|
|
|
|
);
|
|
|
|
$block_content .= sprintf( '<ol>%1$s</ol>', $inner_content );
|
2023-02-07 08:04:52 +01:00
|
|
|
--$comment_depth;
|
2022-09-27 19:32:52 +02:00
|
|
|
} else {
|
Editor: Update block editor packages to the latest patch releases.
This updates the block editor related npm dependencies to their latest patch versions ahead of WordPress 6.2.1 RC1.
Updated packages:
- @wordpress/annotations@2.26.4
- @wordpress/block-directory@4.3.12
- @wordpress/block-editor@11.3.10
- @wordpress/block-library@8.3.12
- @wordpress/components@23.3.7
- @wordpress/customize-widgets@4.3.12
- @wordpress/edit-post@7.3.12
- @wordpress/edit-site@5.3.12
- @wordpress/edit-widgets@5.3.12
- @wordpress/editor@13.3.10
- @wordpress/format-library@4.3.10
- @wordpress/interface@5.3.8
- @wordpress/list-reusable-blocks@4.3.7
- @wordpress/preferences@3.3.7
- @wordpress/reusable-blocks@4.3.10
- @wordpress/rich-text@6.3.4
- @wordpress/server-side-render@4.3.7
- @wordpress/widgets@3.3.10
This changeset includes the following fixes:
- i18n: Add context to labels related to CSS position properties gutenberg#49135
- Comments: Fix 'sprintf requires more than 1 params' error gutenberg#49054
- Fix the site editor loading in multi-site installs gutenberg#49861
- Fix quick inserter going off-screen in some situations gutenberg#49881
- Site Editor: Decode the site title properly gutenberg#49685
- Firefox: fix input rules (React async state issue) gutenberg#48210
- Only show alignment info when parent layout is constrained. gutenberg#49703
- [Inserter]: Fix onHover error on patterns tab in mobile gutenberg#49450
- Fix site editor redirection after creating new template or template part gutenberg#49364
Props mamaduka, audrasjb, wildworks, ocean90, aristath, costdev, hellofromtonya, youknowriad, mdxfr, oandregal, mattwiebe, bph, ndiego, talldanwp, joen, ellatrix, kevin940726, isabel_brison, andrewserong, ntsekouras, welcher.
Fixes #58274.
Built from https://develop.svn.wordpress.org/trunk@55737
git-svn-id: http://core.svn.wordpress.org/trunk@55249 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-09 16:13:25 +02:00
|
|
|
$block_content .= block_core_comment_template_render_comments(
|
2022-09-27 19:32:52 +02:00
|
|
|
$children,
|
|
|
|
$block
|
|
|
|
);
|
|
|
|
}
|
2022-04-12 17:12:47 +02:00
|
|
|
}
|
|
|
|
|
2022-04-19 17:11:17 +02:00
|
|
|
$content .= sprintf( '<li id="comment-%1$s" %2$s>%3$s</li>', $comment->comment_ID, $comment_classes, $block_content );
|
2022-04-12 17:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the `core/comment-template` block on the server.
|
|
|
|
*
|
|
|
|
* @param array $attributes Block attributes.
|
|
|
|
* @param string $content Block default content.
|
|
|
|
* @param WP_Block $block Block instance.
|
|
|
|
*
|
|
|
|
* @return string Returns the HTML representing the comments using the layout
|
|
|
|
* defined by the block's inner blocks.
|
|
|
|
*/
|
|
|
|
function render_block_core_comment_template( $attributes, $content, $block ) {
|
|
|
|
// Bail out early if the post ID is not set for some reason.
|
|
|
|
if ( empty( $block->context['postId'] ) ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2022-05-03 17:00:36 +02:00
|
|
|
if ( post_password_required( $block->context['postId'] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
$comment_query = new WP_Comment_Query(
|
|
|
|
build_comment_query_vars_from_block( $block )
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get an array of comments for the current post.
|
|
|
|
$comments = $comment_query->get_comments();
|
|
|
|
if ( count( $comments ) === 0 ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$comment_order = get_option( 'comment_order' );
|
|
|
|
|
|
|
|
if ( 'desc' === $comment_order ) {
|
|
|
|
$comments = array_reverse( $comments );
|
|
|
|
}
|
|
|
|
|
|
|
|
$wrapper_attributes = get_block_wrapper_attributes();
|
|
|
|
|
|
|
|
return sprintf(
|
|
|
|
'<ol %1$s>%2$s</ol>',
|
|
|
|
$wrapper_attributes,
|
|
|
|
block_core_comment_template_render_comments( $comments, $block )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the `core/comment-template` block on the server.
|
|
|
|
*/
|
|
|
|
function register_block_core_comment_template() {
|
|
|
|
register_block_type_from_metadata(
|
|
|
|
__DIR__ . '/comment-template',
|
|
|
|
array(
|
|
|
|
'render_callback' => 'render_block_core_comment_template',
|
|
|
|
'skip_inner_blocks' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
add_action( 'init', 'register_block_core_comment_template' );
|