Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: comment-template.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/comment-template` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Function that recursively renders a list of nested comments.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.3.0 Changed render_block_context priority to `1`.
[10] Fix | Delete
*
[11] Fix | Delete
* @global int $comment_depth
[12] Fix | Delete
*
[13] Fix | Delete
* @param WP_Comment[] $comments The array of comments.
[14] Fix | Delete
* @param WP_Block $block Block instance.
[15] Fix | Delete
* @return string
[16] Fix | Delete
*/
[17] Fix | Delete
function block_core_comment_template_render_comments( $comments, $block ) {
[18] Fix | Delete
global $comment_depth;
[19] Fix | Delete
$thread_comments = get_option( 'thread_comments' );
[20] Fix | Delete
$thread_comments_depth = get_option( 'thread_comments_depth' );
[21] Fix | Delete
[22] Fix | Delete
if ( empty( $comment_depth ) ) {
[23] Fix | Delete
$comment_depth = 1;
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
$content = '';
[27] Fix | Delete
foreach ( $comments as $comment ) {
[28] Fix | Delete
$comment_id = $comment->comment_ID;
[29] Fix | Delete
$filter_block_context = static function ( $context ) use ( $comment_id ) {
[30] Fix | Delete
$context['commentId'] = $comment_id;
[31] Fix | Delete
return $context;
[32] Fix | Delete
};
[33] Fix | Delete
[34] Fix | Delete
/*
[35] Fix | Delete
* We set commentId context through the `render_block_context` filter so
[36] Fix | Delete
* that dynamically inserted blocks (at `render_block` filter stage)
[37] Fix | Delete
* will also receive that context.
[38] Fix | Delete
*
[39] Fix | Delete
* Use an early priority to so that other 'render_block_context' filters
[40] Fix | Delete
* have access to the values.
[41] Fix | Delete
*/
[42] Fix | Delete
add_filter( 'render_block_context', $filter_block_context, 1 );
[43] Fix | Delete
[44] Fix | Delete
/*
[45] Fix | Delete
* We construct a new WP_Block instance from the parsed block so that
[46] Fix | Delete
* it'll receive any changes made by the `render_block_data` filter.
[47] Fix | Delete
*/
[48] Fix | Delete
$block_content = ( new WP_Block( $block->parsed_block ) )->render( array( 'dynamic' => false ) );
[49] Fix | Delete
[50] Fix | Delete
remove_filter( 'render_block_context', $filter_block_context, 1 );
[51] Fix | Delete
[52] Fix | Delete
$children = $comment->get_children();
[53] Fix | Delete
[54] Fix | Delete
/*
[55] Fix | Delete
* We need to create the CSS classes BEFORE recursing into the children.
[56] Fix | Delete
* This is because comment_class() uses globals like `$comment_alt`
[57] Fix | Delete
* and `$comment_thread_alt` which are order-sensitive.
[58] Fix | Delete
*
[59] Fix | Delete
* The `false` parameter at the end means that we do NOT want the function
[60] Fix | Delete
* to `echo` the output but to return a string.
[61] Fix | Delete
* See https://developer.wordpress.org/reference/functions/comment_class/#parameters.
[62] Fix | Delete
*/
[63] Fix | Delete
$comment_classes = comment_class( '', $comment->comment_ID, $comment->comment_post_ID, false );
[64] Fix | Delete
[65] Fix | Delete
// If the comment has children, recurse to create the HTML for the nested
[66] Fix | Delete
// comments.
[67] Fix | Delete
if ( ! empty( $children ) && ! empty( $thread_comments ) ) {
[68] Fix | Delete
if ( $comment_depth < $thread_comments_depth ) {
[69] Fix | Delete
++$comment_depth;
[70] Fix | Delete
$inner_content = block_core_comment_template_render_comments(
[71] Fix | Delete
$children,
[72] Fix | Delete
$block
[73] Fix | Delete
);
[74] Fix | Delete
$block_content .= sprintf( '<ol>%1$s</ol>', $inner_content );
[75] Fix | Delete
--$comment_depth;
[76] Fix | Delete
} else {
[77] Fix | Delete
$block_content .= block_core_comment_template_render_comments(
[78] Fix | Delete
$children,
[79] Fix | Delete
$block
[80] Fix | Delete
);
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
$content .= sprintf( '<li id="comment-%1$s" %2$s>%3$s</li>', $comment->comment_ID, $comment_classes, $block_content );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
return $content;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Renders the `core/comment-template` block on the server.
[92] Fix | Delete
*
[93] Fix | Delete
* @since 6.0.0
[94] Fix | Delete
*
[95] Fix | Delete
* @param array $attributes Block attributes.
[96] Fix | Delete
* @param string $content Block default content.
[97] Fix | Delete
* @param WP_Block $block Block instance.
[98] Fix | Delete
*
[99] Fix | Delete
* @return string Returns the HTML representing the comments using the layout
[100] Fix | Delete
* defined by the block's inner blocks.
[101] Fix | Delete
*/
[102] Fix | Delete
function render_block_core_comment_template( $attributes, $content, $block ) {
[103] Fix | Delete
// Bail out early if the post ID is not set for some reason.
[104] Fix | Delete
if ( empty( $block->context['postId'] ) ) {
[105] Fix | Delete
return '';
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
if ( post_password_required( $block->context['postId'] ) ) {
[109] Fix | Delete
return;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
$comment_query = new WP_Comment_Query(
[113] Fix | Delete
build_comment_query_vars_from_block( $block )
[114] Fix | Delete
);
[115] Fix | Delete
[116] Fix | Delete
// Get an array of comments for the current post.
[117] Fix | Delete
$comments = $comment_query->get_comments();
[118] Fix | Delete
if ( count( $comments ) === 0 ) {
[119] Fix | Delete
return '';
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
$comment_order = get_option( 'comment_order' );
[123] Fix | Delete
[124] Fix | Delete
if ( 'desc' === $comment_order ) {
[125] Fix | Delete
$comments = array_reverse( $comments );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes();
[129] Fix | Delete
[130] Fix | Delete
return sprintf(
[131] Fix | Delete
'<ol %1$s>%2$s</ol>',
[132] Fix | Delete
$wrapper_attributes,
[133] Fix | Delete
block_core_comment_template_render_comments( $comments, $block )
[134] Fix | Delete
);
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Registers the `core/comment-template` block on the server.
[139] Fix | Delete
*
[140] Fix | Delete
* @since 6.0.0
[141] Fix | Delete
*/
[142] Fix | Delete
function register_block_core_comment_template() {
[143] Fix | Delete
register_block_type_from_metadata(
[144] Fix | Delete
__DIR__ . '/comment-template',
[145] Fix | Delete
array(
[146] Fix | Delete
'render_callback' => 'render_block_core_comment_template',
[147] Fix | Delete
'skip_inner_blocks' => true,
[148] Fix | Delete
)
[149] Fix | Delete
);
[150] Fix | Delete
}
[151] Fix | Delete
add_action( 'init', 'register_block_core_comment_template' );
[152] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function