| | |
| | | <?php |
| | | |
| | | use JVBase\registrar\Registrar; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | | } |
| | | |
| | | |
| | | function jvbGetTermOwners(int $termID, bool $includeManagers = true):array |
| | | { |
| | | $owners = get_term_meta($termID, BASE.'owners', true); |
| | | $owners = empty($owners) ? [] : $owners; |
| | | if ($includeManagers) { |
| | | $managers = get_term_meta($termID, BASE.'managers', true); |
| | | $managers = empty($managers) ? [] : $managers; |
| | | $owners = array_merge($owners, $managers); |
| | | } |
| | | return $owners; |
| | | |
| | | } |
| | | /** |
| | | * @param string $term |
| | | * @param int|false $ID |
| | |
| | | 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 |
| | | { |
| | | if (jvbNoSaveIt($post_id, $post)) { |
| | | return; |
| | | if ($value === '') { |
| | | 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 row left '.jvbNoBase($tax).'">'.$title.implode('',$out).'</ul>' : ''; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param int $artistID |
| | | * @param string $taxonomy |
| | |
| | | if ($users === '') { |
| | | $term = get_term($termID); |
| | | $taxonomy = $term->taxonomy; |
| | | if (taxIsJVBContentTax($taxonomy)) { |
| | | $registrar = Registrar::getInstance($taxonomy); |
| | | if ($registrar->hasFeature('is_content')) { |
| | | $posts = new WP_Query([ |
| | | 'post_type' => jvbCheckBase($user), |
| | | 'posts_per_page' => -1, |