Index: src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
===================================================================
--- src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php	(revision 43438)
+++ src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php	(working copy)
@@ -43,69 +43,65 @@
 	 */
 	public function register_routes() {
 
-		register_rest_route(
-			$this->namespace, '/' . $this->rest_base, array(
-				array(
-					'methods'             => WP_REST_Server::READABLE,
-					'callback'            => array( $this, 'get_items' ),
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
-					'args'                => $this->get_collection_params(),
-				),
-				array(
-					'methods'             => WP_REST_Server::CREATABLE,
-					'callback'            => array( $this, 'create_item' ),
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
-				),
-				'schema' => array( $this, 'get_public_item_schema' ),
-			)
-		);
+		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
+			array(
+				'methods'   => WP_REST_Server::READABLE,
+				'callback'  => array( $this, 'get_items' ),
+				'permission_callback' => array( $this, 'get_items_permissions_check' ),
+				'args'      => $this->get_collection_params(),
+			),
+			array(
+				'methods'  => WP_REST_Server::CREATABLE,
+				'callback' => array( $this, 'create_item' ),
+				'permission_callback' => array( $this, 'create_item_permissions_check' ),
+				'args'     => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
+			),
+			'schema' => array( $this, 'get_public_item_schema' ),
+		) );
 
-		register_rest_route(
-			$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
-				'args'   => array(
-					'id' => array(
-						'description' => __( 'Unique identifier for the object.' ),
-						'type'        => 'integer',
-					),
+		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
+			'args' => array(
+				'id' => array(
+					'description' => __( 'Unique identifier for the object.' ),
+					'type'        => 'integer',
 				),
-				array(
-					'methods'             => WP_REST_Server::READABLE,
-					'callback'            => array( $this, 'get_item' ),
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
-					'args'                => array(
-						'context'  => $this->get_context_param( array( 'default' => 'view' ) ),
-						'password' => array(
-							'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
-							'type'        => 'string',
-						),
+			),
+			array(
+				'methods'  => WP_REST_Server::READABLE,
+				'callback' => array( $this, 'get_item' ),
+				'permission_callback' => array( $this, 'get_item_permissions_check' ),
+				'args'     => array(
+					'context'          => $this->get_context_param( array( 'default' => 'view' ) ),
+					'password' => array(
+						'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
+						'type'        => 'string',
 					),
 				),
-				array(
-					'methods'             => WP_REST_Server::EDITABLE,
-					'callback'            => array( $this, 'update_item' ),
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
-				),
-				array(
-					'methods'             => WP_REST_Server::DELETABLE,
-					'callback'            => array( $this, 'delete_item' ),
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
-					'args'                => array(
-						'force'    => array(
-							'type'        => 'boolean',
-							'default'     => false,
-							'description' => __( 'Whether to bypass trash and force deletion.' ),
-						),
-						'password' => array(
-							'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
-							'type'        => 'string',
-						),
+			),
+			array(
+				'methods'  => WP_REST_Server::EDITABLE,
+				'callback' => array( $this, 'update_item' ),
+				'permission_callback' => array( $this, 'update_item_permissions_check' ),
+				'args'     => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
+			),
+			array(
+				'methods'  => WP_REST_Server::DELETABLE,
+				'callback' => array( $this, 'delete_item' ),
+				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
+				'args'     => array(
+					'force'    => array(
+						'type'        => 'boolean',
+						'default'     => false,
+						'description' => __( 'Whether to bypass trash and force deletion.' ),
 					),
+					'password' => array(
+						'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
+						'type'        => 'string',
+					),
 				),
-				'schema' => array( $this, 'get_public_item_schema' ),
-			)
-		);
+			),
+			'schema' => array( $this, 'get_public_item_schema' ),
+		) );
 	}
 
 	/**
@@ -219,6 +215,14 @@
 			$prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] );
 		}
 
+		/* 
+		 * If hierarchical is true, get just top level comments. Keep parent from response if set.
+		 * Children will be populated in $this->prepare_item_for_response().
+		 */		 
+		if (  isset( $request[ 'hierarchical' ] ) && $request[ 'hierarchical' ] ) {
+				$prepared_args[ 'parent' ] = $request['parent'] ?: 	0;
+		}
+		
 		$prepared_args['no_found_rows'] = false;
 
 		$prepared_args['date_query'] = array();
@@ -248,10 +252,10 @@
 		 * @param WP_REST_Request $request       The current request.
 		 */
 		$prepared_args = apply_filters( 'rest_comment_query', $prepared_args, $request );
-
-		$query        = new WP_Comment_Query;
+		
+		$query = new WP_Comment_Query;
 		$query_result = $query->query( $prepared_args );
-
+		
 		$comments = array();
 
 		foreach ( $query_result as $comment ) {
@@ -259,7 +263,7 @@
 				continue;
 			}
 
-			$data       = $this->prepare_item_for_response( $comment, $request );
+			$data = $this->prepare_item_for_response( $comment, $request );
 			$comments[] = $this->prepare_response_for_collection( $data );
 		}
 
