Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 30 additions & 5 deletions src/wp-includes/class-wp-comment-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ final class WP_Comment_Type {
*/
public $internal = false;

/**
* Whether to include this comment type in the REST API.
*
* Comment types with this enabled are exposed by the read-only
* `/wp/v2/comment-types` discovery endpoint (name, slug, description,
* labels). It does not affect whether comments of this type are readable
* or queryable via `/wp/v2/comments`. Default is the value of $public.
*
* @since 7.1.0
* @var bool
*/
public $show_in_rest;

/**
* Whether this comment type is a native or "built-in" comment type.
*
Expand Down Expand Up @@ -183,15 +196,27 @@ public function set_props( $args ) {
* treated as a provided value and overwrite the default name with false.
*/
$defaults = array(
'labels' => array(),
'description' => '',
'public' => true,
'internal' => false,
'_builtin' => false,
'labels' => array(),
'description' => '',
'public' => true,
'internal' => false,
'show_in_rest' => null,
'_builtin' => false,
);

$args = array_merge( $defaults, $args );

/*
* If not set, default 'show_in_rest' to the setting for 'public'. This
* deliberately diverges from WP_Post_Type, which defaults it to false only
* for backward compatibility with post types registered before the REST API
* existed. A new registry has no such constraint, and 'show_in_rest' gates
* only the read-only comment-types discovery endpoint.
*/
if ( null === $args['show_in_rest'] ) {
$args['show_in_rest'] = $args['public'];
}

$args['name'] = $this->name;

foreach ( $args as $property_name => $property_value ) {
Expand Down
31 changes: 18 additions & 13 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,24 @@ function create_initial_comment_types() {
* @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. Core does not
* currently consult this flag; it is intended to drive default
* query exclusions in the future. 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. Core does not
* currently consult this flag; it is intended to drive default
* query exclusions in the future. Default false.
* @type bool $show_in_rest Whether to expose this comment type in the REST API comment types
* discovery endpoint (`/wp/v2/comment-types`). Exposing a type
* reveals its name, slug, description, and labels only; it does not
* make comments of this type readable or queryable via
* `/wp/v2/comments`. Default is the value of $public.
* }
* @return WP_Comment_Type|WP_Error The registered comment type object on success,
* WP_Error object on failure.
Expand Down
4 changes: 4 additions & 0 deletions src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ function create_initial_rest_routes() {
$controller = new WP_REST_Comments_Controller();
$controller->register_routes();

// Comment types.
$controller = new WP_REST_Comment_Types_Controller();
$controller->register_routes();

$search_handlers = array(
new WP_REST_Post_Search_Handler(),
new WP_REST_Term_Search_Handler(),
Expand Down
Loading