Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_JSON_API_Get_Post_Backup_Endpoint | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| validate_input | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| result | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit( 0 ); |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Get post backup endpoint class. |
| 9 | * |
| 10 | * /sites/%s/posts/%d/backup -> $blog_id, $post_id |
| 11 | * |
| 12 | * @phan-constructor-used-for-side-effects |
| 13 | */ |
| 14 | class Jetpack_JSON_API_Get_Post_Backup_Endpoint extends Jetpack_JSON_API_Endpoint { |
| 15 | |
| 16 | /** |
| 17 | * Needed capabilities. |
| 18 | * |
| 19 | * @var array |
| 20 | */ |
| 21 | protected $needed_capabilities = array(); // This endpoint is only accessible using a site token |
| 22 | |
| 23 | /** |
| 24 | * The post ID. |
| 25 | * |
| 26 | * @var int |
| 27 | */ |
| 28 | protected $post_id; |
| 29 | |
| 30 | /** |
| 31 | * Validate the input. |
| 32 | * |
| 33 | * @param int $post_id - the post ID. |
| 34 | */ |
| 35 | public function validate_input( $post_id ) { |
| 36 | if ( empty( $post_id ) || ! is_numeric( $post_id ) ) { |
| 37 | return new WP_Error( 'post_id_not_specified', __( 'You must specify a Post ID', 'jetpack' ), 400 ); |
| 38 | } |
| 39 | |
| 40 | $this->post_id = (int) $post_id; |
| 41 | |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * The result. |
| 47 | * |
| 48 | * @return array|WP_Error |
| 49 | */ |
| 50 | protected function result() { |
| 51 | global $wpdb; |
| 52 | |
| 53 | // Disable Sync as this is a read-only operation and triggered by sync activity. |
| 54 | \Automattic\Jetpack\Sync\Actions::mark_sync_read_only(); |
| 55 | |
| 56 | $post = get_post( $this->post_id ); |
| 57 | if ( empty( $post ) ) { |
| 58 | return new WP_Error( 'post_not_found', __( 'Post not found', 'jetpack' ), 404 ); |
| 59 | } |
| 60 | |
| 61 | // Fetch terms associated with this post object |
| 62 | $terms = $wpdb->get_results( |
| 63 | $wpdb->prepare( |
| 64 | "SELECT term_taxonomy_id, term_order FROM {$wpdb->term_relationships} WHERE object_id = %d;", |
| 65 | $post->ID |
| 66 | ) |
| 67 | ); |
| 68 | |
| 69 | return array( |
| 70 | 'post' => (array) $post, |
| 71 | 'meta' => get_post_meta( $post->ID ), |
| 72 | 'terms' => (array) $terms, |
| 73 | ); |
| 74 | } |
| 75 | } |