Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
391424b
Comments: Allow comment types to register a display callback.
adamsilverstein Jun 24, 2026
7e8fbf8
Comments: Add tests for comment type display callbacks.
adamsilverstein Jun 24, 2026
eb22755
Comments: Cover render_callback argument contract and non-callable gu…
adamsilverstein Jun 25, 2026
338339b
Comments: Document that render_callback output is not escaped.
adamsilverstein Jun 25, 2026
43be061
Merge branch 'feature/register-comment-type' into feature/comment-typ…
adamsilverstein Jul 11, 2026
6f25cd6
Comments: Document the render_callback element contract and pin it wi…
adamsilverstein Jul 11, 2026
2965cc4
Merge branch 'feature/register-comment-type' into feature/comment-typ…
adamsilverstein Aug 13, 2026
486ccb9
Docs: Spell out the `render_callback` element, echo, and override con…
adamsilverstein Aug 13, 2026
0b19ed2
Comments: Pin the `render_callback` div style and built-in override p…
adamsilverstein Aug 13, 2026
66b0d4a
Merge branch 'feature/register-comment-type' into feature/comment-typ…
adamsilverstein Aug 23, 2026
ebd2e8c
Comments: Stamp the render_callback for 7.2.0 and pin its echo contract.
adamsilverstein Aug 23, 2026
9ccfedd
Merge branch 'feature/register-comment-type' into feature/comment-typ…
adamsilverstein Nov 8, 2026
fb8e383
Merge branch 'feature/register-comment-type' into feature/comment-typ…
adamsilverstein Nov 8, 2026
57be7b9
Comments: Tighten render_callback inline documentation.
adamsilverstein Nov 8, 2026
fdf5edf
Tests: Add native types to the render_callback tests.
adamsilverstein Nov 8, 2026
63cfde0
Merge branch 'feature/register-comment-type' into feature/comment-typ…
adamsilverstein Nov 8, 2026
c0f5198
Docs: Mark the new comment type APIs as @since 7.3.0.
adamsilverstein Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/wp-includes/class-walker-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public function display_element( $element, &$children_elements, $max_depth, $dep
* @since 2.7.0
* @since 5.9.0 Renamed `$comment` to `$data_object` and `$id` to `$current_object_id`
* to match parent class for PHP 8 named parameter support.
* @since 7.3.0 Comments of a registered comment type with a `render_callback`
* are rendered via that callback.
*
* @see Walker::start_el()
* @see wp_list_comments()
Expand Down Expand Up @@ -185,6 +187,16 @@ public function start_el( &$output, $data_object, $depth = 0, $args = array(), $
return;
}

// A registered comment type's render callback, after an explicit `callback` argument.
$comment_type_object = get_comment_type_object( $comment->comment_type );

if ( $comment_type_object && is_callable( $comment_type_object->render_callback ) ) {
ob_start();
call_user_func( $comment_type_object->render_callback, $comment, $args, $depth );
$output .= ob_get_clean();
return;
}

if ( 'comment' === $comment->comment_type ) {
add_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 );
}
Expand Down
31 changes: 26 additions & 5 deletions src/wp-includes/class-wp-comment-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ final class WP_Comment_Type {
*/
public $_builtin = false;

/**
* Callback used to render a comment of this type in wp_list_comments().
*
* Receives the same arguments as the wp_list_comments() `callback` argument,
* which takes precedence over it. Like that callback, it must echo only the
* opening of the element (a `<div>` when `$args['style']` is 'div', an `<li>`
* otherwise), which Walker_Comment::end_el() closes. A returned string is
* discarded, and output is not escaped.
*
* Setting a callback on the 'comment' type through the
* {@see 'register_comment_type_args'} filter also replaces the walker's link
* stripping for pending comments.
*
* Not used by the `core/comment-template` block. Default null.
*
* @since 7.3.0
* @var callable|null
*/
public $render_callback = null;

/**
* Whether the comment type is hierarchical.
*
Expand Down Expand Up @@ -172,11 +192,12 @@ public function set_props( $args ): void {

// No 'label' default, so get_comment_type_labels() can fall back to the default name.
$defaults = array(
'labels' => array(),
'description' => '',
'public' => true,
'internal' => false,
'_builtin' => false,
'labels' => array(),
'description' => '',
'public' => true,
'internal' => false,
'render_callback' => null,
'_builtin' => false,
);

$args = array_merge( $defaults, $args );
Expand Down
40 changes: 23 additions & 17 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,23 +434,29 @@ function create_initial_comment_types(): void {
* @param array|string $args {
* Optional. Array or string of arguments for registering a comment type. Default empty array.
*
* @type string $label Name of the comment type. Usually plural.
* Default is the value of $labels['name'].
* @type string[] $labels An array of labels for this comment type. If not set, the
* default comment labels are used. See get_comment_type_labels()
* for a full list of supported labels.
* @type string $description A short descriptive summary of what the comment type is.
* Default empty.
* @type bool $public Whether the comment type is intended for use publicly either via
* the admin interface or by front-end users. Core does not
* currently act on this argument. Default true.
* @type bool $internal Whether the comment type is for internal use only. Internal
* types are meant to be excluded from comment queries and counts
* by default. Core does not currently act on this argument.
* Default false.
* @type bool $_builtin For internal core use only. Marks the type as native to
* WordPress, which blocks it from being re-registered or
* unregistered. Default false.
* @type string $label Name of the comment type. Usually plural.
* Default is the value of $labels['name'].
* @type string[] $labels An array of labels for this comment type. If not set, the
* default comment labels are used. See get_comment_type_labels()
* for a full list of supported labels.
* @type string $description A short descriptive summary of what the comment type is.
* Default empty.
* @type bool $public Whether the comment type is intended for use publicly either
* via the admin interface or by front-end users. Core does not
* currently act on this argument. Default true.
* @type bool $internal Whether the comment type is for internal use only. Internal
* types are meant to be excluded from comment queries and
* counts by default. Core does not currently act on this
* argument. Default false.
* @type callable $render_callback Callback used to render a comment of this type in
* wp_list_comments(). Receives the same arguments as, and is
* overridden by, the wp_list_comments() `callback` argument.
* Must echo only the opening `<li>` (or `<div>` for the 'div'
* style), unescaped; a returned string is discarded.
* Default null.
* @type bool $_builtin For internal core use only. Marks the type as native to
* WordPress, which blocks it from being re-registered or
* unregistered. Default false.
* }
* @return WP_Comment_Type|WP_Error The registered comment type object on success,
* WP_Error object on failure.
Expand Down
Loading