WPCOM_JSON_API_Update_Option_Endpoint

The WordPress Core WPCOM JSON API Update Option Endpoint class.

Defined (1)

The class is defined in the following location(s).

/json-endpoints/jetpack/class.wpcom-json-api-update-option-endpoint.php  
  1. class WPCOM_JSON_API_Update_Option_Endpoint extends WPCOM_JSON_API_Get_Option_Endpoint { 
  2. public $option_value; 
  3.  
  4. function result() { 
  5. if ( $this->site_option ) { 
  6. update_site_option( $this->option_name, $this->option_value ); 
  7. } else { 
  8. update_option( $this->option_name, $this->option_value ); 
  9. return parent::result(); 
  10.  
  11. function validate_input( $object ) { 
  12. $input = $this->input(); 
  13. $query_args = $this->query_args(); 
  14. if ( ! isset( $input['option_value'] ) || is_array( $input['option_value'] ) ) { 
  15. return new WP_Error( 'option_value_not_set', __( 'You must specify an option_value', 'jetpack' ) ); 
  16. if ( $query_args['is_array'] ) { 
  17. // When converted back from JSON, the value is an object. 
  18. // Cast it to an array for options that expect arrays. 
  19. $this->option_value = (array) $input['option_value']; 
  20. } else { 
  21. $this->option_value = $input['option_value']; 
  22.  
  23. return parent::validate_input( $object );