Jake Vanderwerf
2026-03-29 9f672be1f7bb5f8462374ca4732d095d4f24685b
inc/helpers/terms.php
@@ -1,5 +1,7 @@
<?php
use JVBase\registrar\Registrar;
if (!defined('ABSPATH')) {
   exit;
}
@@ -41,69 +43,29 @@
    return $out;
}
/**
 * Clear taxonomy list caches when terms are saved
 * @param int $term_id
 * @param int $tt_id
 * @param string $taxonomy
 *
 * @return void
 */
add_action('edited_term', 'jvbClearTermListCache', 10, 3);
add_action('created_term', 'jvbClearTermListCache', 10, 3);
add_action('delete_term', 'jvbClearTermListCache', 10, 3);
function jvbClearTermListCache(int $term_id, int $tt_id, string $taxonomy):void
function jvbMetaTermList(string $value, string $tax, bool $icon = true):string
{
    // Check if this taxonomy has a corresponding list
    $types = jvbGlobalDirectoryInfo();
    foreach ($types as $type) {
        if ($type['slug'] === $taxonomy) {
            // Delete the option to force regeneration
            delete_option(BASE . $type['slug'] . '_list');
            break;
        }
    }
    // If this is a city and it's linked to other taxonomies, clear those too
    if ($taxonomy === BASE.'city') {
        foreach ($types as $type) {
            if (!empty($type['links']) && in_array(BASE.'_city', $type['links'])) {
                delete_option(BASE . $type['slug'] . '_list');
            }
        }
    }
}
/**
 * Clear list caches when post types are saved
 */
add_action('save_post', 'jvbClearListCache', 10, 2);
function jvbClearListCache(int $post_id, \WP_Post $post):void
{
   // SAFETY: Skip attachments and other non-content post types
   if (in_array($post->post_type, jvbIgnoredPostTypes())) {
      return;
   if ($value === '') {
      return '';
   }
   if (jvbNoSaveIt($post_id, $post)) {
      return;
   $tax = jvbCheckBase($tax);
   $terms = array_map('absint', explode(',', $value));
   $out = [];
   foreach ($terms as $t) {
      $term = get_term($t, $tax);
      if ($term && !is_wp_error($term)) {
         $url = get_term_link($t, $tax);
         $out[] = '<li><a href="'.$url.'" title="View more in '.$term->name.'" rel="tag">'.$term->name.'</a></li>';
      }
   }
    // Get post type
    $post_type = get_post_type($post_id);
    // Check if this post type has a corresponding list
    $types = jvbGlobalDirectoryInfo();
    foreach ($types as $type) {
        if ($type['slug'] === $post_type) {
            // Delete the option to force regeneration
            delete_option(BASE . $type['slug'] . '_list');
            break;
        }
    }
   $registrar = Registrar::getInstance($tax);
   $icon = ($icon && $registrar) ? $registrar->getIcon() : '';
   $icon = ($icon === '') ? '' : jvbIcon($icon);
   $title = $registrar ? '<li class="title">'.$icon.$registrar->getSingular().'</li>' : '';
   return (!empty($out)) ? '<ul class="term-list '.jvbNoBase($tax).'">'.$title.implode('',$out).'</ul>' : '';
}
/**
 * @param int $artistID
 * @param string $taxonomy