Completed
Push — add/protect-module-sync-packag... ( ad899a...19deca )
by
unknown
133:23 queued 125:08
created

class.wpcom-json-api-get-option-endpoint.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use Automattic\Jetpack\Sync\Defaults;
4
5
class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
6
7
	protected $needed_capabilities = 'manage_options';
8
9
	public $option_name;
10
	public $site_option;
11
12
	function result() {
13
		if ( $this->site_option ) {
14
			return array( 'option_value' => get_site_option( $this->option_name ) );
15
		}
16
		return array( 'option_value' => get_option( $this->option_name ) );
17
	}
18
19
	function validate_input( $object ) {
20
		$query_args = $this->query_args();
21
		$this->option_name = isset( $query_args['option_name'] ) ? $query_args['option_name'] : false;
22
		if ( ! $this->option_name ) {
23
			return new WP_Error( 'option_name_not_set', __( 'You must specify an option_name', 'jetpack' ) );
24
		}
25
		$this->site_option = isset( $query_args['site_option'] ) ? $query_args['site_option'] : false;
26
27
		/**
28
		 * Filter the list of options that are manageable via the JSON API.
29
		 *
30
		 * @module json-api
31
		 *
32
		 * @since 3.8.2
33
		 *
34
		 * @param array The default list of site options.
35
		 * @param bool Is the option a site option.
36
		 */
37
		if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Defaults::$default_options_whitelist, $this->site_option ) ) ) {
0 ignored issues
show
The property default_options_whitelist cannot be accessed from this context as it is declared private in class Automattic\Jetpack\Sync\Defaults.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
38
			return new WP_Error( 'option_name_not_in_whitelist', __( 'You must specify a whitelisted option_name', 'jetpack' ) );
39
		}
40
		return true;
41
	}
42
}
43