2016-03-30 17:29:57 +00:00
< ? php
/**
2017-02-11 14:51:13 +00:00
* REST API Settings controller
*
* Handles requests to the / settings endpoints .
2016-03-30 17:29:57 +00:00
*
2018-03-06 18:04:58 +00:00
* @ package WooCommerce / API
* @ since 3.0 . 0
2016-03-30 17:29:57 +00:00
*/
2017-02-11 14:51:13 +00:00
2018-03-06 18:04:58 +00:00
defined ( 'ABSPATH' ) || exit ;
2017-02-11 14:51:13 +00:00
/**
* REST API Settings controller class .
*
* @ package WooCommerce / API
2018-05-17 10:44:46 +00:00
* @ extends WC_REST_Settings_V2_Controller
2017-02-11 14:51:13 +00:00
*/
2018-05-17 10:44:46 +00:00
class WC_REST_Settings_Controller extends WC_REST_Settings_V2_Controller {
2016-03-30 17:29:57 +00:00
2016-04-04 17:34:14 +00:00
/**
2018-05-17 10:44:46 +00:00
* Endpoint namespace .
2018-03-06 18:04:58 +00:00
*
* @ var string
2016-04-04 17:34:14 +00:00
*/
2018-05-17 10:44:46 +00:00
protected $namespace = 'wc/v3' ;
2018-05-17 15:14:38 +00:00
/**
* Register routes .
*/
public function register_routes () {
parent :: register_routes ();
register_rest_route ( $this -> namespace , '/' . $this -> rest_base . '/batch' , array (
array (
'methods' => WP_REST_Server :: EDITABLE ,
'callback' => array ( $this , 'batch_items' ),
'permission_callback' => array ( $this , 'update_items_permissions_check' ),
),
'schema' => array ( $this , 'get_public_batch_schema' ),
) );
}
/**
* Makes sure the current user has access to WRITE the settings APIs .
*
* @ param WP_REST_Request $request Full data about the request .
* @ return WP_Error | bool
*/
public function update_items_permissions_check ( $request ) {
if ( ! wc_rest_check_manager_permissions ( 'settings' , 'edit' ) ) {
return new WP_Error ( 'woocommerce_rest_cannot_edit' , __ ( 'Sorry, you cannot edit this resource.' , 'woocommerce' ), array ( 'status' => rest_authorization_required_code () ) );
}
return true ;
}
/**
* Update a setting .
*
* @ param WP_REST_Request $request Request data .
* @ return WP_Error | WP_REST_Response
*/
public function update_item ( $request ) {
$options_controller = new WC_REST_Dev_Setting_Options_Controller ();
$response = $options_controller -> update_item ( $request );
return $response ;
}
2018-09-11 19:21:10 +00:00
/**
* Get the groups schema , conforming to JSON Schema .
*
* @ since 3.0 . 0
* @ return array
*/
public function get_item_schema () {
$schema = array (
'$schema' => 'http://json-schema.org/draft-04/schema#' ,
'title' => 'setting_group' ,
'type' => 'object' ,
'properties' => array (
'id' => array (
'description' => __ ( 'A unique identifier that can be used to link settings together.' , 'woocommerce' ),
'type' => 'string' ,
'context' => array ( 'view' , 'edit' ),
),
'label' => array (
'description' => __ ( 'A human readable label for the setting used in interfaces.' , 'woocommerce' ),
'type' => 'string' ,
'context' => array ( 'view' , 'edit' ),
),
'description' => array (
'description' => __ ( 'A human readable description for the setting used in interfaces.' , 'woocommerce' ),
'type' => 'string' ,
'context' => array ( 'view' , 'edit' ),
),
'parent_id' => array (
'description' => __ ( 'ID of parent grouping.' , 'woocommerce' ),
'type' => 'string' ,
'context' => array ( 'view' , 'edit' ),
),
'sub_groups' => array (
'description' => __ ( 'IDs for settings sub groups.' , 'woocommerce' ),
'type' => 'string' ,
'context' => array ( 'view' , 'edit' ),
),
),
);
return $this -> add_additional_fields_schema ( $schema );
}
2016-03-30 17:29:57 +00:00
}