From fff721dd185f5b97f7ae7a6e64189e55887ff590 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 05 Jul 2026 18:36:57 +0000
Subject: [PATCH] =Cleaning up the Square integration (still a bit more to do yet). Also majorly overhauled /rest/ files to ignore a rest request 'user' paramater, and rely on get_current_user_id() instead.
---
inc/integrations/GoogleMyBusiness.php | 72 ++++++++++++++++++++---------------
1 files changed, 41 insertions(+), 31 deletions(-)
diff --git a/inc/integrations/GoogleMyBusiness.php b/inc/integrations/GoogleMyBusiness.php
index e818d5b..b802142 100644
--- a/inc/integrations/GoogleMyBusiness.php
+++ b/inc/integrations/GoogleMyBusiness.php
@@ -1,8 +1,7 @@
<?php
namespace JVBase\integrations;
-use JVBase\meta\MetaManager;
-use JVBase\managers\CacheManager;
+use JVBase\meta\Meta;
use WP_Error;
if (!defined('ABSPATH')) {
exit;
@@ -10,6 +9,11 @@
class GoogleMyBusiness extends Integrations
{
+ protected array $allowedContent = [
+ 'menu_item',
+ 'post',
+ 'event',
+ ];
private ?string $access_token = null;
protected string $readMask = 'name,title,storefrontAddress,metadata,openInfo,storeCode,categories,phoneNumbers,labels,specialHours';
private ?string $location = null;
@@ -18,7 +22,17 @@
private ?string $client_secret = null;
private ?string $account_id = null;
- public function __construct(?int $userID = null)
+ protected static array $instances = [];
+ public static function getInstance(?int $userID = null):self
+ {
+ $key = is_null($userID) ? 'base' : $userID;
+ if (!array_key_exists($key, self::$instances)) {
+ self::$instances[$key] = new self($userID);
+ }
+ return self::$instances[$key];
+ }
+
+ protected function __construct(?int $userID = null)
{
$this->service_name = 'gmb';
$this->title = 'Google My Business';
@@ -129,7 +143,9 @@
]
);
-// $this->cache->clear();
+ if (JVB_TESTING) {
+ $this->cache->flush();
+ }
}
protected function initialize(): void
@@ -281,7 +297,7 @@
}
$postID = $data['post_id'];
- $meta = new MetaManager($postID, 'post');
+ $meta = Meta::forPost($postID);
$fields = [
'start_date',
'end_date',
@@ -317,7 +333,7 @@
$result = $this->updatePost($fields["_{$this->service_name}_item_id"], $data);
} else {
$result = $this->createPost($data);
- $meta->updateValue("_{$this->service_name}_item_id", $result['name']);
+ $meta->set("_{$this->service_name}_item_id", $result['name']);
}
return [
@@ -338,7 +354,7 @@
}
$postID = $data['post_id'];
- $meta = new MetaManager($postID, 'post');
+ $meta = Meta::forPost($postID);
$fields = [
'post_excerpt',
'post_title',
@@ -370,7 +386,7 @@
$result = $this->updatePost($fields["_{$this->service_name}_item_id"], $data);
} else {
$result = $this->createPost($data);
- $meta->updateValue("_{$this->service_name}_item_id", $result['name']);
+ $meta->set("_{$this->service_name}_item_id", $result['name']);
}
return [
@@ -392,7 +408,7 @@
}
$postID = $data['post_id'];
- $meta = new MetaManager($postID, 'post');
+ $meta = Meta::forPost($postID);
$fields = [
'post_excerpt',
'post_title',
@@ -421,7 +437,7 @@
$result = $this->updatePost($fields["_{$this->service_name}_item_id"], $data);
} else {
$result = $this->createPost($data);
- $meta->updateValue("_{$this->service_name}_item_id", $result['name']);
+ $meta->set("_{$this->service_name}_item_id", $result['name']);
}
return [
@@ -1737,9 +1753,7 @@
$text = preg_replace('/\s+/', ' ', $text);
// Trim
- $text = trim($text);
-
- return $text;
+ return trim($text);
}
/**
* Format date for GMB API
@@ -1780,11 +1794,10 @@
// Validate hour and minute ranges
if ($hour >= 0 && $hour <= 23 && $minute >= 0 && $minute <= 59) {
- $result = [
+ return [
'hours' => $hour,
'minutes' => $minute
];
- return $result;
}
}
@@ -2074,9 +2087,7 @@
[],
'posts'
);
- $result = $response['foodMenus'] ?? [];
-
- return $result;
+ return $response['foodMenus'] ?? [];
}
/**
@@ -2279,7 +2290,7 @@
{
try {
// Use the static method to clear the entire cache group
- $this->cache->clear();
+ $this->cache->flush();
return true;
} catch (\Exception $e) {
@@ -2351,12 +2362,11 @@
'dailyRange.endDate.day' => date('j', strtotime($end_date))
];
- $response = $this->getRequest(
- "/v1/{$location_name}:fetchMultiDailyMetricsTimeSeries?" . http_build_query($params),
- $params,
- 'performance'
- );
- return $response;
+ return $this->getRequest(
+ "/v1/{$location_name}:fetchMultiDailyMetricsTimeSeries?" . http_build_query($params),
+ $params,
+ 'performance'
+ );
}
/**
@@ -2475,7 +2485,7 @@
protected function collectMenu(array $menu_items): array
{
- $defaultMeta = new MetaManager($this->userID, 'integrations');
+ $defaultMeta = Meta::forOptions($this->userID.'_integrations');
$defaults = ['menu_name', 'menu_description', 'default_section', 'cuisines', 'source_url', 'language', 'default_currency'];
$defaults = $defaultMeta->getAll($defaults);
@@ -2536,7 +2546,7 @@
protected function buildMenuItem(\WP_Post $item, array $defaults):array
{
- $meta = new MetaManager($item->ID, 'post');
+ $meta = Meta::forPost($item->ID);
$fields = $this->mappedMenuFields($item->post_type);
$values = $meta->getAll(array_values($fields));
@@ -2665,8 +2675,8 @@
protected function getMenuSectionsOrder(array $sections_map):array
{
- $optionsMeta = new MetaManager(null, 'options');
- $sectionOrder = $optionsMeta->getValue('menu_section_order');
+ $optionsMeta = Meta::forOptions('options');
+ $sectionOrder = $optionsMeta->get('menu_section_order');
// Build final GMB menu structure
$ordered = [];
@@ -2702,8 +2712,8 @@
// Collect cuisines from individual items if specified
foreach ($menu_items as $item) {
- $meta = new MetaManager($item->ID, 'post');
- $item_cuisines = $meta->getValue('cuisines');
+ $meta = Meta::forPost($item->ID);
+ $item_cuisines = $meta->get('cuisines');
if (!empty($item_cuisines)) {
$item_cuisines = is_array($item_cuisines) ?
--
Gitblit v1.10.0