From 0a7076744e90f929f7de4a14544ed56b5bb6a403 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 23 Mar 2017 19:52:35 -0300 Subject: [PATCH] [REST API] Fixed settings/options rest_base --- ...ass-wc-rest-setting-options-controller.php | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/includes/api/class-wc-rest-setting-options-controller.php b/includes/api/class-wc-rest-setting-options-controller.php index 96fd48b7bbe..9b4915c384c 100644 --- a/includes/api/class-wc-rest-setting-options-controller.php +++ b/includes/api/class-wc-rest-setting-options-controller.php @@ -1,6 +1,6 @@ [\w-]+)'; /** * Register routes. @@ -40,7 +40,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller { * @since 3.0.0 */ public function register_routes() { - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( + register_rest_route( $this->namespace, '/' . $this->rest_base, array( 'args' => array( 'group' => array( 'description' => __( 'Settings group ID.', 'woocommerce' ), @@ -55,23 +55,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller { 'schema' => array( $this, 'get_public_item_schema' ), ) ); - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)/batch', array( - 'args' => array( - 'group' => array( - 'description' => __( 'Settings group ID.', 'woocommerce' ), - 'type' => 'string', - ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'batch_items' ), - 'permission_callback' => array( $this, 'update_items_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - 'schema' => array( $this, 'get_public_batch_schema' ), - ) ); - - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)/(?P[\w-]+)', array( + register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( 'args' => array( 'group' => array( 'description' => __( 'Settings group ID.', 'woocommerce' ), @@ -95,6 +79,22 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller { ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); + + register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( + 'args' => array( + 'group' => array( + 'description' => __( 'Settings group ID.', 'woocommerce' ), + 'type' => 'string', + ), + ), + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'batch_items' ), + 'permission_callback' => array( $this, 'update_items_permissions_check' ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), + ), + 'schema' => array( $this, 'get_public_batch_schema' ), + ) ); } /** @@ -316,13 +316,13 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller { * @return array Links for the given setting. */ protected function prepare_links( $setting_id, $group_id ) { - $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $group_id; + $base = str_replace( '(?P[\w-]+)', $group_id, $this->rest_base ); $links = array( 'self' => array( - 'href' => rest_url( trailingslashit( $base ) . $setting_id ), + 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ), ), 'collection' => array( - 'href' => rest_url( $base ), + 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), ), );