| | |
| | | */ |
| | | |
| | | namespace JVBase\integrations\services; |
| | | use Exception; |
| | | use JVBase\integrations\Integrations; |
| | | use JVBase\meta\Meta; |
| | | use WP_Error; |
| | | use WP_Post; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | |
| | | /** |
| | | * Handle post save - queue Instagram post creation |
| | | */ |
| | | public function handleTheSavePost(int $postID, \WP_Post $post, bool $update, array $settings): void |
| | | public function handleTheSavePost(int $postID, WP_Post $post, bool $update, array $settings): void |
| | | { |
| | | |
| | | if (!$this->hasOAuthCredentials()) { |
| | |
| | | /** |
| | | * Process queued operations |
| | | */ |
| | | public function processOperation(\WP_Error|array $result, object $operation, array $data): \WP_Error|array |
| | | public function processOperation(WP_Error|array $result, object $operation, array $data): WP_Error|array |
| | | { |
| | | $base = strtolower($this->service_name) . '_'; |
| | | $insta = (array_key_exists('user', $data)) ? new self((int)$data['user']) : $this; |
| | | switch ($operation->type) { |
| | | case $base . 'create_post': |
| | | return $insta->processCreatePost($data); |
| | | |
| | | case $base . 'create_story': |
| | | return $insta->processCreateStory($data); |
| | | |
| | | case $base . 'delete_post': |
| | | return $insta->processDeletePost($data); |
| | | |
| | | default: |
| | | return $result; |
| | | } |
| | | return match ($operation->type) { |
| | | $base . 'create_post' => $insta->processCreatePost($data), |
| | | $base . 'create_story' => $insta->processCreateStory($data), |
| | | $base . 'delete_post' => $insta->processDeletePost($data), |
| | | default => $result, |
| | | }; |
| | | } |
| | | |
| | | private function processDeletePost(array $data): array |
| | |
| | | /** |
| | | * Build caption for Instagram post |
| | | */ |
| | | private function buildCaption(\WP_Post $post): string |
| | | private function buildCaption(WP_Post $post): string |
| | | { |
| | | $caption_parts = []; |
| | | |
| | |
| | | $default = preg_split('/[\s,]+/', $this->post_settings['default_hashtags']); |
| | | foreach ($default as $tag) { |
| | | $tag = trim($tag); |
| | | if (strpos($tag, '#') !== 0) { |
| | | if (!str_starts_with($tag, '#')) { |
| | | $tag = '#' . $tag; |
| | | } |
| | | $hashtags[] = $tag; |