jetpack
1 week ago
class.wpcom-json-api-add-widget-endpoint.php
7 months ago
class.wpcom-json-api-autosave-post-v1-1-endpoint.php
7 months ago
class.wpcom-json-api-bulk-delete-post-endpoint.php
7 months ago
class.wpcom-json-api-bulk-restore-post-endpoint.php
7 months ago
class.wpcom-json-api-bulk-update-comments-endpoint.php
1 month ago
class.wpcom-json-api-comment-endpoint.php
7 months ago
class.wpcom-json-api-delete-media-endpoint.php
7 months ago
class.wpcom-json-api-delete-media-v1-1-endpoint.php
7 months ago
class.wpcom-json-api-edit-media-v1-2-endpoint.php
1 month ago
class.wpcom-json-api-get-autosave-v1-1-endpoint.php
7 months ago
class.wpcom-json-api-get-comment-counts-endpoint.php
7 months ago
class.wpcom-json-api-get-comment-endpoint.php
7 months ago
class.wpcom-json-api-get-comment-history-endpoint.php
7 months ago
class.wpcom-json-api-get-comments-tree-endpoint.php
7 months ago
class.wpcom-json-api-get-comments-tree-v1-1-endpoint.php
7 months ago
class.wpcom-json-api-get-comments-tree-v1-2-endpoint.php
7 months ago
class.wpcom-json-api-get-customcss.php
7 months ago
class.wpcom-json-api-get-media-endpoint.php
7 months ago
class.wpcom-json-api-get-media-v1-1-endpoint.php
7 months ago
class.wpcom-json-api-get-media-v1-2-endpoint.php
7 months ago
class.wpcom-json-api-get-post-counts-v1-1-endpoint.php
1 week ago
class.wpcom-json-api-get-post-endpoint.php
7 months ago
class.wpcom-json-api-get-post-v1-1-endpoint.php
7 months ago
class.wpcom-json-api-get-site-endpoint.php
1 week ago
class.wpcom-json-api-get-site-v1-2-endpoint.php
1 week ago
class.wpcom-json-api-get-taxonomies-endpoint.php
2 months ago
class.wpcom-json-api-get-taxonomy-endpoint.php
7 months ago
class.wpcom-json-api-get-term-endpoint.php
7 months ago
class.wpcom-json-api-list-comments-endpoint.php
1 week ago
class.wpcom-json-api-list-dropdown-pages-endpoint.php
7 months ago
class.wpcom-json-api-list-embeds-endpoint.php
7 months ago
class.wpcom-json-api-list-media-endpoint.php
7 months ago
class.wpcom-json-api-list-media-v1-1-endpoint.php
1 month ago
class.wpcom-json-api-list-media-v1-2-endpoint.php
7 months ago
class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
7 months ago
class.wpcom-json-api-list-post-types-endpoint.php
7 months ago
class.wpcom-json-api-list-posts-endpoint.php
1 week ago
class.wpcom-json-api-list-posts-v1-1-endpoint.php
1 week ago
class.wpcom-json-api-list-posts-v1-2-endpoint.php
1 week ago
class.wpcom-json-api-list-roles-endpoint.php
7 months ago
class.wpcom-json-api-list-shortcodes-endpoint.php
7 months ago
class.wpcom-json-api-list-terms-endpoint.php
7 months ago
class.wpcom-json-api-list-users-endpoint.php
1 week ago
class.wpcom-json-api-menus-v1-1-endpoint.php
1 month ago
class.wpcom-json-api-post-endpoint.php
7 months ago
class.wpcom-json-api-post-v1-1-endpoint.php
2 months ago
class.wpcom-json-api-render-embed-endpoint.php
7 months ago
class.wpcom-json-api-render-embed-reversal-endpoint.php
7 months ago
class.wpcom-json-api-render-endpoint.php
1 month ago
class.wpcom-json-api-render-shortcode-endpoint.php
7 months ago
class.wpcom-json-api-sharing-buttons-endpoint.php
1 month ago
class.wpcom-json-api-site-settings-endpoint.php
1 week ago
class.wpcom-json-api-site-settings-v1-2-endpoint.php
7 months ago
class.wpcom-json-api-site-settings-v1-3-endpoint.php
7 months ago
class.wpcom-json-api-site-settings-v1-4-endpoint.php
1 week ago
class.wpcom-json-api-site-user-endpoint.php
7 months ago
class.wpcom-json-api-taxonomy-endpoint.php
7 months ago
class.wpcom-json-api-update-comment-endpoint.php
5 months ago
class.wpcom-json-api-update-customcss.php
7 months ago
class.wpcom-json-api-update-media-endpoint.php
7 months ago
class.wpcom-json-api-update-media-v1-1-endpoint.php
1 month ago
class.wpcom-json-api-update-post-endpoint.php
1 month ago
class.wpcom-json-api-update-post-v1-1-endpoint.php
1 month ago
class.wpcom-json-api-update-post-v1-2-endpoint.php
1 month ago
class.wpcom-json-api-update-site-homepage-endpoint.php
7 months ago
class.wpcom-json-api-update-site-logo-endpoint.php
7 months ago
class.wpcom-json-api-update-taxonomy-endpoint.php
6 months ago
class.wpcom-json-api-update-term-endpoint.php
7 months ago
class.wpcom-json-api-update-user-endpoint.php
7 months ago
class.wpcom-json-api-upload-media-endpoint.php
7 months ago
class.wpcom-json-api-upload-media-v1-1-endpoint.php
7 months ago
class.wpcom-json-api-get-comment-history-endpoint.php
73 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Endpoint: /sites/%s/comment-history/%d |
| 4 | */ |
| 5 | |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | exit( 0 ); |
| 8 | } |
| 9 | |
| 10 | new WPCOM_JSON_API_GET_Comment_History_Endpoint( |
| 11 | array( |
| 12 | 'description' => 'Get the audit history for given comment', |
| 13 | 'group' => 'comments', |
| 14 | 'stat' => 'comments:1:comment-history', |
| 15 | 'method' => 'GET', |
| 16 | 'path' => '/sites/%s/comment-history/%d', |
| 17 | 'path_labels' => array( |
| 18 | '$site' => '(int|string) Site ID or domain', |
| 19 | '$comment_ID' => '(int) The comment ID', |
| 20 | ), |
| 21 | |
| 22 | 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/comment-history/11', |
| 23 | |
| 24 | 'response_format' => array( |
| 25 | 'comment_history' => '(array) Array of arrays representing the comment history objects.', |
| 26 | ), |
| 27 | ) |
| 28 | ); |
| 29 | /** |
| 30 | * GET Comment History endpoint. |
| 31 | * |
| 32 | * @phan-constructor-used-for-side-effects |
| 33 | */ |
| 34 | class WPCOM_JSON_API_GET_Comment_History_Endpoint extends WPCOM_JSON_API_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 | |
| 46 | if ( is_wp_error( $blog_id ) ) { |
| 47 | return $blog_id; |
| 48 | } |
| 49 | |
| 50 | if ( ! get_current_user_id() ) { |
| 51 | return new WP_Error( 'authorization_required', 'An active access token must be used to retrieve comment history.', 403 ); |
| 52 | } |
| 53 | |
| 54 | if ( ! current_user_can_for_site( $blog_id, 'edit_posts' ) ) { |
| 55 | return new WP_Error( 'authorization_required', 'You are not authorized to view comment history on this blog.', 403 ); |
| 56 | } |
| 57 | |
| 58 | if ( ! method_exists( 'Akismet', 'get_comment_history' ) ) { |
| 59 | return new WP_Error( 'akismet_required', 'Akismet plugin must be active for this feature to work', 503 ); |
| 60 | } |
| 61 | |
| 62 | $comment_history = Akismet::get_comment_history( $comment_id ); |
| 63 | |
| 64 | foreach ( $comment_history as &$item ) { |
| 65 | // Times are stored as floating point values in microseconds. |
| 66 | // We don't need that precision on the client so let's get rid of the decimal part. |
| 67 | $item['time'] = (int) $item['time']; |
| 68 | } |
| 69 | |
| 70 | return array( 'comment_history' => $comment_history ); |
| 71 | } |
| 72 | } |
| 73 |