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

Jetpack_JSON_API_Get_Post_Backup_Endpoint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate_input() 0 9 3
A result() 0 11 2
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