Remove WC_REST_Settings_Controller dependency on WC_REST_Settings_API_Controller.

This commit is contained in:
Jeff Stieler 2016-06-16 14:47:56 -06:00 committed by Justin Shreve
parent 6f36179fe6
commit b31818e695
1 changed files with 24 additions and 2 deletions

View File

@ -13,13 +13,20 @@ if ( ! defined( 'ABSPATH' ) ) {
* @version 2.7.0
* @since 2.7.0
*/
class WC_Rest_Settings_Controller extends WC_REST_Settings_API_Controller {
class WC_Rest_Settings_Controller extends WC_REST_Controller {
/**
* WP REST API namespace/version.
*/
protected $namespace = 'wc/v1';
/**
* Route base.
*
* @var string
*/
protected $rest_base = 'settings';
/**
* Register routes.
* @since 2.7.0
@ -29,7 +36,7 @@ class WC_Rest_Settings_Controller extends WC_REST_Settings_API_Controller {
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'permissions_check' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
@ -152,6 +159,21 @@ class WC_Rest_Settings_Controller extends WC_REST_Settings_API_Controller {
);
}
/**
* Makes sure the current user has access to READ the settings APIs.
*
* @since 2.7.0
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
/**
* Get the groups schema, conforming to JSON Schema.
*