Skip to content
Open
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 @@ -89,6 +89,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;

/*
Expand Down
43 changes: 25 additions & 18 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,11 @@ function create_initial_comment_types() {
* - `public` states display-surface intent: whether the type is meant to be seen by site
* visitors. It does not affect what queries return.
* - `internal` marks the type as excluded from comment queries and counts by default.
* - `show_in_rest` controls REST discovery of the type's metadata, and nothing else.
*
* An argument never implies another argument. The one cascade planned for the future is
* `show_in_rest`, which will default from `public`.
* An argument never implies another argument, with one deliberate exception:
* `show_in_rest` defaults from `public`, since a type meant to be seen is a type worth
* discovering.
*
* Registrations live in a per-process global. Like post types, they are not scoped to a
* site on multisite: a type registered by one site's plugins is visible after
Expand All @@ -434,22 +436,27 @@ 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. Internal types
* are excluded from comment queries and counts by default, through
* the {@see 'default_excluded_comment_types'} filter. 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 excluded from comment queries and counts by default, through
* the {@see 'default_excluded_comment_types'} filter. 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.
* @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
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
Loading