Skip to content

Commit

Permalink
Set embedded true for comment children
Browse files Browse the repository at this point in the history
  • Loading branch information
DAreRodz committed Apr 11, 2022
1 parent 17b5ebf commit 269aef2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
24 changes: 0 additions & 24 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1451,27 +1451,3 @@ function get_comments_pagination_arrow( $block, $pagination_type = 'next' ) {
}
return null;
}

/**
* Mark the `children` attr of comments as embeddable so they can be included in
* REST API responses without additional requests.
*
* @since 6.0.0
*
* @return void
*/
function gutenberg_rest_comment_set_children_as_embeddable() {
add_filter(
'rest_prepare_comment',
function ( $response ) {
$links = $response->get_links();
if ( isset( $links['children'] ) ) {
$href = $links['children'][0]['href'];
$response->remove_link( 'children', $href );
$response->add_link( 'children', $href, array( 'embeddable' => true ) );
}
return $response;
}
);
}
add_action( 'rest_api_init', 'gutenberg_rest_comment_set_children_as_embeddable' );
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,8 @@ protected function prepare_links( $comment ) {
$rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) );

$links['children'] = array(
'href' => $rest_url,
'href' => $rest_url,
'embedded' => true,
);
}

Expand Down

0 comments on commit 269aef2

Please sign in to comment.