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 ;
}
2016-03-30 17:29:57 +00:00
}