PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | json-endpoints/class.wpcom-json-api-get-comment-endpoint.php +61 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,61 @@
1 +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 +/**
3 + * Endpoint: /sites/%s/comments/%d -> $blog_id, $comment_id
4 + */
5 +
6 +if ( ! defined( 'ABSPATH' ) ) {
7 + exit( 0 );
8 +}
9 +
10 +new 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 + */
34 +class 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 +}