PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 13.6.2
Jetpack – WP Security, Backup, Speed, & Growth v13.6.2
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 13.6.2, at json-endpoints/jetpack/class.wpcom-json-api-update-option-endpoint.php

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