暫無描述

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

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. 'allow_fallback_to_jetpack_blog_token' => true,
  13. 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/comments/147564'
  14. ) );
  15. class WPCOM_JSON_API_Get_Comment_Endpoint extends WPCOM_JSON_API_Comment_Endpoint {
  16. // /sites/%s/comments/%d -> $blog_id, $comment_id
  17. function callback( $path = '', $blog_id = 0, $comment_id = 0 ) {
  18. $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
  19. if ( is_wp_error( $blog_id ) ) {
  20. return $blog_id;
  21. }
  22. $args = $this->query_args();
  23. $return = $this->get_comment( $comment_id, $args['context'] );
  24. if ( !$return || is_wp_error( $return ) ) {
  25. return $return;
  26. }
  27. /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
  28. do_action( 'wpcom_json_api_objects', 'comments' );
  29. return $return;
  30. }
  31. }