<?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
|
* @param string $classes
|
*
|
* @return string
|
*/
|
function jvbGetTheTerms(string $term, int|false $ID = false, string $classes = ''):string
|
{
|
$taxonomy = jvbCheckBase($term);
|
if (!taxonomy_exists($taxonomy)) {
|
return '';
|
}
|
if (!str_starts_with($classes, ' ')) {
|
$classes = ' '.$classes;
|
}
|
|
if (!$ID) {
|
$ID = get_the_ID();
|
}
|
|
$classes .= $term;
|
|
$terms = get_the_terms($ID, $taxonomy);
|
$out = '';
|
if ($terms && !is_wp_error($terms)) {
|
$out = '<ul class="'.trim('term-list '.$classes).'">';
|
foreach ($terms as $t) {
|
$url = get_term_link($t->term_id, BASE.$term);
|
$out .= '<li><a href="'.$url.'" title="View more in '.$t->name.'" rel="tag">'.$t->name.'</a></li>';
|
}
|
$out .= '</ul>';
|
}
|
|
return $out;
|
}
|
|
function jvbMetaTermList(string $value, string $tax, bool $icon = true):string
|
{
|
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>';
|
}
|
}
|
|
$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
|
*
|
* @return array
|
*/
|
function jvbGetArtistTerm(int $artistID, string $taxonomy):array
|
{
|
$taxonomy = (str_starts_with($taxonomy, BASE)) ? $taxonomy : BASE.$taxonomy;
|
$terms = get_the_terms($artistID, $taxonomy);
|
if ($terms && !is_wp_error($terms)) {
|
$ID = $terms[0]->term_id;
|
$name = $terms[0]->name;
|
return [
|
'id' => $ID,
|
'name' => $name,
|
'url' => get_term_link($ID, $taxonomy)
|
];
|
}
|
return [];
|
}
|
|
/**
|
* Gets the artist type taxonomy name
|
* @param int $ID
|
*
|
* @return string
|
*/
|
function jvbArtistType(int $ID):string
|
{
|
$types = get_the_terms($ID, BASE.'type');
|
$type = '';
|
if ($types && !is_wp_error($types)) {
|
$type = $types[0]->term_id;
|
$type = get_term_meta($type, BASE.'singular', true);
|
}
|
|
return ($type == '') ? 'Tattoo Artist' : $type;
|
}
|
|
/**
|
* Gets the first name of city listed
|
* @param int $ID
|
*
|
* @return string
|
*/
|
function jvbArtistCity(int $ID):string
|
{
|
$cities = get_the_terms($ID, 'jvb_city');
|
if ($cities && !is_wp_error($cities)) {
|
return $cities[0]->name;
|
}
|
return 'Edmonton';
|
}
|
|
|
function jvbGetContentUsers(int $termID, $user = BASE.'artist'):array
|
{
|
$users = get_term_meta($termID, BASE.'users', true);
|
if ($users === '') {
|
$term = get_term($termID);
|
$taxonomy = $term->taxonomy;
|
$registrar = Registrar::getInstance($taxonomy);
|
if ($registrar->hasFeature('is_content')) {
|
$posts = new WP_Query([
|
'post_type' => jvbCheckBase($user),
|
'posts_per_page' => -1,
|
'tax_query' => [
|
[
|
'taxonomy' => $taxonomy,
|
'terms' => $term
|
]
|
]
|
]);
|
if (!empty($posts->posts)) {
|
$users = array_map(
|
function ($post) {
|
return $post->post_author;
|
},
|
$posts->posts
|
);
|
}
|
$users = implode(',', $users);
|
update_post_meta($termID, BASE.'users', $users);
|
}
|
}
|
return explode(',', $users);
|
}
|