Completed
Push — add/backups ( 1bc9bb...115ecb )
by
unknown
19:48 queued 09:10
created

result()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
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 = 'read_private_posts';
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' ) );
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' ) );
23
		}
24
25
		return array(
26
			'post' => (array)$post,
27
			'meta' => get_post_meta( $post->ID ),
28
		);
29
	}
30
31
}
32