class.wpcom-json-api-get-comment-endpoint.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. new WPCOM_JSON_API_Get_Comment_Endpoint( array(
  3. 'description' => 'Get a single comment.',
  4. 'group' => 'comments',
  5. 'stat' => 'comments:1',
  6. 'method' => 'GET',
  7. 'path' => '/sites/%s/comments/%d',
  8. 'path_labels' => array(
  9. '$site' => '(int|string) Site ID or domain',
  10. '$comment_ID' => '(int) The comment ID'
  11. ),
  12. 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/comments/147564'
  13. ) );
  14. class WPCOM_JSON_API_Get_Comment_Endpoint extends WPCOM_JSON_API_Comment_Endpoint {
  15. // /sites/%s/comments/%d -> $blog_id, $comment_id
  16. function callback( $path = '', $blog_id = 0, $comment_id = 0 ) {
  17. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
  18. if ( is_wp_error( $blog_id ) ) {
  19. return $blog_id;
  20. }
  21. $args = $this->query_args();
  22. $return = $this->get_comment( $comment_id, $args['context'] );
  23. if ( !$return || is_wp_error( $return ) ) {
  24. return $return;
  25. }
  26. /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
  27. do_action( 'wpcom_json_api_objects', 'comments' );
  28. return $return;
  29. }
  30. }