| | |
| | | <?php |
| | | namespace JVBase\integrations; |
| | | |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\meta\Meta; |
| | | use JVBase\registrar\Registrar; |
| | | use WP_Post; |
| | |
| | | trait SyncToPost |
| | | { |
| | | use SyncTo, SyncHelpers, UserConnection; |
| | | |
| | | public function addSavePost():void |
| | | { |
| | | if (!has_action('save_post', [$this, 'handleSavePost'])) { |
| | |
| | | } |
| | | public function removeSavePost():void |
| | | { |
| | | remove_action('save_post', [$this, 'handleSavePost'], 20, 3); |
| | | remove_action('save_post', [$this, 'handleSavePost'], 20); |
| | | } |
| | | public function handleSavePost(int $postID, WP_Post $post, bool $update):void |
| | | { |
| | | if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; |
| | | if (wp_is_post_revision($postID)) return; |
| | | if (wp_is_post_revision($postID) || wp_is_post_autosave($postID)) return; |
| | | if (isset(self::$syncing['posts'][$postID])) return; |
| | | self::$syncing['posts'][$postID] = true; |
| | | |
| | | error_log('=== ['.$this->service_name.']::handleSavePost called'); |
| | | |
| | |
| | | $this->removeSavePost(); |
| | | $this->handleTheSavePost($postID, $post, $update, $settings); |
| | | $this->addSavePost(); |
| | | unset(self::$syncing['posts'][$postID]); |
| | | } |
| | | /** |
| | | * Handle post save for syncing |
| | |
| | | } |
| | | public function removeDeletePost():void |
| | | { |
| | | remove_action('before_delete_post', [$this, 'handleSavePost'], 20, 3); |
| | | remove_action('before_delete_post', [$this, 'handleSavePost'], 20); |
| | | } |
| | | public function handleDeletePost(int $postID):void |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | JVB()->queue()->add( |
| | | Queue::getInstance()->add( |
| | | self::$deleteFrom, |
| | | $userID, |
| | | [ |