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

result()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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