Jake Vanderwerf
2026-07-09 c68aefb847b09daa0697de7684d3451e2e68ce1e
inc/integrations/Facebook.php
@@ -360,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');
   }
   /**
@@ -393,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);