@@ 3-31 (lines=29) @@ | ||
1 | <?php |
|
2 | ||
3 | class Jetpack_JSON_API_Get_Post_Backup_Endpoint extends Jetpack_JSON_API_Endpoint { |
|
4 | // /sites/%s/posts/%d/backup -> $blog_id, $post_id |
|
5 | ||
6 | protected $needed_capabilities = array(); // This endpoint is only accessible using a site token |
|
7 | protected $post_id; |
|
8 | ||
9 | function validate_input( $post_id ) { |
|
10 | if ( empty( $post_id ) || ! is_numeric( $post_id ) ) { |
|
11 | return new WP_Error( 'post_id_not_specified', __( 'You must specify a Post ID', 'jetpack' ), 400 ); |
|
12 | } |
|
13 | ||
14 | $this->post_id = intval( $post_id ); |
|
15 | ||
16 | return true; |
|
17 | } |
|
18 | ||
19 | protected function result() { |
|
20 | $post = get_post( $this->post_id ); |
|
21 | if ( empty( $post ) ) { |
|
22 | return new WP_Error( 'post_not_found', __( 'Post not found', 'jetpack' ), 404 ); |
|
23 | } |
|
24 | ||
25 | return array( |
|
26 | 'post' => (array)$post, |
|
27 | 'meta' => get_post_meta( $post->ID ), |
|
28 | ); |
|
29 | } |
|
30 | ||
31 | } |
|
32 |
@@ 3-31 (lines=29) @@ | ||
1 | <?php |
|
2 | ||
3 | class Jetpack_JSON_API_Get_Term_Backup_Endpoint extends Jetpack_JSON_API_Endpoint { |
|
4 | // /sites/%s/terms/%d/backup -> $blog_id, $term_id |
|
5 | ||
6 | protected $needed_capabilities = array(); // This endpoint is only accessible using a site token |
|
7 | protected $term_id; |
|
8 | ||
9 | function validate_input( $term_id ) { |
|
10 | if ( empty( $term_id ) || ! is_numeric( $term_id ) ) { |
|
11 | return new WP_Error( 'term_id_not_specified', __( 'You must specify a Term ID', 'jetpack' ), 400 ); |
|
12 | } |
|
13 | ||
14 | $this->term_id = intval( $term_id ); |
|
15 | ||
16 | return true; |
|
17 | } |
|
18 | ||
19 | protected function result() { |
|
20 | $term = get_term( $this->term_id ); |
|
21 | if ( empty( $term ) ) { |
|
22 | return new WP_Error( 'term_not_found', __( 'Term not found', 'jetpack' ), 404 ); |
|
23 | } |
|
24 | ||
25 | return array( |
|
26 | 'term' => (array) $term, |
|
27 | 'meta' => get_term_meta( $this->term_id ), |
|
28 | ); |
|
29 | } |
|
30 | ||
31 | } |
|
32 | ||
33 |
@@ 3-31 (lines=29) @@ | ||
1 | <?php |
|
2 | ||
3 | class Jetpack_JSON_API_Get_User_Backup_Endpoint extends Jetpack_JSON_API_Endpoint { |
|
4 | // /sites/%s/users/%d/backup -> $blog_id, $user_id |
|
5 | ||
6 | protected $needed_capabilities = array(); // This endpoint is only accessible using a site token |
|
7 | protected $user_id; |
|
8 | ||
9 | function validate_input( $user_id ) { |
|
10 | if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
11 | return new WP_Error( 'user_id_not_specified', __( 'You must specify a User ID', 'jetpack' ), 400 ); |
|
12 | } |
|
13 | ||
14 | $this->user_id = intval( $user_id ); |
|
15 | ||
16 | return true; |
|
17 | } |
|
18 | ||
19 | protected function result() { |
|
20 | $user = get_user_by( 'id', $this->user_id ); |
|
21 | if ( empty( $user ) ) { |
|
22 | return new WP_Error( 'user_not_found', __( 'User not found', 'jetpack' ), 404 ); |
|
23 | } |
|
24 | ||
25 | return array( |
|
26 | 'user' => (array)$user, |
|
27 | 'meta' => get_user_meta( $user->ID ), |
|
28 | ); |
|
29 | } |
|
30 | ||
31 | } |
|
32 | ||
33 |