Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip rendering badges that are complete #46

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions classes/badges/class-badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public function register_badge() {
);
}

/**
* Get the badge ID.
*
* @return string
*/
public function get_id() {
return $this->id;
}

/**
* Get the badge name.
*
Expand Down
3 changes: 3 additions & 0 deletions classes/class-badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Badges {
* @return void
*/
public static function register_badge( $badge_id, $args ) {
if ( ! isset( $args['id'] ) ) {
$args['id'] = $badge_id;
}
self::$badges[ $badge_id ] = $args;
}

Expand Down
15 changes: 14 additions & 1 deletion classes/widgets/class-badge-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ final class Badge_Content extends Widget {
*/
protected $id = 'badge-content';

/**
* Whether we should render the widget or not.
*
* @return bool
*/
protected function should_render() {
$details = $this->get_badge_details();
return ( 100 > (int) $details['progress']['progress'] );
}

/**
* Render the widget content.
*
Expand Down Expand Up @@ -78,7 +88,10 @@ class="prpl-badge-gauge"
* @return array
*/
public function get_badge_details() {
$result = [];
static $result = [];
if ( ! empty( $result ) ) {
return $result;
}
$badges = [ 'wonderful-writer', 'bold-blogger', 'awesome-author' ];

// Get the badge to display.
Expand Down
15 changes: 14 additions & 1 deletion classes/widgets/class-badge-streak.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ final class Badge_Streak extends Widget {
*/
protected $id = 'badge-streak';

/**
* Whether we should render the widget or not.
*
* @return bool
*/
protected function should_render() {
$details = $this->get_badge_details();
return ( 100 > (int) $details['progress']['progress'] );
}

/**
* Render the widget content.
*
Expand Down Expand Up @@ -79,7 +89,10 @@ class="prpl-badge-gauge"
* @return array
*/
public function get_badge_details() {
$result = [];
static $result = [];
if ( ! empty( $result ) ) {
return $result;
}
$badges = [
'progress-padawan',
'maintenance-maniac',
Expand Down
12 changes: 12 additions & 0 deletions classes/widgets/class-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,23 @@ public function get_frequency() {
* @return void
*/
protected function render() {
if ( ! $this->should_render() ) {
return;
}
echo '<div class="prpl-widget-wrapper prpl-' . \esc_attr( $this->id ) . '">';
$this->the_content();
echo '</div>';
}

/**
* Whether we should render the widget or not.
*
* @return bool
*/
protected function should_render() {
return true;
}

/**
* Render a big counter.
*
Expand Down
Loading