Jake Vanderwerf
2026-02-04 2127b1bdd73ecd2423e443992da4b442f5a3c1a3
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
 
use JVBase\managers\Cache;
use JVBase\utility\Features;
 
if (!defined('ABSPATH')) {
    exit;
}
function jvbCheck(string $key, $config = [])
{
    return (array_key_exists($key, $config) && $config[$key] === true);
}
/**
 * Tests whether this site needs forum functionality
 * @return bool
 */
function jvbSiteHasForum():bool
{
    return jvbCheck('forum', JVB_MEMBERSHIP);
}
 
function jvbSiteUsesSquare():bool
{
    return jvbSiteHasIntegrations() && jvbCheck('square', JVB_SITE['integrations']);
}
function jvbSiteUsesGoogleBusiness():bool
{
    return jvbSiteUsesGMB();
}
 
function jvbSiteHasFavourites():bool
{
    return jvbCheck('favourites', JVB_SITE);
}
 
/**
 * Tests whether this site has a custom dashboard
 * @return bool
 */
function jvbSiteHasDashboard():bool
{
    return jvbCheck('dashboard', JVB_SITE);
}
 
function jvbSiteHasKarma():bool
{
    global $jvb_karma;
    return (!empty($jvb_karma['content']) || !empty($jvb_karma['taxonomy']));
}
 
function jvbSiteHasSupport():bool
{
    return  jvbCheck('has_support', JVB_SITE);
}
 
function jvbSiteHasInvitations():bool
{
    return jvbCheck('can_invite', JVB_MEMBERSHIP);
}
 
function jvbSiteHasMemberApproval():bool
{
    return jvbCheck('member_verified', JVB_MEMBERSHIP);
}
 
function jvbSiteHasMembership():bool
{
    return jvbCheck('has_membership', JVB_SITE);
}
 
function jvbSiteHasResponse():bool
{
    global $jvb_responses;
    return (!empty($jvb_responses['content']) || !empty($jvb_responses['taxonomy']));
}
 
function jvbSiteUsesFeedBlock():bool
{
    return jvbCheck('use_feed_block', JVB_SITE);
}
 
function jvbSiteCanFavourite():bool
{
    return jvbCheck('enthusiast', JVB_SITE) && jvbCheck('favourites', JVB_SITE);
}
 
function jvbSiteUsesUmami():bool
{
    return jvbSiteHasIntegrations() && jvbCheck('umami', JVB_SITE['integrations']);
}
function jvbSiteUsesCloudflare():bool
{
    return jvbSiteHasIntegrations() && jvbCheck('cloudflare', JVB_SITE['integrations']);
}
 
function jvbSiteUsesFacebook():bool
{
    return jvbSiteHasIntegrations() && jvbCheck('facebook', JVB_SITE['integrations']);
}
function jvbSiteUsesInstagram():bool
{
    return jvbSiteHasIntegrations() && jvbCheck('instagram', JVB_SITE['integrations']);
}
function jvbSiteUsesBluesky():bool
{
    return jvbSiteHasIntegrations() && jvbCheck('bluesky', JVB_SITE['integrations']);
}
function jvbSiteUsesGMB():bool
{
    return jvbSiteHasIntegrations() && jvbCheck('gmb', JVB_SITE['integrations']);
}
function jvbSiteUsesHelcim():bool
{
    return jvbSiteHasIntegrations() && jvbCheck('helcim', JVB_SITE['integrations']);
}
 
function jvbSiteUses(string $key):bool
{
    return jvbCheck($key, JVB_SITE);
}
 
function jvbSiteUsesMaps():bool
{
    return true;
}
 
function jvbSiteHasTermContent():bool
{
    return (!empty(array_keys(array_filter(JVB_TAXONOMY, function ($taxonomy) {
        return jvbCheck('is_content', $taxonomy);
    }))));
}
 
function jvbSiteHasNotifications():bool
{
    return jvbCheck('notifications', JVB_MEMBERSHIP);
}
 
function jvbUserCanCreate(int $userID = 0):bool
{
    $user = ($userID === 0) ? wp_get_current_user() : get_userdata($userID);
    $roles = array_intersect(
        jvbRolesWithDashboard(),
        array_map(function ($role) {
            return jvbNoBase($role);
        },
            $user->roles)
    );
    $creatable = [];
    foreach ($roles as $role) {
        $creatable = array_merge($creatable, JVB_USER[$role]['can_create']??[]);
    }
 
    $creatable = jvbExtractUserContent($creatable);
    return !empty($creatable);
}
 
function jvbRolesWithDashboard():array
{
    return array_keys(array_filter(JVB_USER, function ($role) {
        return jvbCheck('has_dashboard', $role);
    }));
}
 
function jvbSiteHasTermApproval():bool
{
    return jvbCheck('terms_approval', JVB_MEMBERSHIP);
}
 
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 isJVBUserType():bool
{
    return (is_singular(jvbUserTypes()) || is_post_type_archive(jvbUserTypes()));
}
 
function contentIsJVBUserType(string $content):bool
{
    $content = jvbCheckBase($content);
    return in_array($content, jvbUserTypes());
}
 
 
function isJVBContentTax():bool
{
    return is_tax(jvbContentTaxonomies());
}
 
function taxIsJVBContentTax($tax):bool
{
    $tax = jvbCheckBase($tax);
    return in_array($tax, jvbContentTaxonomies());
}
 
function jvbSiteHasIntegrations():bool
{
    return array_key_exists('integrations', JVB_SITE) && !empty(JVB_SITE['integrations']);
}
 
 
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 jvbIsValidType(string $type):bool {
 
    return (array_key_exists($type, JVB_CONTENT) ||
        array_key_exists($type, JVB_TAXONOMY) ||
        array_key_exists($type, JVB_USER) ||
        $type === 'options');
}
 
function jvbGetObjectType(string $type):string {
    if (array_key_exists($type, JVB_CONTENT)) {
        return 'post';
    } elseif (array_key_exists($type, JVB_TAXONOMY)) {
        return 'term';
    } elseif (array_key_exists($type, JVB_USER)) {
        return 'user';
    } elseif ($type === 'options') {
        return 'options';
    }
    return '';
}
 
 
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;
        }
    );
}