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-update-option-endpoint.php

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

58 lines 1.4 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 if ( ! defined( 'ABSPATH' ) ) {
4 exit( 0 );
5 }
6
7 /**
8 * Update option endpoint.
9 *
10 * @phan-constructor-used-for-side-effects
11 */
12 class WPCOM_JSON_API_Update_Option_Endpoint extends WPCOM_JSON_API_Get_Option_Endpoint {
13 /**
14 * The option value.
15 *
16 * @var string
17 */
18 public $option_value;
19
20 /**
21 * Endpoint callback.
22 *
23 * @return array
24 */
25 public function result() {
26 if ( $this->site_option ) {
27 update_site_option( $this->option_name, $this->option_value );
28 } else {
29 update_option( $this->option_name, $this->option_value );
30 }
31 return parent::result();
32 }
33
34 /**
35 * Validate the input.
36 *
37 * @param object $object - the object we're validating.
38 *
39 * @return bool|WP_Error
40 */
41 public function validate_input( $object ) {
42 $input = $this->input();
43 $query_args = $this->query_args();
44 if ( ! isset( $input['option_value'] ) || is_array( $input['option_value'] ) ) {
45 return new WP_Error( 'option_value_not_set', __( 'You must specify an option_value', 'jetpack' ) );
46 }
47 if ( $query_args['is_array'] ) {
48 // When converted back from JSON, the value is an object.
49 // Cast it to an array for options that expect arrays.
50 $this->option_value = (array) $input['option_value'];
51 } else {
52 $this->option_value = $input['option_value'];
53 }
54
55 return parent::validate_input( $object );
56 }
57 }
58