From 6b329b5159ec40a9fc37ecaa7a126d64f88fbe8f Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 7 Oct 2020 14:20:09 +0100 Subject: [PATCH 1/2] Make sure that key is set before using it --- .../php/class-connect.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php index fa89fc83e..99d8fb65f 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php @@ -543,7 +543,11 @@ public function get_usage_stat( $type, $stat = null ) { if ( 'limit' === $stat && isset( $this->usage[ $type ]['usage'] ) ) { $value = $this->usage[ $type ]['usage']; - } elseif ( 'used_percent' === $stat && isset( $this->usage[ $type ]['credits_usage'] ) ) { + } elseif ( + 'used_percent' === $stat + && isset( $this->usage[ $type ]['credits_usage'] ) + && ! empty( $this->usage['credits']['limit'] ) + ) { // Calculate percentage based on credit limit and usage. $value = round( $this->usage[ $type ]['credits_usage'] / $this->usage['credits']['limit'] * 100, 2 ); } From 75840e85f00635252f766bf02bed897a86a6b029 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 7 Oct 2020 14:20:56 +0100 Subject: [PATCH 2/2] Make sure that there is a value for stat before using it --- .../ui-definitions/tabs/dashboard-content.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php index 08bc3313b..ddbbf25bd 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php @@ -50,21 +50,29 @@ get_usage_stat( 'credits', 'limit' ) ) : ?> get_usage_stat( 'credits', 'limit' ) ) ); ?> - get_usage_stat( 'credits', 'used_percent' ) . '%' ); ?> | + get_usage_stat( 'credits', 'used_percent' ) ) : ?> + get_usage_stat( 'credits', 'used_percent' ) . '%' ); ?> | + get_usage_stat( 'storage', 'limit' ) ) ); ?> - get_usage_stat( 'storage', 'used_percent' ) . '%' ); ?> | + get_usage_stat( 'storage', 'used_percent' ) ) : ?> + get_usage_stat( 'storage', 'used_percent' ) . '%' ); ?> | + get_usage_stat( 'transformations', 'limit' ) ) ); ?> - get_usage_stat( 'transformations', 'used_percent' ) . '%' ); ?> | + get_usage_stat( 'transformations', 'used_percent' ) ) : ?> + get_usage_stat( 'transformations', 'used_percent' ) . '%' ); ?> | + get_usage_stat( 'bandwidth', 'limit' ) ) ); ?> - get_usage_stat( 'bandwidth', 'used_percent' ) . '%' ); ?> + get_usage_stat( 'bandwidth', 'used_percent' ) ) : ?> + get_usage_stat( 'bandwidth', 'used_percent' ) . '%' ); ?> +