Jake Vanderwerf
2026-02-04 2127b1bdd73ecd2423e443992da4b442f5a3c1a3
inc/helpers/formatting.php
@@ -1,6 +1,7 @@
<?php
use JVBase\managers\Cache;
use JVBase\meta\Meta;
use JVBase\utility\Image;
if (!defined('ABSPATH')) {
@@ -68,11 +69,10 @@
/**
 * @param int $ID
 * @param JVBase\meta\MetaManager|null $meta
 *
 * @param string $type 'post', 'user', or 'term'
 * @return string
 */
function jvbFormatRating(int $ID, JVBase\meta\MetaManager|null $meta = null):string
function jvbFormatRating(int $ID, string $type = 'post'):string
{
    $cache = Cache::for('rating', WEEK_IN_SECONDS)->connect('post')->connect('taxonomy')->connect('user');
@@ -81,21 +81,21 @@
        return $cached;
    }
    if (!$meta) {
        if (term_exists((int)$ID)) {
            $type = 'term';
        } elseif (get_post_status((int)$ID)) {
            $type = 'post';
        } else {
            $type = 'user';
        }
        $meta = new JVBase\meta\MetaManager($ID, $type);
    }
   $meta = match ($type) {
      'term' => Meta::forTerm($ID),
      'post'   => Meta::forPost($ID),
      'user'   => Meta::forUser($ID),
      default => false
   };
   if (!$type) {
      return '';
   }
    $out = '';
    $avg = $meta->getValue('average_rating');
    $avg = $meta->get('average_rating');
    $total = $meta->getValue('total_ratings');
    $total = $meta->get('total_ratings');
    if ($avg !== 'none') {
        $out .= jvbFormatStarRating($avg, (int)$total);
    }