Sin descripción

class.jetpack-json-api-get-comment-backup-endpoint.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class Jetpack_JSON_API_Get_Comment_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
  3. // /sites/%s/comments/%d/backup -> $blog_id, $comment_id
  4. protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
  5. protected $comment_id;
  6. function validate_input( $comment_id ) {
  7. if ( empty( $comment_id ) || ! is_numeric( $comment_id ) ) {
  8. return new WP_Error( 'comment_id_not_specified', __( 'You must specify a Comment ID', 'jetpack' ), 400 );
  9. }
  10. $this->comment_id = (int) $comment_id;
  11. return true;
  12. }
  13. protected function result() {
  14. // Disable Sync as this is a read-only operation and triggered by sync activity.
  15. \Automattic\Jetpack\Sync\Actions::mark_sync_read_only();
  16. $comment = get_comment( $this->comment_id );
  17. if ( empty( $comment ) ) {
  18. return new WP_Error( 'comment_not_found', __( 'Comment not found', 'jetpack' ), 404 );
  19. }
  20. $allowed_keys = array(
  21. 'comment_ID',
  22. 'comment_post_ID',
  23. 'comment_author',
  24. 'comment_author_email',
  25. 'comment_author_url',
  26. 'comment_author_IP',
  27. 'comment_date',
  28. 'comment_date_gmt',
  29. 'comment_content',
  30. 'comment_karma',
  31. 'comment_approved',
  32. 'comment_agent',
  33. 'comment_type',
  34. 'comment_parent',
  35. 'user_id',
  36. );
  37. $comment = array_intersect_key( $comment->to_array(), array_flip( $allowed_keys ) );
  38. $comment_meta = get_comment_meta( $comment['comment_ID'] );
  39. return array(
  40. 'comment' => $comment,
  41. 'meta' => is_array( $comment_meta ) ? $comment_meta : array(),
  42. );
  43. }
  44. }