rest_prepare_comment
Filters a comment returned from the REST API.
Allows modification of the comment right before it is returned.
Usage
add_filter( 'rest_prepare_comment', 'wp_kama_rest_prepare_comment_filter', 10, 3 );
/**
* Function for `rest_prepare_comment` filter-hook.
*
* @param WP_REST_Response $response The response object.
* @param WP_Comment $comment The original comment object.
* @param WP_REST_Request $request Request used to generate the response.
*
* @return WP_REST_Response
*/
function wp_kama_rest_prepare_comment_filter( $response, $comment, $request ){
// filter...
return $response;
}
- $response(WP_REST_Response)
- The response object.
- $comment(WP_Comment)
- The original comment object.
- $request(WP_REST_Request)
- Request used to generate the response.
Changelog
| Since 4.7.0 | Introduced. |
Where the hook is called
rest_prepare_comment
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php 1229
return apply_filters( 'rest_prepare_comment', $response, $comment, $request );
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php 1129
return apply_filters( 'rest_prepare_comment', new WP_REST_Response( array() ), $comment, $request );