From f94860aacd6200fb24c9e7431eb379a368cb392d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 10 Jul 2026 00:35:44 +0000
Subject: [PATCH] =Refactored CredentialsManager.php to utilize a CustomTable instance instead
---
inc/integrations/Facebook.php | 47 ++++++++++++++++++++++-------------------------
1 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/inc/integrations/Facebook.php b/inc/integrations/Facebook.php
index e7d54e9..2812607 100644
--- a/inc/integrations/Facebook.php
+++ b/inc/integrations/Facebook.php
@@ -42,7 +42,17 @@
'milestone' => 'milestones'
];
- 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 = 'facebook';
$this->title = 'Facebook';
@@ -350,31 +360,18 @@
*/
protected function handleTheSavePost(int $postID, WP_Post $post, bool $update, array $settings): void
{
- $post_type = $settings['fb_type'] ?? 'post';
- $sync_immediately = $settings['immediate'] ?? false;
- // Determine the Facebook post type
- $fb_endpoint = self::FB_POST_TYPES[$post_type] ?? 'feed';
-
- $operation_data = [
- 'post_id' => $postID,
- 'fb_type' => $post_type,
- 'endpoint' => $fb_endpoint,
- 'page_id' => $this->page_id
- ];
-
- // Check for scheduled posting
- $schedule_time = get_post_meta($postID, BASE . 'schedule_facebook', true);
- $options = [];
-
- if ($schedule_time && strtotime($schedule_time) > time()) {
- $options['scheduled'] = strtotime($schedule_time);
- } elseif (!$sync_immediately) {
- $options['delay'] = 300; // 5 minute delay for batching
+ if (!$this->hasOAuthCredentials()) {
+ error_log('OAuth Not set up for '.$this->service_name);
+ return;
}
-
- $operation = $update ? 'update_post' : 'create_post';
- $this->queueOperation($operation, $operation_data, $options);
+ $this->queueOperation(self::$syncTo, [
+ 'items' => [$postID],
+ 'user' => user_can($post->post_author, 'manage_options') ? null : $post->post_author
+ ], [
+ 'delay' => 60
+ ]);
+ Meta::forPost($postID)->set('_'.$this->service_name.'_sync_status', 'queued');
}
/**
@@ -383,7 +380,7 @@
public function processOperation(WP_Error|array $result, object $operation, array $data): WP_Error|array
{
try {
- $fb = (array_key_exists('user', $data)) ? new self((int)$data['user']) : $this;
+ $fb = (array_key_exists('user', $data) && $data['user'] !== 0) ? $this->getInstance((int)$data['user']) : $this;
switch ($operation->type) {
case 'facebook_create_post':
return $fb->createFacebookPost($data);
--
Gitblit v1.10.0