From 0ded4aedad662085c2d58a19c736031de056c3f2 Mon Sep 17 00:00:00 2001 From: NiclasNorin Date: Mon, 6 Jul 2026 14:08:24 +0200 Subject: [PATCH] fix: posts get password protected --- source/php/Admin/DisplayEditLinkInterfaceNotice.php | 2 +- source/php/Api/RestApiParams.php | 6 ++++-- source/php/DataProcessor/Handlers/WpDbHandler.php | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/source/php/Admin/DisplayEditLinkInterfaceNotice.php b/source/php/Admin/DisplayEditLinkInterfaceNotice.php index a672c86e..094141a8 100644 --- a/source/php/Admin/DisplayEditLinkInterfaceNotice.php +++ b/source/php/Admin/DisplayEditLinkInterfaceNotice.php @@ -79,7 +79,7 @@ private function constructFrontendUrl(int $postId): string */ private function getPostPasswordToken(int $postId): string { - return $this->wpService->getPost($postId)->post_password ?? ''; + return $this->wpService->getPostMeta($postId, $this->config->getMetaDataNamespace('edit_token'), true) ?? ''; } /** diff --git a/source/php/Api/RestApiParams.php b/source/php/Api/RestApiParams.php index 10d07ff2..03386053 100644 --- a/source/php/Api/RestApiParams.php +++ b/source/php/Api/RestApiParams.php @@ -189,7 +189,9 @@ private function getTokenSpecification(): array } // Unprotected post - if(empty($post->post_password)) { + $editToken = $this->wpService->getPostMeta($postId, $this->config->getMetaDataNamespace('edit_token'), true); + + if(empty($editToken)) { return new WP_Error( 'asset_not_protected', __('The resource you are trying to access is not editable.', 'modularity-frontend-form'), @@ -198,7 +200,7 @@ private function getTokenSpecification(): array } //Not matching the token - if($token !== $post->post_password) { + if($token !== $editToken) { return new WP_Error( 'invalid_token', __('The token provided, does not match the asset.', 'modularity-frontend-form'), diff --git a/source/php/DataProcessor/Handlers/WpDbHandler.php b/source/php/DataProcessor/Handlers/WpDbHandler.php index 770683fa..72478253 100644 --- a/source/php/DataProcessor/Handlers/WpDbHandler.php +++ b/source/php/DataProcessor/Handlers/WpDbHandler.php @@ -112,14 +112,14 @@ private function insertPost( 'post_content' => $postContent ?: '', 'post_type' => $moduleConfig->saveToPostType, 'post_status' => $moduleConfig->saveToPostTypeStatus, - 'post_password' => $this->createPostPassword(), 'meta_input' => [ $this->config->getMetaDataNamespace('holding_post_id') => ( $params->holdingPostId ?? null ), - $this->config->getMetaDataNamespace('module_id') => $moduleID, - $this->config->getMetaDataNamespace('nonce') => $fieldMeta['nonce'] ?? '', - $this->config->getMetaDataNamespace('submission') => true + $this->config->getMetaDataNamespace('module_id') => $moduleID, + $this->config->getMetaDataNamespace('nonce') => $fieldMeta['nonce'] ?? '', + $this->config->getMetaDataNamespace('submission') => true, + $this->config->getMetaDataNamespace('edit_token') => $this->createPostPassword(), ], ]);