@@ -270,11 +274,11 @@
 			// Out-of-bounds, run the query again without LIMIT for total count.
 			unset( $prepared_args['number'], $prepared_args['offset'] );
 
-			$query                  = new WP_Comment_Query;
+			$query = new WP_Comment_Query;
 			$prepared_args['count'] = true;
 
 			$total_comments = $query->query( $prepared_args );
-			$max_pages      = ceil( $total_comments / $request['per_page'] );
+			$max_pages = ceil( $total_comments / $request['per_page'] );
 		}
 
 		$response = rest_ensure_response( $comments );
@@ -318,7 +322,7 @@
 			return $error;
 		}
 
-		$id      = (int) $id;
+		$id = (int) $id;
 		$comment = get_comment( $id );
 		if ( empty( $comment ) ) {
 			return $error;
@@ -379,7 +383,7 @@
 			return $comment;
 		}
 
-		$data     = $this->prepare_item_for_response( $comment, $request );
+		$data = $this->prepare_item_for_response( $comment, $request );
 		$response = rest_ensure_response( $data );
 
 		return $response;
@@ -419,8 +423,7 @@
 
 		// Limit who can set comment `author`, `author_ip` or `status` to anything other than the default.
 		if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) {
-			return new WP_Error(
-				'rest_comment_invalid_author',
+			return new WP_Error( 'rest_comment_invalid_author',
 				/* translators: %s: request parameter */
 				sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ),
 				array( 'status' => rest_authorization_required_code() )
@@ -429,8 +432,7 @@
 
 		if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) {
 			if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) {
-				return new WP_Error(
-					'rest_comment_invalid_author_ip',
+				return new WP_Error( 'rest_comment_invalid_author_ip',
 					/* translators: %s: request parameter */
 					sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ),
 					array( 'status' => rest_authorization_required_code() )
@@ -439,8 +441,7 @@
 		}
 
 		if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) {
-			return new WP_Error(
-				'rest_comment_invalid_status',
+			return new WP_Error( 'rest_comment_invalid_status',
 				/* translators: %s: request parameter */
 				sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ),
 				array( 'status' => rest_authorization_required_code() )
@@ -522,10 +523,10 @@
 		if ( is_user_logged_in() && $missing_author ) {
 			$user = wp_get_current_user();
 
-			$prepared_comment['user_id']              = $user->ID;
-			$prepared_comment['comment_author']       = $user->display_name;
+			$prepared_comment['user_id'] = $user->ID;
+			$prepared_comment['comment_author'] = $user->display_name;
 			$prepared_comment['comment_author_email'] = $user->user_email;
-			$prepared_comment['comment_author_url']   = $user->user_url;
+			$prepared_comment['comment_author_url'] = $user->user_url;
 		}
 
 		// Honor the discussion setting that requires a name and email address of the comment author.
@@ -578,7 +579,7 @@
 		 * skipping further processing.
 		 *
 		 * @since 4.7.0
-		 * @since 4.8.0 `$prepared_comment` can now be a WP_Error to shortcircuit insertion.
+		 * @since 4.8.0 $prepared_comment can now be a WP_Error to shortcircuit insertion.
 		 *
 		 * @param array|WP_Error  $prepared_comment The prepared comment data for wp_insert_comment().
 		 * @param WP_REST_Request $request          Request used to insert the comment.
@@ -638,6 +639,7 @@
 		$response->set_status( 201 );
 		$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment_id ) ) );
 
