Skip to content

Commit cf5a14c

Browse files
authored
Merge pull request #228 from cloudinary/fix/payg-dashboard
Fix PAYG accounts dashboard
2 parents 09de44d + 75840e8 commit cf5a14c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-connect.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,11 @@ public function get_usage_stat( $type, $stat = null ) {
543543

544544
if ( 'limit' === $stat && isset( $this->usage[ $type ]['usage'] ) ) {
545545
$value = $this->usage[ $type ]['usage'];
546-
} elseif ( 'used_percent' === $stat && isset( $this->usage[ $type ]['credits_usage'] ) ) {
546+
} elseif (
547+
'used_percent' === $stat
548+
&& isset( $this->usage[ $type ]['credits_usage'] )
549+
&& ! empty( $this->usage['credits']['limit'] )
550+
) {
547551
// Calculate percentage based on credit limit and usage.
548552
$value = round( $this->usage[ $type ]['credits_usage'] / $this->usage['credits']['limit'] * 100, 2 );
549553
}

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/ui-definitions/tabs/dashboard-content.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,29 @@
5050
<?php if ( false !== $connection->get_usage_stat( 'credits', 'limit' ) ) : ?>
5151
<span class="cloudinary-stat" title="<?php esc_attr_e( 'Credits', 'cloudinary' ); ?>">
5252
<span class="dashicons dashicons-marker"></span> <?php esc_html_e( number_format_i18n( $connection->get_usage_stat( 'credits', 'limit' ) ) ); ?>
53-
<span class="cloudinary-percent"> <?php esc_html_e( $connection->get_usage_stat( 'credits', 'used_percent' ) . '%' ); ?></span> |
53+
<?php if ( false !== $connection->get_usage_stat( 'credits', 'used_percent' ) ) : ?>
54+
<span class="cloudinary-percent"> <?php esc_html_e( $connection->get_usage_stat( 'credits', 'used_percent' ) . '%' ); ?></span> |
55+
<?php endif; ?>
5456
</span>
5557
<?php endif; ?>
5658

5759
<span class="cloudinary-stat" title="<?php esc_attr_e( 'Storage', 'cloudinary' ); ?>">
5860
<span class="dashicons dashicons-cloud"></span> <?php esc_html_e( size_format( $connection->get_usage_stat( 'storage', 'limit' ) ) ); ?>
59-
<span class="cloudinary-percent"> <?php esc_html_e( $connection->get_usage_stat( 'storage', 'used_percent' ) . '%' ); ?></span> |
61+
<?php if ( false !== $connection->get_usage_stat( 'storage', 'used_percent' ) ) : ?>
62+
<span class="cloudinary-percent"> <?php esc_html_e( $connection->get_usage_stat( 'storage', 'used_percent' ) . '%' ); ?></span> |
63+
<?php endif; ?>
6064
</span>
6165
<span class="cloudinary-stat" title="<?php esc_attr_e( 'Transformations', 'cloudinary' ); ?>">
6266
<span class="dashicons dashicons-image-filter"></span> <?php esc_html_e( number_format_i18n( $connection->get_usage_stat( 'transformations', 'limit' ) ) ); ?>
63-
<span class="cloudinary-percent success"> <?php esc_html_e( $connection->get_usage_stat( 'transformations', 'used_percent' ) . '%' ); ?></span> |
67+
<?php if ( false !== $connection->get_usage_stat( 'transformations', 'used_percent' ) ) : ?>
68+
<span class="cloudinary-percent success"> <?php esc_html_e( $connection->get_usage_stat( 'transformations', 'used_percent' ) . '%' ); ?></span> |
69+
<?php endif; ?>
6470
</span>
6571
<span class="cloudinary-stat" title="<?php esc_attr_e( 'Bandwidth', 'cloudinary' ); ?>">
6672
<span class="dashicons dashicons-dashboard"></span> <?php esc_html_e( size_format( $connection->get_usage_stat( 'bandwidth', 'limit' ) ) ); ?>
67-
<span class="cloudinary-percent success"> <?php esc_html_e( $connection->get_usage_stat( 'bandwidth', 'used_percent' ) . '%' ); ?></span>
73+
<?php if ( false !== $connection->get_usage_stat( 'bandwidth', 'used_percent' ) ) : ?>
74+
<span class="cloudinary-percent success"> <?php esc_html_e( $connection->get_usage_stat( 'bandwidth', 'used_percent' ) . '%' ); ?></span>
75+
<?php endif; ?>
6876
</span>
6977
</div>
7078
<hr>

0 commit comments

Comments
 (0)