Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
WPCOM_JSON_API_Get_Comment_Endpoint
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 callback
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
1<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2/**
3 * Endpoint: /sites/%s/comments/%d -> $blog_id, $comment_id
4 */
5
6if ( ! defined( 'ABSPATH' ) ) {
7    exit( 0 );
8}
9
10new WPCOM_JSON_API_Get_Comment_Endpoint(
11    array(
12        'description'                          => 'Get a single comment.',
13        'group'                                => 'comments',
14        'stat'                                 => 'comments:1',
15
16        'method'                               => 'GET',
17        'path'                                 => '/sites/%s/comments/%d',
18        'path_labels'                          => array(
19            '$site'       => '(int|string) Site ID or domain',
20            '$comment_ID' => '(int) The comment ID',
21        ),
22
23        'allow_fallback_to_jetpack_blog_token' => true,
24
25        'example_request'                      => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/comments/147564',
26    )
27);
28
29/**
30 * Get Comment endpoint class.
31 *
32 * @phan-constructor-used-for-side-effects
33 */
34class WPCOM_JSON_API_Get_Comment_Endpoint extends WPCOM_JSON_API_Comment_Endpoint {
35    /**
36     *
37     * API callback.
38     *
39     * @param string $path - the path.
40     * @param int    $blog_id - the blog ID.
41     * @param int    $comment_id - the comment ID.
42     */
43    public function callback( $path = '', $blog_id = 0, $comment_id = 0 ) {
44        $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
45        if ( is_wp_error( $blog_id ) ) {
46            return $blog_id;
47        }
48
49        $args = $this->query_args();
50
51        $return = $this->get_comment( $comment_id, $args['context'] );
52        if ( ! $return || is_wp_error( $return ) ) {
53            return $return;
54        }
55
56        /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
57        do_action( 'wpcom_json_api_objects', 'comments' );
58
59        return $return;
60    }
61}