Completed
Push — branch-5.0 ( 360082...ee9cce )
by Jeremy
96:49 queued 85:16
created

Jetpack_JSON_API_Get_Option_Backup_Endpoint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate_input() 0 15 3
A result() 0 4 1
A get_option_row() 0 4 1
1
<?php
2
3
class Jetpack_JSON_API_Get_Option_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
4
	// /sites/%s/options/backup      -> $blog_id
5
6
	protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
7
	protected $option_names;
8
9
	function validate_input( $object ) {
10
		$query_args = $this->query_args();		
11
12
		if ( empty( $query_args['name'] ) ) {
13
			return new WP_Error( 'option_name_not_specified', __( 'You must specify an option name', 'jetpack' ), 400 );
14
		}
15
16
		if ( is_array( $query_args['name'] ) ) {
17
			$this->option_names = $query_args['name'];
18
		} else {
19
			$this->option_names = array( $query_args['name'] );
20
		}
21
22
		return true;
23
	}
24
25
	protected function result() {
26
		$options = array_map( array( $this, 'get_option_row' ), $this->option_names );
27
		return array( 'options' => $options );
28
	}
29
30
	private function get_option_row( $name ) {
31
		global $wpdb;
32
		return $wpdb->get_row( $wpdb->prepare( "select * from `{$wpdb->options}` where option_name = %s", $name ) );
33
	}
34
35
}
36