From 0afb2c0046b55c123eafb4ab9ee77efa68d12463 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sat, 06 Jun 2026 17:15:31 +0000
Subject: [PATCH] =Starting the Favourites.js setup, converting previous Northeh stuff to new Registrar, fixing up Square.php integration to match
---
checks.php | 311 +++++++--------------------------------------------
1 files changed, 43 insertions(+), 268 deletions(-)
diff --git a/checks.php b/checks.php
index 793b586..6b55711 100644
--- a/checks.php
+++ b/checks.php
@@ -1,288 +1,63 @@
<?php
-use JVBase\utility\Features;
+use JVBase\base\Site;
+use JVBase\managers\Cache;
+use JVBase\registrar\Registrar;
if (!defined('ABSPATH')) {
exit;
}
-function jvbCheck(string $key, $config = [])
+function jvbCheck(string $key, $config = []):bool
{
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') :
- true;
-}
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());
+ return Registrar::getFeatured('profile_link', 'user');
}
-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 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 = new \JVBase\managers\CacheManager('termCheck', 60*30);
- $key = $termID.$taxonomy;
- $cached = $cache->get($key);
- if ($cached) {
- return ($cached === 'true');
- }
- $taxonomy = jvbCheckBase($taxonomy);
- $tax = get_taxonomy($taxonomy);
- $query = new WP_Query([
- 'post_type' => $tax->object_type,
- 'posts_per_page' => 1,
- 'fields' => 'id',
- 'tax_query' => [
- [
- 'taxonomy' => $taxonomy,
- 'terms' => $termID
- ]
- ]
- ]);
- $result = ($query->have_posts()) ? 'true': 'false';
- wp_reset_postdata();
- $cache->set($key, $result);
- return $result === 'true';
+ $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;
+ }
+ );
}
--
Gitblit v1.10.0