Jake Vanderwerf
2026-03-29 9f672be1f7bb5f8462374ca4732d095d4f24685b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
 
use JVBase\managers\Cache;
use JVBase\registrar\Registrar;
use JVBase\utility\Features;
 
if (!defined('ABSPATH')) {
    exit;
}
function jvbCheck(string $key, $config = []):bool
{
    return (array_key_exists($key, $config) && $config[$key] === true);
}
 
function jvbUserIsVerified():bool
{
    return !(Features::forMembership()->has('member_verified')) || current_user_can('skip_moderation');
}
 
function jvbUserTypes():array
{
    $types = get_option(BASE.'user_types');
    if (JVB_TESTING) {
        $types = false;
    }
    if ($types === false) {
        $types = [];
        foreach (JVB_USER as $type => $config) {
            if (array_key_exists('profile', $config)) {
                $types[$type] = BASE.$config['profile'];
            }
        }
        update_option(BASE.'user_types', $types);
    }
    return $types;
}
 
function isJVBContentTax():bool
{
    return is_tax(array_map(function ($tax) {
        return jvbCheckBase($tax);
    }, Registrar::getFeatured('is_content', 'term')));
}
 
function taxIsJVBContentTax($tax):bool
{
    $allowed = Registrar::getFeatured('is_content', 'term');
    $tax = jvbNoBase($tax);
    return in_array($tax, $allowed);
}
 
function jvbIsOpen():bool
{
 
    if (!jvbCheck('limit_hours', JVB_SITE)) {
        return true;
    }
    if (get_option(BASE.'open_to_public') !== '1') {
        return false;
    }
    //Check if today_hours is set
    if (get_option(BASE.'today_hours')) {
        return jvbIsTimeBetween();
    }
    //Default to the stored settings
    return jvbIsCurrentlyOpen();
}
 
 
function jvbTermHasPosts(int $termID, string $taxonomy):bool
{
    $cache = Cache::for('termUtility', 30*60)->connect('taxonomy');
    return $cache->remember(
        $termID,
        function() use($taxonomy, $termID) {
            $taxonomy = jvbCheckBase($taxonomy);
            $tax = get_taxonomy($taxonomy);
            $query = new WP_Query([
                'post_type' => $tax->object_type,
                'posts_per_page' => 1,
                'fields' => 'ids',
                'tax_query' => [
                    [
                        'taxonomy' => $taxonomy,
                        'terms' => $termID
                    ]
                ]
            ]);
            $result = ($query->have_posts()) ? 'true' : 'false';
            wp_reset_postdata();
            return $result;
        }
    );
}