+
 		return $response;
 	}
 
@@ -810,14 +812,9 @@
 
 		if ( $force ) {
 			$previous = $this->prepare_item_for_response( $comment, $request );
-			$result   = wp_delete_comment( $comment->comment_ID, true );
+			$result = wp_delete_comment( $comment->comment_ID, true );
 			$response = new WP_REST_Response();
-			$response->set_data(
-				array(
-					'deleted'  => true,
-					'previous' => $previous->get_data(),
-				)
-			);
+			$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
 		} else {
 			// If this type doesn't support trashing, error out.
 			if ( ! $supports_trash ) {
@@ -829,8 +826,8 @@
 				return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) );
 			}
 
-			$result   = wp_trash_comment( $comment->comment_ID );
-			$comment  = get_comment( $comment->comment_ID );
+			$result = wp_trash_comment( $comment->comment_ID );
+			$comment = get_comment( $comment->comment_ID );
 			$response = $this->prepare_item_for_response( $comment, $request );
 		}
 
@@ -862,79 +859,44 @@
 	 * @return WP_REST_Response Response object.
 	 */
 	public function prepare_item_for_response( $comment, $request ) {
-
-		$fields = $this->get_fields_for_response( $request );
-		$data   = array();
-
-		if ( in_array( 'id', $fields, true ) ) {
-			$data['id'] = (int) $comment->comment_ID;
-		}
-
-		if ( in_array( 'post', $fields, true ) ) {
-			$data['post'] = (int) $comment->comment_post_ID;
-		}
-
-		if ( in_array( 'parent', $fields, true ) ) {
-			$data['parent'] = (int) $comment->comment_parent;
-		}
-
-		if ( in_array( 'author', $fields, true ) ) {
-			$data['author'] = (int) $comment->user_id;
-		}
-
-		if ( in_array( 'author_name', $fields, true ) ) {
-			$data['author_name'] = $comment->comment_author;
-		}
-
-		if ( in_array( 'author_email', $fields, true ) ) {
-			$data['author_email'] = $comment->comment_author_email;
-		}
-
-		if ( in_array( 'author_url', $fields, true ) ) {
-			$data['author_url'] = $comment->comment_author_url;
-		}
-
-		if ( in_array( 'author_ip', $fields, true ) ) {
-			$data['author_ip'] = $comment->comment_author_IP;
-		}
-
-		if ( in_array( 'author_user_agent', $fields, true ) ) {
-			$data['author_user_agent'] = $comment->comment_agent;
-		}
-
-		if ( in_array( 'date', $fields, true ) ) {
-			$data['date'] = mysql_to_rfc3339( $comment->comment_date );
-		}
-
-		if ( in_array( 'date_gmt', $fields, true ) ) {
-			$data['date_gmt'] = mysql_to_rfc3339( $comment->comment_date_gmt );
-		}
-
-		if ( in_array( 'content', $fields, true ) ) {
-			$data['content'] = array(
+		$data = array(
+			'id'                 => (int) $comment->comment_ID,
+			'post'               => (int) $comment->comment_post_ID,
+			'parent'             => (int) $comment->comment_parent,
+			'author'             => (int) $comment->user_id,
+			'author_name'        => $comment->comment_author,
+			'author_email'       => $comment->comment_author_email,
+			'author_url'         => $comment->comment_author_url,
+			'author_ip'          => $comment->comment_author_IP,
+			'author_user_agent'  => $comment->comment_agent,
+			'date'               => mysql_to_rfc3339( $comment->comment_date ),
+			'date_gmt'           => mysql_to_rfc3339( $comment->comment_date_gmt ),
+			'content'             => array(
 				/** This filter is documented in wp-includes/comment-template.php */
 				'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ),
 				'raw'      => $comment->comment_content,
-			);
+			),
+			'link'               => get_comment_link( $comment ),
+			'status'             => $this->prepare_status_response( $comment->comment_approved ),
+			'type'               => get_comment_type( $comment->comment_ID ),
+		);
+		
+		$children = $comment->get_children();
+		// Loop through children and prepare them too
+		if (!empty($children)){		
+			foreach ($children as $child){
+				$child_response = $this->prepare_item_for_response($child, $request);
+				$data['children'][] = $child_response->data;
+			}
 		}
+		
+		$schema = $this->get_item_schema();
 
-		if ( in_array( 'link', $fields, true ) ) {
-			$data['link'] = get_comment_link( $comment );
-		}
-
-		if ( in_array( 'status', $fields, true ) ) {
-			$data['status'] = $this->prepare_status_response( $comment->comment_approved );
-		}
-
-		if ( in_array( 'type', $fields, true ) ) {
-			$data['type'] = get_comment_type( $comment->comment_ID );
-		}
-
-		if ( in_array( 'author_avatar_urls', $fields, true ) ) {
+		if ( ! empty( $schema['properties']['author_avatar_urls'] ) ) {
 			$data['author_avatar_urls'] = rest_get_avatar_urls( $comment->comment_author_email );
 		}
 
-		if ( in_array( 'meta', $fields, true ) ) {
+		if ( ! empty( $schema['properties']['meta'] ) ) {
 			$data['meta'] = $this->meta->get_value( $comment->comment_ID, $request );
 		}
 
@@ -971,7 +933,7 @@
 	 */
 	protected function prepare_links( $comment ) {
 		$links = array(
-			'self'       => array(
+			'self' => array(
 				'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ),
 			),
 			'collection' => array(
@@ -990,7 +952,7 @@
 			$post = get_post( $comment->comment_post_ID );
 
 			if ( ! empty( $post->ID ) ) {
-				$obj  = get_post_type_object( $post->post_type );
+				$obj = get_post_type_object( $post->post_type );
 				$base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
 
 				$links['up'] = array(
@@ -1009,16 +971,14 @@
 		}
 
 		// Only grab one comment to verify the comment has children.
-		$comment_children = $comment->get_children(
-			array(
-				'number' => 1,
-				'count'  => true,
-			)
-		);
+		$comment_children = $comment->get_children( array(
+			'number' => 1,
+			'count'  => true
+		) );
 
 		if ( ! empty( $comment_children ) ) {
 			$args = array(
-				'parent' => $comment->comment_ID,
+				'parent' => $comment->comment_ID
 			);
 
 			$rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) );
@@ -1127,10 +1087,10 @@
 			$user = new WP_User( $request['author'] );
 
 			if ( $user->exists() ) {
-				$prepared_comment['user_id']              = $user->ID;
-				$prepared_comment['comment_author']       = $user->display_name;
+				$prepared_comment['user_id'] = $user->ID;
+				$prepared_comment['comment_author'] = $user->display_name;
 				$prepared_comment['comment_author_email'] = $user->user_email;
-				$prepared_comment['comment_author_url']   = $user->user_url;
+				$prepared_comment['comment_author_url'] = $user->user_url;
 			} else {
 				return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) );
 			}
@@ -1198,125 +1158,130 @@
 	 */
 	public function get_item_schema() {
 		$schema = array(
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
-			'title'      => 'comment',
-			'type'       => 'object',
-			'properties' => array(
-				'id'                => array(
-					'description' => __( 'Unique identifier for the object.' ),
-					'type'        => 'integer',
-					'context'     => array( 'view', 'edit', 'embed' ),
-					'readonly'    => true,
+			'$schema'              => 'http://json-schema.org/draft-04/schema#',
+			'title'                => 'comment',
+			'type'                 => 'object',
+			'properties'           => array(
+				'id'               => array(
+					'description'  => __( 'Unique identifier for the object.' ),
+					'type'         => 'integer',
+					'context'      => array( 'view', 'edit', 'embed' ),
+					'readonly'     => true,
 				),
-				'author'            => array(
-					'description' => __( 'The ID of the user object, if author was a user.' ),
-					'type'        => 'integer',
-					'context'     => array( 'view', 'edit', 'embed' ),
+				'author'           => array(
+					'description'  => __( 'The ID of the user object, if author was a user.' ),
+					'type'         => 'integer',
+					'context'      => array( 'view', 'edit', 'embed' ),
 				),
-				'author_email'      => array(
-					'description' => __( 'Email address for the object author.' ),
-					'type'        => 'string',
-					'format'      => 'email',
-					'context'     => array( 'edit' ),
-					'arg_options' => array(
+				'author_email'     => array(
+					'description'  => __( 'Email address for the object author.' ),
+					'type'         => 'string',
+					'format'       => 'email',
+					'context'      => array( 'edit' ),
+					'arg_options'  => array(
 						'sanitize_callback' => array( $this, 'check_comment_author_email' ),
 						'validate_callback' => null, // skip built-in validation of 'email'.
 					),
 				),
-				'author_ip'         => array(
-					'description' => __( 'IP address for the object author.' ),
-					'type'        => 'string',
-					'format'      => 'ip',
-					'context'     => array( 'edit' ),
+				'author_ip'     => array(
+					'description'  => __( 'IP address for the object author.' ),
+					'type'         => 'string',
+					'format'       => 'ip',
+					'context'      => array( 'edit' ),
 				),
-				'author_name'       => array(
-					'description' => __( 'Display name for the object author.' ),
-					'type'        => 'string',
-					'context'     => array( 'view', 'edit', 'embed' ),
-					'arg_options' => array(
+				'author_name'     => array(
+					'description'  => __( 'Display name for the object author.' ),
+					'type'         => 'string',
+					'context'      => array( 'view', 'edit', 'embed' ),
+					'arg_options'  => array(
 						'sanitize_callback' => 'sanitize_text_field',
 					),
 				),
-				'author_url'        => array(
-					'description' => __( 'URL for the object author.' ),
-					'type'        => 'string',
-					'format'      => 'uri',
-					'context'     => array( 'view', 'edit', 'embed' ),
+				'author_url'       => array(
+					'description'  => __( 'URL for the object author.' ),
+					'type'         => 'string',
+					'format'       => 'uri',
+					'context'      => array( 'view', 'edit', 'embed' ),
 				),
-				'author_user_agent' => array(
-					'description' => __( 'User agent for the object author.' ),
-					'type'        => 'string',
-					'context'     => array( 'edit' ),
-					'arg_options' => array(
+				'author_user_agent'     => array(
+					'description'  => __( 'User agent for the object author.' ),
+					'type'         => 'string',
+					'context'      => array( 'edit' ),
+					'arg_options'  => array(
 						'sanitize_callback' => 'sanitize_text_field',
 					),
+				),				
+				'children'             => array(
+					'description'  => __( "Comment's children, if hierarchical comments are requested." ),
+					'type'         => 'array',
+					'context'      => array( 'view', 'embed' ),
 				),
-				'content'           => array(
-					'description' => __( 'The content for the object.' ),
-					'type'        => 'object',
-					'context'     => array( 'view', 'edit', 'embed' ),
-					'arg_options' => array(
+				'content'          => array(
+					'description'     => __( 'The content for the object.' ),
+					'type'            => 'object',
+					'context'         => array( 'view', 'edit', 'embed' ),
+					'arg_options'     => array(
 						'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
 						'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database()
 					),
-					'properties'  => array(
-						'raw'      => array(
-							'description' => __( 'Content for the object, as it exists in the database.' ),
-							'type'        => 'string',
-							'context'     => array( 'edit' ),
+					'properties'      => array(
+						'raw'         => array(
+							'description'     => __( 'Content for the object, as it exists in the database.' ),
+							'type'            => 'string',
+							'context'         => array( 'edit' ),
 						),
-						'rendered' => array(
-							'description' => __( 'HTML content for the object, transformed for display.' ),
-							'type'        => 'string',
-							'context'     => array( 'view', 'edit', 'embed' ),
-							'readonly'    => true,
+						'rendered'    => array(
+							'description'     => __( 'HTML content for the object, transformed for display.' ),
+							'type'            => 'string',
+							'context'         => array( 'view', 'edit', 'embed' ),
+							'readonly'        => true,
 						),
 					),
 				),
-				'date'              => array(
-					'description' => __( "The date the object was published, in the site's timezone." ),
-					'type'        => 'string',
-					'format'      => 'date-time',
-					'context'     => array( 'view', 'edit', 'embed' ),
+				'date'             => array(
+					'description'  => __( "The date the object was published, in the site's timezone." ),
+					'type'         => 'string',
+					'format'       => 'date-time',
+					'context'      => array( 'view', 'edit', 'embed' ),
 				),
-				'date_gmt'          => array(
-					'description' => __( 'The date the object was published, as GMT.' ),
-					'type'        => 'string',
-					'format'      => 'date-time',
-					'context'     => array( 'view', 'edit' ),
+				'date_gmt'         => array(
+					'description'  => __( 'The date the object was published, as GMT.' ),
+					'type'         => 'string',
+					'format'       => 'date-time',
+					'context'      => array( 'view', 'edit' ),
 				),
-				'link'              => array(
-					'description' => __( 'URL to the object.' ),
-					'type'        => 'string',
-					'format'      => 'uri',
-					'context'     => array( 'view', 'edit', 'embed' ),
-					'readonly'    => true,
+				'link'             => array(
+					'description'  => __( 'URL to the object.' ),
+					'type'         => 'string',
+					'format'       => 'uri',
+					'context'      => array( 'view', 'edit', 'embed' ),
+					'readonly'     => true,
 				),
-				'parent'            => array(
-					'description' => __( 'The ID for the parent of the object.' ),
-					'type'        => 'integer',
-					'context'     => array( 'view', 'edit', 'embed' ),
-					'default'     => 0,
+				'parent'           => array(
+					'description'  => __( 'The ID for the parent of the object.' ),
+					'type'         => 'integer',
+					'context'      => array( 'view', 'edit', 'embed' ),
+					'default'      => 0,
 				),
-				'post'              => array(
-					'description' => __( 'The ID of the associated post object.' ),
-					'type'        => 'integer',
-					'context'     => array( 'view', 'edit' ),
-					'default'     => 0,
+				'post'             => array(
+					'description'  => __( 'The ID of the associated post object.' ),
+					'type'         => 'integer',
+					'context'      => array( 'view', 'edit' ),
+					'default'      => 0,
 				),
-				'status'            => array(
-					'description' => __( 'State of the object.' ),
-					'type'        => 'string',
-					'context'     => array( 'view', 'edit' ),
-					'arg_options' => array(
+				'status'           => array(
+					'description'  => __( 'State of the object.' ),
+					'type'         => 'string',
+					'context'      => array( 'view', 'edit' ),
+					'arg_options'  => array(
 						'sanitize_callback' => 'sanitize_key',
 					),
 				),
-				'type'              => array(
-					'description' => __( 'Type of Comment for the object.' ),
-					'type'        => 'string',
-					'context'     => array( 'view', 'edit', 'embed' ),
-					'readonly'    => true,
+				'type'             => array(
+					'description'  => __( 'Type of Comment for the object.' ),
+					'type'         => 'string',
+					'context'      => array( 'view', 'edit', 'embed' ),
+					'readonly'     => true,
 				),
 			),
 		);
@@ -1336,11 +1301,11 @@
 			}
 
 			$schema['properties']['author_avatar_urls'] = array(
-				'description' => __( 'Avatar URLs for the object author.' ),
-				'type'        => 'object',
-				'context'     => array( 'view', 'edit', 'embed' ),
-				'readonly'    => true,
-				'properties'  => $avatar_properties,
+				'description'   => __( 'Avatar URLs for the object author.' ),
+				'type'          => 'object',
+				'context'       => array( 'view', 'edit', 'embed' ),
+				'readonly'      => true,
+				'properties'    => $avatar_properties,
 			);
 		}
 
@@ -1362,78 +1327,85 @@
 		$query_params['context']['default'] = 'view';
 
 		$query_params['after'] = array(
-			'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ),
-			'type'        => 'string',
-			'format'      => 'date-time',
+			'description'       => __( 'Limit response to comments published after a given ISO8601 compliant date.' ),
+			'type'              => 'string',
+			'format'            => 'date-time',
 		);
 
 		$query_params['author'] = array(
-			'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ),
-			'type'        => 'array',
-			'items'       => array(
-				'type' => 'integer',
+			'description'       => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ),
+			'type'              => 'array',
+			'items'             => array(
+				'type'          => 'integer',
 			),
 		);
 
 		$query_params['author_exclude'] = array(
-			'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ),
-			'type'        => 'array',
-			'items'       => array(
-				'type' => 'integer',
+			'description'       => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ),
+			'type'              => 'array',
+			'items'             => array(
+				'type'          => 'integer',
 			),
 		);
 
 		$query_params['author_email'] = array(
-			'default'     => null,
-			'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ),
-			'format'      => 'email',
-			'type'        => 'string',
+			'default'           => null,
+			'description'       => __( 'Limit result set to that from a specific author email. Requires authorization.' ),
+			'format'            => 'email',
+			'type'              => 'string',
 		);
 
 		$query_params['before'] = array(
-			'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ),
-			'type'        => 'string',
-			'format'      => 'date-time',
+			'description'       => __( 'Limit response to comments published before a given ISO8601 compliant date.' ),
+			'type'              => 'string',
+			'format'            => 'date-time',
 		);
 
 		$query_params['exclude'] = array(
-			'description' => __( 'Ensure result set excludes specific IDs.' ),
-			'type'        => 'array',
-			'items'       => array(
-				'type' => 'integer',
+			'description'        => __( 'Ensure result set excludes specific IDs.' ),
+			'type'               => 'array',
+			'items'              => array(
+				'type'           => 'integer',
 			),
-			'default'     => array(),
+			'default'            => array(),
 		);
+		
+		$query_params['hierarchical'] = array(
+                        'description' => __( 'Whether to include comment descendants in the results. Returns a flat array of found comments plus their children.' ),
+                        'type'        => 'boolean',
+						'default'     => false,
+                );
 
+
 		$query_params['include'] = array(
-			'description' => __( 'Limit result set to specific IDs.' ),
-			'type'        => 'array',
-			'items'       => array(
-				'type' => 'integer',
+			'description'        => __( 'Limit result set to specific IDs.' ),
+			'type'               => 'array',
+			'items'              => array(
+				'type'           => 'integer',
 			),
-			'default'     => array(),
+			'default'            => array(),
 		);
 
 		$query_params['offset'] = array(
-			'description' => __( 'Offset the result set by a specific number of items.' ),
-			'type'        => 'integer',
+			'description'        => __( 'Offset the result set by a specific number of items.' ),
+			'type'               => 'integer',
 		);
 
-		$query_params['order'] = array(
-			'description' => __( 'Order sort attribute ascending or descending.' ),
-			'type'        => 'string',
-			'default'     => 'desc',
-			'enum'        => array(
+		$query_params['order']      = array(
+			'description'           => __( 'Order sort attribute ascending or descending.' ),
+			'type'                  => 'string',
+			'default'               => 'desc',
+			'enum'                  => array(
 				'asc',
 				'desc',
 			),
 		);
 
-		$query_params['orderby'] = array(
-			'description' => __( 'Sort collection by object attribute.' ),
-			'type'        => 'string',
-			'default'     => 'date_gmt',
-			'enum'        => array(
+		$query_params['orderby']    = array(
+			'description'           => __( 'Sort collection by object attribute.' ),
+			'type'                  => 'string',
+			'default'               => 'date_gmt',
+			'enum'                  => array(
 				'date',
 				'date_gmt',
 				'id',
@@ -1445,29 +1417,29 @@
 		);
 
 		$query_params['parent'] = array(
-			'default'     => array(),
-			'description' => __( 'Limit result set to comments of specific parent IDs.' ),
-			'type'        => 'array',
-			'items'       => array(
-				'type' => 'integer',
+			'default'           => array(),
+			'description'       => __( 'Limit result set to comments of specific parent IDs.' ),
+			'type'              => 'array',
+			'items'             => array(
+				'type'          => 'integer',
 			),
 		);
 
 		$query_params['parent_exclude'] = array(
-			'default'     => array(),
-			'description' => __( 'Ensure result set excludes specific parent IDs.' ),
-			'type'        => 'array',
-			'items'       => array(
-				'type' => 'integer',
+			'default'           => array(),
+			'description'       => __( 'Ensure result set excludes specific parent IDs.' ),
+			'type'              => 'array',
+			'items'             => array(
+				'type'          => 'integer',
 			),
 		);
 
-		$query_params['post'] = array(
-			'default'     => array(),
-			'description' => __( 'Limit result set to comments assigned to specific post IDs.' ),
-			'type'        => 'array',
-			'items'       => array(
-				'type' => 'integer',
+		$query_params['post']   = array(
+			'default'           => array(),
+			'description'       => __( 'Limit result set to comments assigned to specific post IDs.' ),
+			'type'              => 'array',
+			'items'             => array(
+				'type'          => 'integer',
 			),
 		);
 
@@ -1523,7 +1495,7 @@
 		}
 
 		switch ( $new_status ) {
-			case 'approved':
+			case 'approved' :
 			case 'approve':
 			case '1':
 				$changed = wp_set_comment_status( $comment_id, 'approve' );
@@ -1532,19 +1504,19 @@
 			case '0':
 				$changed = wp_set_comment_status( $comment_id, 'hold' );
 				break;
-			case 'spam':
+			case 'spam' :
 				$changed = wp_spam_comment( $comment_id );
 				break;
-			case 'unspam':
+			case 'unspam' :
 				$changed = wp_unspam_comment( $comment_id );
 				break;
-			case 'trash':
+			case 'trash' :
 				$changed = wp_trash_comment( $comment_id );
 				break;
-			case 'untrash':
+			case 'untrash' :
 				$changed = wp_untrash_comment( $comment_id );
 				break;
-			default:
+			default :
 				$changed = false;
 				break;
 		}
@@ -1565,12 +1537,12 @@
 	 */
 	protected function check_read_post_permission( $post, $request ) {
 		$posts_controller = new WP_REST_Posts_Controller( $post->post_type );
-		$post_type        = get_post_type_object( $post->post_type );
+		$post_type = get_post_type_object( $post->post_type );
 
 		$has_password_filter = false;
 
 		// Only check password if a specific post was queried for or a single comment
-		$requested_post    = ! empty( $request['post'] ) && ( ! is_array( $request['post'] ) || 1 === count( $request['post'] ) );
+		$requested_post = ! empty( $request['post'] ) && ( !is_array( $request['post'] ) || 1 === count( $request['post'] ) );
 		$requested_comment = ! empty( $request['id'] );
 		if ( ( $requested_post || $requested_comment ) && $posts_controller->can_access_password_content( $post, $request ) ) {
 			add_filter( 'post_password_required', '__return_false' );
