| | |
| | | namespace JVBase\integrations; |
| | | |
| | | use JVBase\integrations\Integrations; |
| | | use JVBase\meta\Meta; |
| | | use WP_Error; |
| | | use WP_REST_Request; |
| | | use WP_REST_Response; |
| | |
| | | */ |
| | | public function handleTheSavePost(int $postID, \WP_Post $post, bool $update, array $settings): void |
| | | { |
| | | // Check if post has featured image (Instagram requirement) |
| | | |
| | | if (!$this->hasOAuthCredentials()) { |
| | | error_log('OAuth Not set up for '.$this->service_name); |
| | | return; |
| | | } |
| | | if (!has_post_thumbnail($postID)) { |
| | | $this->logError('Cannot post to Instagram without featured image', [ |
| | | 'post_id' => $postID |
| | | ]); |
| | | return; |
| | | } |
| | | |
| | | // Queue the Instagram post creation |
| | | $this->queueOperation('create_post', [ |
| | | 'post_id' => $postID, |
| | | 'type' => get_post_type($postID) |
| | | $this->queueOperation(self::$syncTo, [ |
| | | 'items' => [$postID], |
| | | 'user' => user_can($post->post_author, 'manage_options') ? null : $post->post_author |
| | | ], [ |
| | | 'priority' => 'normal', |
| | | 'delay' => 60 // Wait 1 minute to ensure all metadata is saved |
| | | 'delay' => 60 |
| | | ]); |
| | | |
| | | update_post_meta($postID, BASE . '_instagram_sync_status', 'queued'); |
| | | Meta::forPost($postID)->set('_'.$this->service_name.'_sync_status', 'queued'); |
| | | } |
| | | |
| | | /** |