Ticket #41821: 41821v2.diff
File 41821v2.diff, 2.6 KB (added by , 6 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
237 237 $prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 ); 238 238 } 239 239 240 /* 241 * If hierarchical is true, get just top level comments. Keep parent from response if set. 242 * Children will be populated in $this->prepare_item_for_response(). 243 */ 244 if ( isset( $request[ 'hierarchical' ] ) && $request[ 'hierarchical' ] ) { 245 $prepared_args[ 'parent' ] = $request['parent'] ?: 0; 246 } 247 240 248 /** 241 249 * Filters arguments, before passing to WP_Comment_Query, when querying comments via the REST API. 242 250 * … … 942 950 $data = $this->add_additional_fields_to_object( $data, $request ); 943 951 $data = $this->filter_response_by_context( $data, $context ); 944 952 953 $children = $comment->get_children(); 954 // Loop through children and prepare them too 955 if (!empty($children)){ 956 foreach ($children as $child){ 957 //cehck read permission for each child 958 if ( ! $this->check_read_permission( $child, $request ) ) { 959 continue; 960 } 961 //prepare child for response 962 $child_response = $this->prepare_item_for_response($child, $request); 963 //prepare response for collection and add child to parent's data 964 $data['children'][] = $this->prepare_response_for_collection( $child_response->data); 965 } 966 } 967 945 968 // Wrap the data in a response object. 946 969 $response = rest_ensure_response( $data ); 947 970 … … 1251 1274 'sanitize_callback' => 'sanitize_text_field', 1252 1275 ), 1253 1276 ), 1277 'children' => array( 1278 'description' => __( "Comment's children, if hierarchical comments are requested." ), 1279 'type' => 'array', 1280 'context' => array( 'view', 'embed' ), 1281 ), 1254 1282 'content' => array( 1255 1283 'description' => __( 'The content for the object.' ), 1256 1284 'type' => 'object', … … 1405 1433 'default' => array(), 1406 1434 ); 1407 1435 1436 $query_params['hierarchical'] = array( 1437 'description' => __( 'Whether to include comment descendants in the results. Returns a flat array of found comments plus their children.' ), 1438 'type' => 'boolean', 1439 'default' => false, 1440 ); 1441 1408 1442 $query_params['include'] = array( 1409 1443 'description' => __( 'Limit result set to specific IDs.' ), 1410 1444 'type' => 'array',