From ccf5e61a075c35d24befc175994b5cb8957ca322 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 26 Aug 2026 21:45:53 +0000
Subject: [PATCH] =Extra JVB() calls replaced, minor tweaks
---
inc/managers/IconsManager.php | 74 +++++++++++++++++++++++++------------
1 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/inc/managers/IconsManager.php b/inc/managers/IconsManager.php
index cf48409..b3b5d62 100644
--- a/inc/managers/IconsManager.php
+++ b/inc/managers/IconsManager.php
@@ -26,6 +26,15 @@
protected array $map = [];
protected const MAX_VERSIONS = 5;
+ protected string $timestampKey;
+ protected string $iconKey;
+ protected string $iconHistoryKey;
+ protected static string $allIcons = 'icons_all_used';
+ protected static string $updateIcons = 'icons_needs_update';
+ protected static string $iconMap = 'icons_map';
+
+
+
/**
* Factory method - get or create instance for a source
*/
@@ -34,6 +43,9 @@
if (!isset(self::$instances[$source])) {
self::$instances[$source] = new self($source);
}
+ self::$instances[$source]->setTimestampKey(BASE.'icons_'.$source.'_timestamp');
+ self::$instances[$source]->setIconKey(BASE.'icons_'.$source);
+ self::$instances[$source]->setIconHistoryKey(BASE.'icons_history_'.$source);
return self::$instances[$source];
}
@@ -72,6 +84,19 @@
$this->registerInstanceHooks();
}
+ protected function setIconKey(string $key):void
+ {
+ $this->iconKey = $key;
+ }
+ protected function setTimestampKey(string $key):void
+ {
+ $this->timestampKey = $key;
+ }
+ protected function setIconHistoryKey(string $key):void
+ {
+ $this->iconHistoryKey = $key;
+ }
+
/**
@@ -124,7 +149,7 @@
*/
protected function loadStoredIcons(): void
{
- $allIcons = get_option(BASE.'usedIcons', []);
+ $allIcons = get_option(BASE.self::$allIcons, []);
$storedIcons = $allIcons[$this->source] ?? [];
// Merge stored icons with any existing icons (like custom icons)
@@ -304,20 +329,19 @@
*/
protected function saveIcons(): void
{
- $allIcons = [];
- foreach (self::$instances as $source => $instance) {
- $allIcons[$source] = $instance->icons;
- }
+ $allIcons = array_map(function ($instance) {
+ return $instance->icons;
+ }, self::$instances);
- update_option(BASE.'usedIcons', $allIcons);
+ update_option(BASE.self::$allIcons, $allIcons);
// Track WHICH source needs updating
- $needsUpdate = get_option(BASE.'icons_needs_update', []);
+ $needsUpdate = get_option(BASE.self::$updateIcons, []);
if (!is_array($needsUpdate)) {
$needsUpdate = [];
}
$needsUpdate[$this->source] = true;
- update_option(BASE.'icons_needs_update', $needsUpdate);
+ update_option(BASE.self::$updateIcons, $needsUpdate);
}
/**
@@ -345,7 +369,7 @@
protected function addMap(): void
{
- $map = get_option(BASE.'iconMap');
+ $map = get_option(BASE.self::$iconMap);
if (!$map) {
$map = [
'seo' => 'robot'
@@ -362,7 +386,7 @@
if (Site::hasAnyIntegration()) {
$map['integrations'] = 'plugs-connected';
}
- update_option(BASE.'iconMap', $map);
+ update_option(BASE.self::$iconMap, $map);
}
$this->map = apply_filters('jvbMapIcons', $map);
@@ -404,10 +428,13 @@
public static function checkCSS(): void
{
- $needsUpdate = get_option(BASE.'icons_needs_update', []);
+ $needsUpdate = get_option(BASE.self::$updateIcons, []);
+ $needsUpdate = array_filter($needsUpdate, function ($item) {
+ return $item === true;
+ });
if (!empty($needsUpdate)) {
error_log('Regenerating CSS for sources: ' . implode(', ', array_keys($needsUpdate)));
- delete_option(BASE.'icons_needs_update');
+ delete_option(BASE.self::$updateIcons);
self::regenerateAllCSS($needsUpdate);
}
}
@@ -422,7 +449,7 @@
}
// Load all icons from database option
- $allIcons = get_option(BASE.'usedIcons', []);
+ $allIcons = get_option(BASE.self::$allIcons, []);
// If no specific sources provided, regenerate all
if (empty($sourcesToUpdate)) {
@@ -535,7 +562,7 @@
}
// Track usage - only if not already tracked
- if (!isset($this->icons[$style])) {
+ if (!array_key_exists($style, $this->icons)) {
$this->icons[$style] = [];
}
@@ -649,7 +676,7 @@
public function registerStyle(): void
{
- $timestamp = Cache::for('icons_'.$this->source)->getTimestamp();
+ $timestamp = get_option($this->timestampKey);
$handle = 'jvb-icons-' . $this->source;
wp_register_style(
@@ -687,7 +714,7 @@
}
}
}
-
+ update_option($this->timestampKey, time());
return $this->minifyCss($css);
}
@@ -743,9 +770,8 @@
*/
public function clearIconCache(): void
{
- delete_option(BASE . 'icon_usage_list'); // Legacy
- delete_option(BASE.'usedIcons');
- delete_option(BASE.'iconMap');
+ delete_option(self::$allIcons);
+ delete_option(self::$iconMap);
// Clear cache for all sources
foreach (self::$instances as $source => $instance) {
@@ -777,12 +803,12 @@
$history = array_slice($history, 0, self::MAX_VERSIONS);
}
- update_option(BASE.'icon_css_history_' . $this->source, $history);
+ update_option($this->iconHistoryKey, $history);
}
public function getVersionHistory(): array
{
- return get_option(BASE.'icon_css_history_' . $this->source, []);
+ return get_option($this->iconHistoryKey, []);
}
public function restoreVersion(int $timestamp): bool
@@ -818,12 +844,12 @@
public function forceRefresh(): void
{
$this->clearIconCache();
- $needsUpdate = get_option(BASE.'icons_needs_update', []);
+ $needsUpdate = get_option(BASE.self::$updateIcons, []);
if (!is_array($needsUpdate)) {
$needsUpdate = [];
}
$needsUpdate[$this->source] = true;
- update_option(BASE.'icons_needs_update', $needsUpdate);
+ update_option(BASE.self::$updateIcons, $needsUpdate);
Cache::for('icons_'.$this->source)->flush();
}
@@ -834,7 +860,7 @@
return false;
}
- $history = get_option(BASE.'icon_css_history_' . $this->source, []);
+ $history = get_option($this->iconHistoryKey, []);
$merged_icons = [];
// Collect icons from selected versions
--
Gitblit v1.10.0