From 79991ae46274b07cb77971f96c41c7ddd551e00d Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Mon, 11 Apr 2022 15:59:36 -0300 Subject: [PATCH] Revert "Restrict dynamic blocks to `public` post status only" This reverts commit 72b3172c1a3d225937a5e957840e1af561bc699b. --- .../API/JSON/v1/AutomatedLatestContent.php | 34 +++++++------------ mailpoet/lib/Newsletter/BlockPostQuery.php | 20 ++++------- .../Blocks/AutomatedLatestContentBlock.php | 1 - 3 files changed, 18 insertions(+), 37 deletions(-) diff --git a/mailpoet/lib/API/JSON/v1/AutomatedLatestContent.php b/mailpoet/lib/API/JSON/v1/AutomatedLatestContent.php index e4aebdcdb9..f2332c11a5 100644 --- a/mailpoet/lib/API/JSON/v1/AutomatedLatestContent.php +++ b/mailpoet/lib/API/JSON/v1/AutomatedLatestContent.php @@ -3,7 +3,6 @@ namespace MailPoet\API\JSON\v1; use MailPoet\API\JSON\Endpoint as APIEndpoint; -use MailPoet\API\JSON\SuccessResponse; use MailPoet\Config\AccessControl; use MailPoet\Newsletter\AutomatedLatestContent as ALC; use MailPoet\Newsletter\BlockPostQuery; @@ -78,28 +77,29 @@ class AutomatedLatestContent extends APIEndpoint { } /** - * Fetches posts for Posts static block + * @param \WP_Post[] $posts + * @return \WP_Post[] */ - public function getPosts(array $data = []): SuccessResponse { + private function getPermittedPosts($posts) { + return array_filter($posts, function ($post) { + return $this->permissionHelper->checkReadPermission($post); + }); + } + + public function getPosts($data = []) { return $this->successResponse( - $this->getPermittedPosts($this->ALC->getPosts(new BlockPostQuery(['args' => $data, 'dynamic' => false]))) + $this->getPermittedPosts($this->ALC->getPosts(new BlockPostQuery(['args' => $data]))) ); } - /** - * Fetches products for Abandoned Cart Content dynamic block - */ - public function getTransformedPosts(array $data = []): SuccessResponse { + public function getTransformedPosts($data = []) { $posts = $this->getPermittedPosts($this->ALC->getPosts(new BlockPostQuery(['args' => $data]))); return $this->successResponse( $this->ALC->transformPosts($data, $posts) ); } - /** - * Fetches different post types for ALC dynamic block - */ - public function getBulkTransformedPosts(array $data = []): SuccessResponse { + public function getBulkTransformedPosts($data = []) { $usedPosts = []; $renderedPosts = []; @@ -115,14 +115,4 @@ class AutomatedLatestContent extends APIEndpoint { return $this->successResponse($renderedPosts); } - - /** - * @param \WP_Post[] $posts - * @return \WP_Post[] - */ - private function getPermittedPosts($posts) { - return array_filter($posts, function ($post) { - return $this->permissionHelper->checkReadPermission($post); - }); - } } diff --git a/mailpoet/lib/Newsletter/BlockPostQuery.php b/mailpoet/lib/Newsletter/BlockPostQuery.php index 9083bf5069..032fa8d43e 100644 --- a/mailpoet/lib/Newsletter/BlockPostQuery.php +++ b/mailpoet/lib/Newsletter/BlockPostQuery.php @@ -29,20 +29,12 @@ class BlockPostQuery { public $newsletterId = false; /*** - * Translates to \WP_Query::date_query => array{'column': 'post_date', 'after': date string} + * Translates to \WP_Query::date_query => ['column' => 'post_date', 'after' => {date string}] * * @var bool|DateTimeInterface|null */ public $newerThanTimestamp = false; - /** - * If it's a dynamic block - * Dynamic blocks are not allowed to query none-public posts - * - * @var bool - */ - public $dynamic = true; - /** * @param array{ * args?: array{ @@ -59,7 +51,6 @@ class BlockPostQuery { * postsToExclude?: int[], * newsletterId?: int|false|null, * newerThanTimestamp?: bool|DateTimeInterface|null, - * dynamic?: bool, * } $query * @return void */ @@ -70,17 +61,18 @@ class BlockPostQuery { $this->postsToExclude = $query['postsToExclude'] ?? []; $this->newsletterId = $query['newsletterId'] ?? false; $this->newerThanTimestamp = $query['newerThanTimestamp'] ?? false; - $this->dynamic = $query['dynamic'] ?? true; } public function getPostType(): string { return $this->args['contentType'] ?? 'post'; } + /** + * Returns post status + * + * @return string + */ public function getPostStatus(): string { - if ($this->dynamic) { - return 'publish'; - } return $this->args['postStatus'] ?? 'publish'; } diff --git a/mailpoet/lib/Newsletter/Renderer/Blocks/AutomatedLatestContentBlock.php b/mailpoet/lib/Newsletter/Renderer/Blocks/AutomatedLatestContentBlock.php index 601a95027f..faaaf5286c 100644 --- a/mailpoet/lib/Newsletter/Renderer/Blocks/AutomatedLatestContentBlock.php +++ b/mailpoet/lib/Newsletter/Renderer/Blocks/AutomatedLatestContentBlock.php @@ -53,7 +53,6 @@ class AutomatedLatestContentBlock { 'postsToExclude' => $postsToExclude, 'newsletterId' => $newsletterId, 'newerThanTimestamp' => $newerThanTimestamp, - 'dynamic' => true, ]); $aLCPosts = $this->ALC->getPosts($query); foreach ($aLCPosts as $post) {