ID arg definitions

This commit is contained in:
Mike Jolley 2017-01-26 19:22:57 +00:00
parent def35a5aa2
commit 2d23705431
18 changed files with 147 additions and 17 deletions

View File

@ -353,16 +353,25 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
'description' => __( 'List of created resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'object',
),
),
'update' => array(
'description' => __( 'List of updated resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'object',
),
),
'delete' => array(
'description' => __( 'List of delete resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'object',
),
),
),
);

View File

@ -75,6 +75,12 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -67,6 +67,12 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -68,6 +68,12 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -80,6 +80,12 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -77,6 +77,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -48,6 +48,12 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -68,6 +68,12 @@ class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
));
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -67,6 +67,12 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -71,6 +71,12 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -72,6 +72,12 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -94,8 +100,8 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
'force' => array(
'default' => false,
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
'type' => 'boolean',
),
'reassign' => array(),
),
),
'schema' => array( $this, 'get_public_item_schema' ),

View File

@ -53,6 +53,12 @@ class WC_REST_Settings_Options_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<group>[\w-]+)/(?P<id>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -48,6 +48,12 @@ class WC_REST_Shipping_Methods_Controller extends WC_REST_Controller {
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -282,6 +282,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'Database tables', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
),
),
@ -289,6 +292,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'Active plugins', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
'theme' => array(
'description' => __( 'Theme', 'woocommerce' ),
@ -340,6 +346,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'Template overrides', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
'parent_name' => array(
'description' => __( 'Parent theme name', 'woocommerce' ),
@ -413,6 +422,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'Taxonomy terms for product/order statuses', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
),
),
@ -437,6 +449,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'WooCommerce pages', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
),
);

View File

@ -38,17 +38,23 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
* Register the routes for /system_status/tools/*.
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -64,15 +70,15 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
) );
}
/**
/**
* Check whether a given request has permission to view system status tools.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) {
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) {
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
@ -122,10 +128,10 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
'desc' => __( 'This tool will clear ALL expired transients from WordPress.', 'woocommerce' ),
),
'delete_orphaned_variations' => array(
'name' => __( 'Orphaned variations', 'woocommerce' ),
'button' => __( 'Delete orphaned variations', 'woocommerce' ),
'desc' => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ),
),
'name' => __( 'Orphaned variations', 'woocommerce' ),
'button' => __( 'Delete orphaned variations', 'woocommerce' ),
'desc' => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ),
),
'recount_terms' => array(
'name' => __( 'Term counts', 'woocommerce' ),
'button' => __( 'Recount terms', 'woocommerce' ),
@ -173,7 +179,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
return apply_filters( 'woocommerce_debug_tools', $tools );
}
/**
/**
* Get a list of system status tools.
*
* @param WP_REST_Request $request Full details about the request.
@ -260,7 +266,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
return $response;
}
/**
/**
* Get the system status tools schema, conforming to JSON Schema.
*
* @return array
@ -393,8 +399,8 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
break;
case 'delete_orphaned_variations' :
/**
* Delete orphans
*/
* Delete orphans
*/
$result = absint( $wpdb->query( "DELETE products
FROM {$wpdb->posts} products
LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent

View File

@ -57,6 +57,12 @@ class WC_REST_Taxes_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -51,6 +51,12 @@ class WC_REST_Webhook_Deliveries_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -67,13 +67,19 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'topic' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Webhook topic.', 'woocommerce' ),
),
'delivery_url' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Webhook delivery URL.', 'woocommerce' ),
),
'secret' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Webhook secret.', 'woocommerce' ),
),
) ),
),
@ -81,6 +87,12 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -102,6 +114,7 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),
@ -514,6 +527,9 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'readonly' => true,
'items' => array(
'type' => 'string',
),
),
'delivery_url' => array(
'description' => __( 'The URL where the webhook payload is delivered.', 'woocommerce' ),