[API] dont count coupons if the user dont have permissions
This commit is contained in:
parent
678f5e67a0
commit
a74efe61a9
|
@ -156,14 +156,13 @@ class WC_API_Coupons extends WC_API_Resource {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_coupons_count( $filter = array() ) {
|
public function get_coupons_count( $filter = array() ) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$query = $this->query_coupons( $filter );
|
|
||||||
|
|
||||||
if ( ! current_user_can( 'read_private_shop_coupons' ) ) {
|
if ( ! current_user_can( 'read_private_shop_coupons' ) ) {
|
||||||
throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_coupons_count', __( 'You do not have permission to read the coupons count', 'woocommerce' ), 401 );
|
throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_coupons_count', __( 'You do not have permission to read the coupons count', 'woocommerce' ), 401 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$query = $this->query_coupons( $filter );
|
||||||
|
|
||||||
return array( 'count' => (int) $query->found_posts );
|
return array( 'count' => (int) $query->found_posts );
|
||||||
} catch ( WC_API_Exception $e ) {
|
} catch ( WC_API_Exception $e ) {
|
||||||
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
|
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
|
||||||
|
|
Loading…
Reference in New Issue