Add permissions for count endpoints

This commit is contained in:
Max Rice 2013-11-23 17:11:16 -05:00
parent 2af47c6699
commit 017e7cee1d
4 changed files with 7 additions and 4 deletions

View File

@ -148,7 +148,8 @@ class WC_API_Coupons extends WC_API_Resource {
$query = $this->query_coupons( $filter );
// TODO: permissions?
if ( ! current_user_can( 'read_private_shop_coupons' ) )
return new WP_Error( 'woocommerce_api_user_cannot_read_coupons_count', __( 'You do not have permission to read the coupons count', 'woocommerce' ), array( 'status' => 401 ) );
return array( 'count' => (int) $query->found_posts );
}

View File

@ -189,7 +189,7 @@ class WC_API_Customers extends WC_API_Resource {
$query = $this->query_customers( $filter );
if ( ! current_user_can( 'list_users' ) )
return new WP_Error( 'woocommerce_api_user_cannot_read_customer', __( 'You do not have permission to read customers', 'woocommerce' ), array( 'status' => 401 ) );
return new WP_Error( 'woocommerce_api_user_cannot_read_customers_count', __( 'You do not have permission to read the customers count', 'woocommerce' ), array( 'status' => 401 ) );
return array( 'count' => count( $query->get_results() ) );
}

View File

@ -249,7 +249,8 @@ class WC_API_Orders extends WC_API_Resource {
$query = $this->query_orders( $filter );
// TODO: permissions?
if ( ! current_user_can( 'read_private_shop_orders' ) )
return new WP_Error( 'woocommerce_api_user_cannot_read_orders_count', __( 'You do not have permission to read the orders count', 'woocommerce' ), array( 'status' => 401 ) );
return array( 'count' => (int) $query->found_posts );
}

View File

@ -136,7 +136,8 @@ class WC_API_Products extends WC_API_Resource {
if ( ! empty( $type ) )
$filter['type'] = $type;
// TODO: permissions?
if ( ! current_user_can( 'read_private_products' ) )
return new WP_Error( 'woocommerce_api_user_cannot_read_products_count', __( 'You do not have permission to read the products count', 'woocommerce' ), array( 'status' => 401 ) );
$query = $this->query_products( $filter );