diff --git a/assets/css/admin.css b/assets/css/admin.css index 3fb47930b..ac33cec31 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -978,7 +978,7 @@ button.prpl-info-icon { /*------------------------------------*\ Dashboard widget styles. \*------------------------------------*/ -#progress_planner_dashboard_widget_score .prpl-dashboard-widget { +#progress_planner_dashboard_widget_score .prpl-dashboard-widget.show-badges { display: grid; grid-template-columns: 1fr 1px 140px; grid-gap: calc(var(--prpl-gap) / 2); diff --git a/classes/admin/class-dashboard-widget-score.php b/classes/admin/class-dashboard-widget-score.php index 23f02c691..8efd51340 100644 --- a/classes/admin/class-dashboard-widget-score.php +++ b/classes/admin/class-dashboard-widget-score.php @@ -39,19 +39,24 @@ protected function get_title() { */ public function render_widget() { Page::enqueue_styles(); + + $show_badges = ( + $this->get_badge_details( 'content' )['progress']['progress'] || + $this->get_badge_details( 'streak' )['progress']['progress'] + ); ?> -
+
' . \esc_html__( 'Website activity score', 'progress-planner' ) . '

' ); ?>
- -
- -
-

- the_badge( 'content' ); ?> - the_badge( 'streak' ); ?> -
+ +
+
+

+ the_badge( 'content' ); ?> + the_badge( 'streak' ); ?> +
+
@@ -121,6 +126,9 @@ public function render_widget() { */ protected function the_badge( $category = 'content' ) { $details = $this->get_badge_details( $category ); + if ( 100 <= (int) $details['progress']['progress'] ) { + return; + } ?>
@@ -152,6 +160,15 @@ class="prpl-badge-gauge" * @return array */ public function get_badge_details( $category = 'content' ) { + $cached = [ + 'content' => false, + 'streak' => false, + ]; + + if ( $cached[ $category ] ) { + return $cached[ $category ]; + } + $result = []; $badges = [ 'content' => [ 'wonderful-writer', 'bold-blogger', 'awesome-author' ], @@ -175,6 +192,9 @@ public function get_badge_details( $category = 'content' ) { if ( $result['progress']['progress'] > 75 ) { $result['color'] = 'var(--prpl-color-accent-green)'; } + + $cached[ $category ] = $result; + return $result; } }