From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh
---
jvb.php | 1270 ++++++++++++++++++++-------------------------------------
1 files changed, 446 insertions(+), 824 deletions(-)
diff --git a/jvb.php b/jvb.php
index 9e57dd1..6494ea5 100644
--- a/jvb.php
+++ b/jvb.php
@@ -4,65 +4,222 @@
Plugin URI: https://jakevan.ca
Description: The Base Plugin for JakeVan clients
Author: Jake Vanderwerf
-Version: 1.0.0
+Version: 1.1.0
Author URI: https://jakevan.ca/
Textdomain: jvb
*/
-use JVBase\JVB;
-use JVBase\utility\Checker;
-use JVBase\utility\Features;
-
-//security
if (!defined('ABSPATH')) {
- exit;
+ exit; // Exit if accessed directly
+}
+use JVBase\admin\SEOAdmin;
+use JVBase\base\SchemaHelper;
+use JVBase\blocks\CustomBlocks;
+use JVBase\JVB;
+use JVBase\managers\AdminPages;
+use JVBase\managers\Approvals;
+use JVBase\managers\Dashboard\Dashboard;
+use JVBase\managers\DirectoryManager;
+use JVBase\managers\Emails;
+use JVBase\managers\Favourites;
+use JVBase\managers\IconsManager;
+use JVBase\managers\InvitationsManager;
+use JVBase\managers\Login;
+use JVBase\managers\MagicLinks;
+use JVBase\managers\NotificationManager;
+use JVBase\managers\Notifications\Notifications;
+use JVBase\managers\queue\Queue;
+use JVBase\managers\Referrals;
+use JVBase\managers\Responses;
+use JVBase\managers\Roles;
+use JVBase\managers\SEO\render\SchemaOutput;
+use JVBase\managers\TaxonomyRelationships;
+use JVBase\managers\UserTermsManager;
+use JVBase\registrar\Registrar;
+
+use JVBase\base\Site;
+
+//add_action('admin_enqueue_scripts', function() {
+// global $wp_scripts;
+// add_action('admin_print_scripts', function() use ($wp_scripts) {
+// $queue = $wp_scripts->queue ?? [];
+// foreach ($queue as $handle) {
+// $src = $wp_scripts->registered[$handle]->src ?? 'unknown';
+// error_log("Enqueued: $handle => $src");
+// }
+// }, 999);
+//}, 999);
+
+
+/**
+ * Track REST API errors by wrapping request execution
+ */
+add_filter('rest_pre_dispatch', function($result, $server, $request) {
+ // Store request details globally for error logging
+ $GLOBALS['jvb_rest_request'] = [
+ 'route' => $request->get_route(),
+ 'method' => $request->get_method(),
+ 'params' => $request->get_params(),
+ 'time' => microtime(true),
+ ];
+
+ // Set up error handler for this request
+ set_error_handler(function($errno, $errstr, $errfile, $errline) {
+ if (!(error_reporting() & $errno)) {
+ return false;
+ }
+
+ $context = array_merge($GLOBALS['jvb_rest_request'] ?? [], [
+ 'error_type' => $errno,
+ 'error_message' => $errstr,
+ 'file' => $errfile,
+ 'line' => $errline,
+ 'user_id' => get_current_user_id(),
+ ]);
+
+ error_log('JVB REST Error: ' . json_encode($context));
+
+ return false; // Let PHP handle it normally too
+ });
+
+ return $result;
+}, 10, 3);
+
+add_filter('rest_post_dispatch', function($result, $server, $request) {
+ // Restore default error handler
+ restore_error_handler();
+
+ // Check for fatal errors that occurred during request
+ $error = error_get_last();
+ if ($error && in_array($error['type'], [E_ERROR, E_USER_ERROR, E_PARSE, E_COMPILE_ERROR])) {
+ $context = array_merge($GLOBALS['jvb_rest_request'] ?? [], [
+ 'fatal_error' => $error,
+ 'user_id' => get_current_user_id(),
+ ]);
+
+ error_log('JVB REST Fatal: ' . json_encode($context));
+ }
+
+ // Clean up
+ unset($GLOBALS['jvb_rest_request']);
+
+ return $result;
+}, 10, 3);
+
+
+
+function jvbIgnoredPostTypes():array
+{
+ return [BASE.'directory', BASE.'dash', 'attachment', 'revision', 'nav_menu_item'];
}
-const JVB_LOCAL = 'northeh.test';
-add_filter('show_admin_bar', '__return_false');
-const JVB_TESTING = false;
+define('JVB_TESTING', str_contains(get_home_url(),'.test'));
+//const JVB_TESTING = false;
+
+//if (!JVB_TESTING) {
+ add_filter('show_admin_bar', '__return_false');
+//}
+
+//if (JVB_TESTING) {
+// error_log('In testing mode...');
+//} else {
+// error_log('Not in testing mode...');
+//}
const JVB_DIR = WP_PLUGIN_DIR . '/jvb';
define('JVB_URL', plugin_dir_url(__FILE__));
+// Session Security
+define('JVB_SESSION_FINGERPRINT', true);
+
+// Login Security
+define('JVB_MAX_LOGIN_ATTEMPTS', 5);
+define('JVB_LOCKOUT_DURATION', 15 * MINUTE_IN_SECONDS);
+
+
+require(JVB_DIR.'/inc/Instance.php');
require(JVB_DIR.'/base/_setup.php');
-//error_log('###############################################');
-//error_log('Registered Base');
-//error_log('###############################################');
-//error_log('BASE: '.print_r(BASE, true));
-//error_log('JVB_SITE: '.print_r(JVB_SITE, true));
-//error_log('JVB_OPTIONS: '.print_r(JVB_OPTIONS, true));
-//error_log('JVB_CONTENT: '.print_r(JVB_CONTENT, true));
-//error_log('JVB_TAXONOMY: '.print_r(JVB_TAXONOMY, true));
-//error_log('JVB_LOGIN: '.print_r(JVB_LOGIN, true));
-//error_log('JVB_MEMBERSHIP: '.print_r(JVB_MEMBERSHIP, true));
-//error_log('JVB_USER: '.print_r(JVB_USER, true));
-
-if (empty(JVB_SITE)) {
- return;
-}
require(JVB_DIR.'/inc/utility/setup.php');
require(JVB_DIR.'/checks.php');
-require(JVB_DIR.'/globals.php');
-$jvb_feed = jvbGlobalFeedContent();
-$jvb_taxonomy_for= jvbGlobalTaxonomyFor();
-$jvb_responses = jvbGlobalResponses();
-
-global $jvb_everything;
-$jvb_everything = array_merge(JVB_CONTENT, JVB_TAXONOMY);
-
-require(JVB_DIR . '/inc/registry/_setup.php');
-
+require(JVB_DIR . '/inc/integrations/ServiceMap.php');
+require(JVB_DIR . '/inc/registrar/_setup.php');
require(JVB_DIR . '/activate.php');
require(JVB_DIR . '/inc/helpers/all.php');
+require(JVB_DIR . '/inc/ui/_setup.php');
+require(JVB_DIR . '/inc/meta/_setup.php');
+require(JVB_DIR . '/inc/importers/_setup.php');
require(JVB_DIR . '/inc/managers/_setup.php');
+/**
+ * Get an icon element
+ *
+ * @param string $name Icon name
+ * @param array $options Options array:
+ * - 'source' => 'icons'|'dash'|'forms'|etc. (default: 'icons')
+ * - 'style' => 'regular'|'bold'|'fill'|etc.
+ * - 'label' => 'Accessible label'
+ * - 'decorative' => true
+ * - 'class' => 'additional classes'
+ * - 'size' => 24
+ * @return string HTML icon element
+ */
+function jvbIcon(string $name, array $options = []): string
+{
+ $source = $options['source'] ?? 'icons';
+
+ // Remove source from options before passing to IconsManager
+ unset($options['source']);
+
+ return IconsManager::for($source)->get($name, $options);
+}
+
+function jvbFullIcon(string $name, array $options = []):string
+{
+ $source = $options['source'] ?? 'icons';
+ unset($options['source']);
+ return IconsManager::for($source)->getRawSvg($name, $options['style']??null);
+}
+
+/**
+ * Get a CSS data URI for an icon
+ *
+ * @param string $name Icon name
+ * @param array $options Options array:
+ * - 'style' => 'regular'|'bold'|'fill'|etc.
+ * - 'source' => 'icons'|'dash'|'forms'|etc. (for tracking purposes)
+ * @return string data:image/svg+xml;base64,... URL
+ */
+function jvbCSSIcon(string $name, array $options = []): string
+{
+ $style = $options['style'] ?? null;
+ $source = $options['source'] ?? 'icons';
+
+ return IconsManager::for($source)->getCSSIcon($name, $style);
+}
+
+/**
+ * Get a dashboard icon
+ */
+function jvbDashIcon(string $name, array $options = []): string
+{
+ $options['source'] = 'dash';
+ return jvbIcon($name, $options);
+}
+
+/**
+ * Get a form editor icon
+ */
+function jvbFormIcon(string $name, array $options = []): string
+{
+ $options['source'] = 'forms';
+ return jvbIcon($name, $options);
+}
+
require(JVB_DIR . '/inc/integrations/_setup.php');
require(JVB_DIR . '/inc/rest/_setup.php');
-require(JVB_DIR . '/inc/meta/_setup.php');
add_filter( 'cron_schedules', 'jvbCronSchedules');
function jvbCronSchedules($schedules)
@@ -76,7 +233,7 @@
'display' => __('Every minute', 'jvb')
];
$schedules[ 'monthly' ] = [
- 'interval' => 604800 * 4,
+ 'interval' => MONTH_IN_SECONDS,
'display' => __('Once Monthly', 'jvb')
];
@@ -87,21 +244,7 @@
register_deactivation_hook(JVB_DIR.'/jvb.php', 'jvbDeactivatePlugin');
-
-
-
-
-
-add_action('init', 'jvbUserCheck');
-function jvbUserCheck():void
-{
- if (is_admin() && isOurPeople()) {
- wp_redirect(get_home_url(2, '/dash'));
- exit;
- }
-}
-
-require(JVB_DIR . '/inc/users/UserSettings.php');
+//require(JVB_DIR . '/inc/users/UserSettings.php');
require(JVB_DIR . '/inc/templates.php');
@@ -113,22 +256,202 @@
require(JVB_DIR . '/inc/admin/_setup.php');
require(JVB_DIR . '/JVBase.php');
-add_action('init', 'jvbLoadBase', 1);
+
+/**
+ * After moving to the Registrar::based registration, we need to carefully time
+ * when Site gets defined, as well as Registrar initial definitions, field definitions,
+ * and integration config
+ * These custom actions should simplify the timing for us.
+ */
+add_action('plugins_loaded', 'jvb_site_definitions',1);
+add_action('plugins_loaded', 'jvb_registrar_definitions',2);
+add_action('plugins_loaded', 'jvb_field_definitions', 3);
+add_action('plugins_loaded', 'jvb_options_definitions',3);
+add_action('init', 'jvbLoadBase', 2);
+add_action('init', 'jvb_integration_definitions',3);
+add_action('init', 'jvb_field_section_definitions', 5);
+/**
+ * Can define the Site settings
+ * @return void
+ */
+function jvb_site_definitions():void
+{
+ do_action('jvb_define_site');
+}
+function jvb_registrar_definitions():void
+{
+ do_action('jvb_define_registrar');
+}
+function jvb_field_definitions():void
+{
+ do_action('jvb_define_fields');
+}
+
+function jvb_options_definitions():void
+{
+ do_action('jvb_define_options');
+}
+
function jvbLoadBase():void
{
- JVB::getInstance();
+ do_action('jvbloaded');
+ Emails::getInstance();
+ Queue::getInstance();
+ Roles::getInstance();
+ Login::getInstance();
+ SEOAdmin::getInstance();
+ SchemaOutput::getInstance();
+ SchemaHelper::getInstance();
+ CustomBlocks::getInstance();
+
+ AdminPages::getInstance();
+
+ if (Site::has('magic_link')) {
+ MagicLinks::getInstance();
+ }
+ if (Site::has('dashboard')) {
+ Dashboard::getInstance();
+ }
+ if (Site::has('referrals')) {
+ Referrals::getInstance();
+ }
+
+
+ if (Site::has('is_directory')) {
+ DirectoryManager::getInstance();
+ }
+
+ if (Site::has('feed_block')) {
+ TaxonomyRelationships::getInstance();
+ }
+
+ if (Site::hasAll(['dashboard', 'membership', 'feed_block'])) {
+ UserTermsManager::getInstance();
+ }
+
+ if (Site::has('favourites')) {
+ Favourites::getInstance();
+ }
+
+ if (!empty(Registrar::withFeature('has_responses'))) {
+ Responses::getInstance();
+ }
+
+ $membership = Site::membership();
+ if ($membership && $membership->has('notifications')) {
+ NotificationManager::getInstance();
+ }
+ if ($membership && $membership->has('invitable')) {
+ InvitationsManager::getInstance();
+ }
+
+ if (!empty(Registrar::withFeature('approve_new'))) {
+ Approvals::getInstance();
+ }
+ jvbLoadRoutes();
}
+
+function jvb_integration_definitions():void
+{
+ do_action('jvb_define_integrations');
+}
+
+function jvb_field_section_definitions():void
+{
+ do_action('jvb_define_field_sections');
+ Registrar::maybeBuildSections();
+}
+
+add_action('wp_footer', 'jvbAdditionalActions');
+function jvbAdditionalActions():void
+{
+ if (Login::isLogin()) {
+ return;
+ }
+ $extras = apply_filters('jvbAdditionalActions', []);
+ $extras = array_filter($extras, function ($extra) {
+ return is_array($extra) && array_key_exists('button', $extra) && array_key_exists('content', $extra);
+ });
+ if (empty ($extras)) {
+ return;
+ }
+ $buttons = array_map(function ($extra) {
+ return $extra['button'];
+ }, $extras);
+ $contents = array_map(function($extra) {
+ return $extra['content'];
+ }, $extras);
+
+ if (!empty ($buttons)) {
+ ?>
+ <section class="main-actions">
+ <div class="buttons col">
+ <?= implode('', $buttons); ?>
+ </div>
+ <div class="actions">
+ <?= implode('', $contents); ?>
+ </div>
+ </section>
+ <?php
+ }
+}
+
+
function JVB(): JVB
{
return JVB::getInstance();
}
+use JVBase\rest\routes\AdminRoutes;
+use JVBase\rest\routes\ContentRoutes;
+use JVBase\rest\routes\ContentTermsRoutes;
+use JVBase\rest\routes\ErrorRoutes;
+use JVBase\rest\routes\FeedRoutes;
+use JVBase\rest\routes\FormRoutes;
+use JVBase\rest\routes\NewsRoutes;
+use JVBase\rest\routes\OptionsRoutes;
+use JVBase\rest\routes\SEORoutes;
+use JVBase\rest\routes\SettingsRoutes;
+use JVBase\rest\routes\TermRoutes;
+use JVBase\rest\routes\UploadRoutes;
-function checkIf(): Checker
+function jvbLoadRoutes():void
{
- return JVBase\utility\Checker::getInstance();
+ SEORoutes::getInstance();
+ SettingsRoutes::getInstance();
+ UploadRoutes::getInstance();
+ if (!empty(apply_filters('jvb_register_forms', []))) {
+ FormRoutes::getInstance();
+ }
+ UserRoutes::getInstance();
+
+ if (Site::has('feed_block')) {
+ FeedRoutes::getInstance();
+ }
+
+ if (Site::has('feed_block') || Site::has('dashboard')) {
+ TermRoutes::getInstance();
+ }
+
+ if (Site::has('dashboard')) {
+ ErrorRoutes::getInstance();
+ AdminRoutes::getInstance();
+ ContentRoutes::getInstance();
+ ContentTermsRoutes::getInstance();
+ OptionsRoutes::getInstance();
+ }
+
+ $membership = Site::membership();
+ if ($membership && $membership->has('forum'))
+ {
+ NewsRoutes::getInstance();
+ }
}
+
+
+
+
require(JVB_DIR . '/inc/blocks/_setup.php');
@@ -158,746 +481,7 @@
}
-/**
- * Scripts
- */
-add_action('wp_enqueue_scripts', 'jvbScripts', 999);
-function jvbScripts():void
-{
- /**
- * Register Scripts
- */
- //Helper functions used by other classes
- wp_register_script(
- 'jvb-utility',
- JVB_URL.'assets/js/min/utility.min.js',
- [],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- wp_register_script(
- 'jvb-favourites',
- JVB_URL.'assets/js/min/favourites.min.js',
- [
- 'jvb-queue',
- 'jvb-data-store'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
- wp_register_script(
- 'jvb-votes',
- JVB_URL.'assets/js/min/votes.min.js',
- [
- 'jvb-queue',
- 'jvb-data-store'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Main js image resizing, and gallery
- //TODO: lots of overlap between modals and this, utilize a11y for trapFocus,
- wp_register_script(
- 'jvb-media',
- JVB_URL.'assets/js/min/media.min.js',
- [],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- wp_register_script(
- 'jvb-copy-hours',
- JVB_URL.'assets/js/min/hours.min.js',
- [
- 'jvb-form',
- 'jvb-utility',
- 'jvb-modal',
- 'jvb-a11y'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Includes the escape and outside click listeners and intersection observers
- //TODO: make the Modals class use this?
-// wp_register_script(
-// 'jvb-ui',
-// JVB_URL.'assets/js/min/ui.min.js',
-// [],
-// '1.0.0',
-// [
-// 'strategy' => 'defer',
-// 'in_footer' => true,
-// ]
-// );
-
- wp_register_script(
- 'jvb-gallery',
- JVB_URL.'assets/js/min/gallery.min.js',
- [
- 'jvb-utility',
- 'jvb-queue'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- wp_register_script(
- 'jvb-integrations',
- JVB_URL.'assets/js/min/integrations.min.js',
- [],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true
- ]
- );
-
-
- $integration_nonces = [
- 'jvb_square_sync' => wp_create_nonce('jvb_square_sync'),
- 'jvb_gmb_sync_reviews' => wp_create_nonce('jvb_gmb_sync'),
- 'jvb_gmb_test_api' => wp_create_nonce('jvb_gmb_test'),
- 'jvb_bluesky_test_post' => wp_create_nonce('jvb_bluesky_test'),
- 'jvb_facebook_test_post' => wp_create_nonce('jvb_facebook_test'),
- 'jvb_instagram_test_post' => wp_create_nonce('jvb_instagram_test'),
- 'jvb_instagram_sync_media' => wp_create_nonce('jvb_instagram_sync'),
- 'jvb_umami_refresh_data' => wp_create_nonce('jvb_umami_refresh'),
- 'jvb_export_integration_settings' => wp_create_nonce('jvb_integration_export'),
- ];
- $data = [
- 'ajaxUrl' => admin_url('admin-ajax.php'),
- 'nonce' => wp_create_nonce('jvb_integrations'),
- 'nonces' => $integration_nonces,
-// 'services' => array_keys(jvbConnect()->getAvailableServices()),
- 'userId' => get_current_user_id(),
- 'baseUrl' => admin_url('admin.php?page=' . BASE)
- ];
- wp_localize_script(
- 'jvb-integrations',
- 'jvbIntegrationsConfig',
- $data
- );
-
- //The On-This-Page menu. TODO: just include in ui?
- wp_register_script(
- 'jvb-page-nav',
- JVB_URL.'assets/js/min/page-nav.min.js',
- [],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //A11y accessibility
- wp_register_script(
- 'jvb-a11y',
- JVB_URL.'assets/js/min/a11y.min.js',
- [],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Central Error Management
- wp_register_script(
- 'jvb-error',
- JVB_URL.'assets/js/min/error.min.js',
- [
-
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Cache Management
- wp_register_script(
- 'jvb-cache',
- JVB_URL.'assets/js/min/cache.min.js',
- [],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- wp_register_Script(
- 'jvb-data-store',
- JVB_URL.'assets/js/min/dataStore.min.js',
- [],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Tabs functionality
- wp_register_script(
- 'jvb-tabs',
- JVB_URL.'assets/js/min/tabs.min.js',
- [
- 'jvb-a11y'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Modal functionality
- wp_register_script(
- 'jvb-modal',
- JVB_URL.'assets/js/min/modal.min.js',
- [
- 'jvb-a11y'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Central Queue Management
- wp_register_script(
- 'jvb-queue',
- JVB_URL.'assets/js/min/queue.min.js',
- [
- 'jvb-a11y',
- 'jvb-error',
- 'jvb-data-store',
- 'jvb-utility',
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //TaxonomySelector.js
- wp_register_script(
- 'jvb-selector',
- JVB_URL.'assets/js/min/selector.min.js',
- [
- 'jvb-utility',
- 'jvb-a11y',
- 'jvb-error',
- 'jvb-data-store',
- 'jvb-modal',
-// 'jvb-loading'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- wp_register_script(
- 'jvb-creator',
- JVB_URL.'assets/js/min/creator.min.js',
- ['jvb-selector'],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true
- ]
- );
-
- //PostSelector.js
- wp_register_script(
- 'jvb-post-selector',
- JVB_URL.'assets/js/min/postSelector.min.js',
- [
- 'jvb-selector'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
-// //Central Loading Manager
-// wp_register_script(
-// 'jvb-loading',
-// JVB_URL.'assets/js/min/loading.min.js',
-// [],
-// '1.0.0',
-// [
-// 'strategy' => 'defer',
-// 'in_footer' => true,
-// ]
-// );
-// wp_localize_script(
-// 'jvb-loading',
-// 'loadingQuips',
-// [
-// 'quips' => json_encode(apply_filters(
-// 'jvbLoadingQuips',
-// []
-// ))
-// ]
-// );
-
- //Upload Manager
- wp_register_script(
- 'jvb-uploader',
- JVB_URL.'assets/js/min/uploader.min.js',
- [
- 'jvb-cache',
- 'jvb-a11y',
- 'jvb-utility',
-// 'jvb-loading',
- 'jvb-queue',
- 'jvb-notifications'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- wp_register_script(
- 'quill-js',
- 'https://cdn.jsdelivr.net/npm/quill@2.0.3/dist/quill.js',
- [],
- null,
- true
- );
-
- wp_register_script(
- 'sortable-js',
- 'https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js',
- array(),
- null,
- true
- );
-
- //Custom Dashboard Navigator
-// wp_register_script(
-// 'jvb-dashboard-navigator',
-// JVB_URL.'assets/js/min/DashboardNavigator.min.js',
-// [
-// 'jvb-a11y',
-// 'jvb-loading',
-// 'jvb-content',
-// 'jvb-crud',
-// 'jvb-tabs'
-// ],
-// '1.0.0',
-// [
-// 'strategy' => 'defer',
-// 'in_footer' => true,
-// ]
-// );
-
- //Notifications
- wp_register_script(
- 'jvb-notifications',
- JVB_URL.'assets/js/min/notifications.min.js',
- [
- 'jvb-utility',
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Base Form Handler
- wp_register_script(
- 'jvb-form',
- JVB_URL.'assets/js/min/form.min.js',
- [
- 'jvb-utility',
- 'jvb-selector',
- 'jvb-uploader',
- 'sortable-js'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- wp_register_script(
- 'jvb-populate-form',
- JVB_URL.'assets/js/min/populate.min.js',
- [],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
- wp_register_script(
- 'jvb-quill',
- JVB_URL.'assets/js/min/quill.min.js',
- [
- 'quill-js'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
- //CRUD Base Manager
- wp_register_script(
- 'jvb-crud',
- JVB_URL.'assets/js/min/crud.min.js',
- [
- 'jvb-selector',
- 'jvb-a11y',
- 'jvb-error',
- 'jvb-data-store',
- 'jvb-populate-form',
- 'jvb-queue',
- 'jvb-utility',
- 'jvb-quill',
- 'jvb-form',
- 'jvb-view',
- 'jvb-modal'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- wp_register_script(
- 'jvb-view',
- JVB_URL.'assets/js/min/view.min.js',
- [
- 'jvb-a11y',
- 'jvb-utility',
- 'jvb-data-store',
- 'jvb-error'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Bio Manager TODO: Replace with Form Handler
- wp_register_script(
- 'jvb-bio',
- JVB_URL.'assets/js/min/bioManager.min.js',
- [
- 'jvb-tabs',
- 'jvb-form',
- 'jvb-queue'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Shop Manager TODO: Replace with Form Handler
- wp_register_script(
- 'jvb-shop',
- JVB_URL.'assets/js/min/shopManager.min.js',
- [
- 'jvb-tabs',
- 'jvb-form',
- 'jvb-queue'
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Content Manager TODO: Replace with CRUD.js
- wp_register_script(
- 'jvb-content',
- JVB_URL.'assets/js/min/ContentManager.min.js',
- [
- 'jvb-queue',
- 'jvb-cache',
- 'jvb-error',
- 'jvb-uploader',
- 'jvb-utility',
- 'jvb-modal',
- 'jvb-selector',
- 'jvb-post-selector',
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Favourites Manager TODO: Replace with CRUD.js
- wp_register_script(
- 'jvb-favourites',
- JVB_URL.'assets/js/min/favouritesManager.min.js',
- [
- 'jvb-a11y',
- 'jvb-queue',
- 'jvb-cache',
- 'jvb-error',
- 'jvb-utility',
- 'jvb-tabs',
- 'jvb-selector',
- 'jvb-notifications',
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //News Manager TODO: Replace with CRUD.js
- wp_register_script(
- 'jvb-news',
- JVB_URL.'assets/js/min/news.min.js',
- [
- 'jvb-a11y',
- 'jvb-queue',
- 'jvb-cache',
- 'jvb-error',
- 'jvb-utility',
- 'jvb-modal',
- 'jvb-selector',
- 'jvb-tabs',
- ],
- '1.0.0',
- [
- 'strategy' => 'defer',
- 'in_footer' => true,
- ]
- );
-
- //Notification Manager TODO: Replace with CRUD? Not quite...
- wp_register_script(
- 'jvb-notification-manager',
- JVB_URL.'assets/js/min/notificationManager.min.js',
- [
- 'jvb-a11y',
- 'jvb-tabs',
- ]
- );
-
- wp_register_script(
- 'jvb-navigation',
- JVB_URL.'assets/js/min/navigation.min.js',
- );
-
-
-
- add_action('wp_head', 'jvbInlineNavStyles');
-
- wp_enqueue_script('jvb-queue');
- wp_enqueue_script('jvb-navigation');
-// wp_enqueue_script('jvb-ui');
- wp_enqueue_script('jvb-media');
- wp_enqueue_script('jvb-cache');
- wp_localize_script(
- 'jvb-cache',
- 'cacheJVB',
- [
- 'cache' => json_encode(jvbGetCache())
- ]
- );
-
-
-
- $userID = get_current_user_id();
- $icons = new \JVBase\JVBIcons();
- $queue = (is_user_logged_in()) ?
- [
- 'api' => rest_url('jvb/v1/'),
- 'currentUser' => $userID,
- 'nonce' => wp_create_nonce('wp_rest'),
- 'dash' => wp_create_nonce('dash-'.$userID),
- 'favourites' => wp_create_nonce('favourites-'.$userID),
- 'notifications' => wp_create_nonce('notifications-'.$userID),
- 'icons' => $icons->localizeIcons(),
- 'labels' => jvbGetLabels(),
- ] :
- [
- 'api' => rest_url('jvb/v1/'),
- 'nonce' => wp_create_nonce('wp_rest'),
- 'currentUser' => false,
- 'redirect' => wp_login_url(home_url(add_query_arg(null, null))), // Current URL as redirect
- 'icons' => $icons->localizeIcons(),
- 'labels' => jvbGetLabels(),
- ];
-
- wp_localize_script('jvb-queue', 'jvbSettings', $queue);
-
- $initUserSettings = 'async function initUserItems() {
- if (!jvbSettings.currentUser) return;
-
- window.userFavourites = {};
- window.userVotes = {};
- ';
- if (Features::forSite()->has('favourites')) {
- wp_enqueue_script('jvb-favourites');
- $initUserSettings .= '
- //Fetch user favourites
- try {
- const result = await window.jvbCache.fetchWithCache(
- `${jvbSettings.api}favourites?all=true`,
- {
- method: \'GET\',
- headers: {\'X-WP-Nonce\': jvbSettings.nonce}
- }
- );
-
- if (result && result.favourites) {
- for (const key in result.favourites) {
- window.userFavourites[key] = new Set();
- result.favourites[key].forEach(id => {
- window.userFavourites[key].add(parseInt(id));
- });
- }
- }
- } catch (error) {
- console.error(\'Failed to fetch user favourites:\', error);
- }';
- }
-
- if (Features::anyContentHas('karma') || Features::anyTaxonomyHas('karma') || Features::anyUserHas('karma')) {
- wp_enqueue_script('jvb-votes');
- $initUserSettings .= '// Fetch user votes
- try {
- const result = await window.jvbCache.fetchWithCache(
- `${jvbSettings.api}vote?user=${jvbSettings.currentUser}`,
- {
- method: \'GET\',
- headers: {\'X-WP-Nonce\': jvbSettings.nonce}
- },
- {forceRefresh: true}
- );
-
- window.userVotes = {};
- if (result) {
- for (const key in result) {
- window.userVotes[key] = new Map();
- for (const [id, vote] of Object.entries(result[key])) {
- window.userVotes[key].set(parseInt(id), vote);
- }
- }
- }
- } catch (error) {
- console.error(\'Failed to fetch user votes:\', error);
- }';
- }
-
- $initUserSettings .= '} initUserItems();';
-
-// wp_add_inline_script('jvb-queue', $initUserSettings, 'after');
-
-
- if (is_search() ||
- is_tax(BASE.'shop') ||
- is_singular(BASE.'artist') ||
- jvbIsDirectory()
- ) {
- wp_enqueue_script('jvb-page-nav');
- }
-
- // Only load on single shop pages or other relevant pages
- if (is_tax(BASE.'shop') ||
- is_singular(BASE.'partner')) {
- $ID = get_queried_object_id();
- if (is_tax()) {
- $check = get_term_meta($ID, BASE.'has_map', true);
- } else {
- $check = get_post_meta($ID, BASE.'has_map', true);
- }
-
-// if ($check && $check !== '') {
-//// wp_enqueue_script(
-//// 'google-maps-frontend',
-//// 'https://maps.googleapis.com/maps/api/js?key=' . GOOGLE_API . '&callback=googleMapsLoaded',
-//// [],
-//// null,
-//// ['strategy' => 'async',
-//// 'in_footer' => true]
-//// );
-//
-// // Add the callback function
-// wp_add_inline_script('google-maps-frontend', '
-// function googleMapsLoaded() {
-// if (window.googleMapsCallbacks && window.googleMapsCallbacks.length) {
-// window.googleMapsCallbacks.forEach(callback => callback());
-// }
-// }
-// ');
-// }
- }
- if (is_user_logged_in()) {
- wp_enqueue_script('jvb-notifications');
-
- wp_localize_script('jvb-notifications', 'notificationSettings', array(
- 'homeUrl' => home_url(),
- 'strings' => array(
- 'loading' => 'Loading...',
- 'error' => 'Failed to load notifications',
- 'noNotifications' => 'No new notifications',
- 'viewAll' => 'View All Notifications',
- 'markRead' => 'Mark as read',
- 'review' => 'Review'
- )
- ));
- }
-
- jvbAddScriptDependency('jvb-feed-view-script', 'jvb-queue');
- jvbAddScriptDependency('jvb-feed-view-script', 'jvb-selector');
- jvbAddScriptDependency('jvb-feed-view-script', 'jvb-gallery');
-// jvbAddScriptDependency('jvb-feed-view-script', 'jvb-loading');
- jvbAddScriptDependency('jvb-forms-view-script', 'jvb-queue');
- jvbAddScriptDependency('jvb-forms-view-script', 'jvb-quill');
- jvbAddScriptDependency('jvb-forms-view-script', 'jvb-form');
- jvbAddScriptDependency('jvb-forms-view-script', 'jvb-tabs');
-}
function jvbAdminMap():void
{
@@ -922,21 +506,7 @@
// ');
}
-function jvbAddScriptDependency(string $handle, string $dep):bool
-{
- global $wp_scripts;
- $script = $wp_scripts->query($handle);
- if (!$script) {
- return false;
- }
-
- if (!in_array($dep, $script->deps)) {
- $script->deps[] = $dep;
- }
-
- return true;
-}
add_action('wp_body_open', 'jvbAccessibility');
@@ -945,25 +515,77 @@
echo '<div class="screen-reader-text live-region" aria-live="polite" role="status"></div>';
}
+//add_action('wp_head', 'jvbFrontendBase',1);
+//function jvbFrontendBase():void
+//{
+// ?>
+<!-- <script type="text/javascript">window.jvbBase = '--><?php //= BASE ?>//';</script>
+// <?php
+//}
-//add_action('wp_head', 'jvbDumpIt');
-function jvbDumpIt()
+
+
+add_action('after_setup_theme', 'jvbImageSize');
+function jvbImageSize():void
{
-
+ add_theme_support('post-thumbnails');
+ add_image_size( 'tiny', 50, 50, false );
+ add_image_size( 'directory-preview', 100, 100, false );
}
-//add_filter('map_meta_cap', function($caps, $cap, $user_id, $args) {
-// error_log('Caps: '.print_r($caps, true));
-// error_log('Cap: '.print_r($cap, true));
-// error_log('User ID: '.print_r($user_id, true));
-// error_log('Args: '.print_r($args, true));
-// return $caps;
-//}, 10, 4);
-add_action( 'doing_it_wrong_run', function( $function, $message, $version ) {
- if ( 'map_meta_cap' === $function ) {
- error_log( "Map Meta Cap Wrong: $message" );
- error_log( print_r( wp_debug_backtrace_summary( null, 0, false ), true ) );
+//
+//add_action('rest_api_init', function() {
+// error_log('User ' . get_current_user_id() . ' can edit pages: ' . (current_user_can('edit_pages') ? 'yes' : 'no'));
+// error_log('User roles: ' . print_r(wp_get_current_user()->roles, true));
+//});
+//
+//add_filter('rest_pre_dispatch', function($result, $server, $request) {
+// if (strpos($request->get_route(), '/wp/v2/pages') !== false) {
+// error_log('Pages request - User: ' . get_current_user_id());
+// error_log('Can edit pages: ' . (current_user_can('edit_pages') ? 'yes' : 'no'));
+// error_log('Nonce: ' . $request->get_header('X-WP-Nonce'));
+// }
+// return $result;
+//}, 10, 3);
+
+add_filter('rest_authentication_errors', function($result) {
+
+ // Don't override existing authentication
+ if (is_wp_error($result) || $result === true) {
+ return $result;
}
-}, 10, 3 );
+ // Try to authenticate from cookie
+ $cookie_user = wp_validate_auth_cookie('', 'logged_in');
+
+ if ($cookie_user) {
+ wp_set_current_user($cookie_user);
+ return true;
+ }
+ return $result;
+}, 99);
+
+
+add_action('wp_footer', 'jvb_back_to_top');
+function jvb_back_to_top():void
+{
+ echo sprintf(
+ '<a id="back-to-top" class="btn sticky" href="#">%s<span>Back to Top</span></a>',
+ jvbIcon('caret-double-up')
+ );
+}
+
+add_action( 'doing_it_wrong_run', function ( $function_name ) {
+ if ( '_load_textdomain_just_in_time' === $function_name ) {
+ // This will print the full execution path to your screen or log
+ debug_print_backtrace();
+ }
+} );
+
+
+add_filter('the_seo_framework_sitemap_exclude_ids', 'jvb_maybe_exclude_singles', 8, 1);
+function jvb_maybe_exclude_singles(array $IDs):array
+{
+ return Registrar::maybeExcludeSingles($IDs);
+}
--
Gitblit v1.10.0