PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / json-endpoints / jetpack / class.wpcom-json-api-get-option-endpoint.php

class.wpcom-json-api-get-option-endpoint.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.5, at json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php

80 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 use Automattic\Jetpack\Sync\Defaults;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit( 0 );
7 }
8
9 /**
10 * Get option endpoint.
11 *
12 * @phan-constructor-used-for-side-effects
13 */
14 class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
15 /**
16 * This endpoint allows authentication both via a blog and a user token.
17 * If a user token is used, that user should have `manage_options` capability.
18 *
19 * @var array|string
20 */
21 protected $needed_capabilities = 'manage_options';
22
23 /**
24 * Options name.
25 *
26 * @var string
27 */
28 public $option_name;
29
30 /**
31 * Site option.
32 *
33 * @var string
34 */
35 public $site_option;
36
37 /**
38 * Endpoint callback.
39 *
40 * @return array
41 */
42 public function result() {
43 if ( $this->site_option ) {
44 return array( 'option_value' => get_site_option( $this->option_name ) );
45 }
46 return array( 'option_value' => get_option( $this->option_name ) );
47 }
48
49 /**
50 * Validate the input.
51 *
52 * @param object $object - unused, for parent class compatability.
53 *
54 * @return bool|WP_Error
55 */
56 public function validate_input( $object ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
57 $query_args = $this->query_args();
58 $this->option_name = $query_args['option_name'] ?? false;
59 if ( ! $this->option_name ) {
60 return new WP_Error( 'option_name_not_set', __( 'You must specify an option_name', 'jetpack' ) );
61 }
62 $this->site_option = $query_args['site_option'] ?? false;
63
64 /**
65 * Filter the list of options that are manageable via the JSON API.
66 *
67 * @module json-api
68 *
69 * @since 3.8.2
70 *
71 * @param array The default list of site options.
72 * @param bool Is the option a site option.
73 */
74 if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Defaults::$default_options_whitelist, $this->site_option ), true ) ) {
75 return new WP_Error( 'option_name_not_in_whitelist', __( 'You must specify a whitelisted option_name', 'jetpack' ) );
76 }
77 return true;
78 }
79 }
80